GVKun编程网logo

Failed to convert property value of type ‘java.lang.String‘ to required type ‘java.lang.Date‘

11

在本文中,我们将带你了解Failedtoconvertpropertyvalueoftype‘java.lang.String‘torequiredtype‘java.lang.Date‘在这篇文章中

在本文中,我们将带你了解Failed to convert property value of type ‘java.lang.String‘ to required type ‘java.lang.Date‘在这篇文章中,同时我们还将给您一些技巧,以帮助您实现更有效的angularjs select number type default value required validate、c# – 如何使用InvariantCulture调用TypeConverter.ConvertTo或ConvertToString但不实现ITypeDescriptorContext、C++之error: cannot bind non-const lvalue reference of type ‘myString&’ to an rvalue of type ‘m...、cannot convert t (type interface {}) to type string: need type assertion

本文目录一览:

Failed to convert property value of type ‘java.lang.String‘ to required type ‘java.lang.Date‘

Failed to convert property value of type ‘java.lang.String‘ to required type ‘java.lang.Date‘

前端返回的是 json 字符串,实体类是 date 属性
实体类上增加 @DateTmeFormat 注解,这样前端传过来的值就自动转化为 Date 格式
增加 @JsonFormat 注解,后台返回给前端的 Date 属性自动转化为 json 字符串
在这里插入图片描述

angularjs select number type default value required validate

angularjs select number type default value required validate

<!DOCTYPE html>
<html lang="en">
<head>
    <Meta charset="UTF-8">
    <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
    <div ng-app="app" ng-controller="controller">
        <form name="form" novalidate>
            <divng->
                <label for="exampleInputEmail1">select</label>
                <!--http://stackoverflow.com/questions/32304519/ng-pattern-regex-to-allow-all-characters-except-decimal-value-->
                <selectng-model="item.value" name="value" convert-to-number ng-pattern="/^(?!0$).*/" required>
                    <option value="0" disabled>please choose a number</option>
                    <option ng-repeat="option in [1,2,3,4,5]" value="{{option}}">{{option}}</option>
                </select>
                <span ng-show="form.value.$error.required">required</span>
                <span ng-show="form.value.$error.pattern">pattern</span>
            </div>
            <button type="button"ng-click="submit(form)">submit</button>
        </form>
    </div>
    <script src="http://cdn.bootcss.com/angular.js/1.5.6/angular.min.js"></script>
    <script>
        'use strict';

        var app = angular.module('app',[])

        app.controller('controller',function ($scope) {
            $scope.item = {
                value: 0,}
            $scope.submit = function (form) {
                if (!form.$valid) {
                    return
                }
                alert(JSON.stringify($scope.item))
            }
        })

        //http://stackoverflow.com/a/35407627/2586541
        app.directive('convertToNumber',function () {
            return {
                require: 'ngModel',link: function (scope,element,attrs,ngModel) {
                    //value
                    ngModel.$parsers.push(function (val) {
                        //return '' + val;
                        return parseInt(val,10);
                    });
                    //show
                    ngModel.$formatters.push(function (val) {
                        //return parseInt(val,10);
                        return '' + parseInt(val || 0,10);
                    });
                }
            };
        });
    </script>
</body>
</html>

c# – 如何使用InvariantCulture调用TypeConverter.ConvertTo或ConvertToString但不实现ITypeDescriptorContext

c# – 如何使用InvariantCulture调用TypeConverter.ConvertTo或ConvertToString但不实现ITypeDescriptorContext

在我的转换方法中,当我使用TypeConverter.ConvertToString(Object)时,我得到了错误的数字分隔符,因为我的系统是德语.此方法还有另一个重载,如下所示:TypeConverter.ConvertToString(ITypeDescriptorContext,CultureInfo,Object).

除了在之前和之后切换文化之外,有没有一种聪明的方法来获取ITypeDescriptorContext或使用InvariantCulture调用此方法的其他选项?

解决方法

您可以将null作为参数传递
TypeConverter.ConvertToString(null,CultureInfo.InvariantCulture,Object);

C++之error: cannot bind non-const lvalue reference of type ‘myString&’ to an rvalue of type ‘m...

C++之error: cannot bind non-const lvalue reference of type ‘myString&’ to an rvalue of type ‘m...

先看代码(不想看代码可以直接看代码后的问题描述)

//header.h
#ifndef _HEADER_H
#define _HEADER_H
#define defaultSize 128
#include<iostream>
#include<string.h>
using namespace std;
class myString
{
	private:
		char *ch;
		int curLength;
		int maxSize;
	public:
		myString(int sz=defaultSize);
		myString(const char *init);
		myString(const myString& ob);
		~myString(){delete []ch;}
		void print();
		int Length()const;
		myString operator()(int pos, int len);
		myString& operator = (myString& ob);
};
myString& myString::operator = (myString& ob)
{
	if(&ob!=this)
	{
		delete[]ch;

		this->ch = new char[ob.maxSize];
		this->maxSize = ob.curLength;
		strcpy(this->ch, ob.ch);
		this->curLength = ob.curLength;
	}
	else
	{
		cerr<<"String copy error\n";
	}
	return *this;
}

myString myString::operator()(int pos, int len)
{
	myString temp;
	if(pos<0 || len<=0 || pos+len-1>=this->maxSize)
	{
		temp.curLength = 0;
		temp.ch[0] = ''\0'';
	}
	else
	{
		if(pos+len-1 >= this->curLength)
			len = this->curLength-pos;
		temp.curLength = len;
		for(int i=0,j=pos; i<len; ++i,++j)
			temp.ch[i] = this->ch[j];
		temp.ch[len] = ''\0'';
	}
	return temp;
}

int myString::Length()const
{
	return this->curLength;
}

void myString::print()
{
	cout<<this->ch<<endl;
}

myString::myString(int sz)
{
	this->maxSize = sz;
	this->ch = new char[this->maxSize+1];
	if(this->ch == NULL)
	{
		cerr<<"Allocation ERROR\n";
		exit(1);
	}
	this->curLength = 0;
	ch[0] = ''\0'';
}

myString::myString(const char *init)
{
	int len = strlen(init);
	this->maxSize = (len > defaultSize) ? len : defaultSize;
	this->ch = new char[this->maxSize+1];
	if(this->ch == NULL)
	{
		cerr<<"Application Memory ERROR\n";
		exit(1);
	}

	this->curLength = len;
	strcpy(this->ch, init);

}

myString::myString(const myString& ob)
{
	this->maxSize = ob.maxSize;
	this->ch = new char[this->maxSize+1];
	if(this->ch == NULL)
	{
		cerr<<"Application Memory ERROR\n";
		exit(1);
	}
	this->curLength = ob.curLength;
	strcpy(this->ch, ob.ch);

}

#endif

 

//main.cpp
#include"header.h"

int main()
{
	myString st(10), st1("ABCDEFG");
	myString st2(st1);
	st.print(), st1.print(), st2.print();
	st = st1(0, 4);//???
	st.print();
	return 0;
}

这是一个字符串类,问题出现在了两个符号重载,()和=

()重载是想对字符串对象做一个切片,返回一个临时对象,=重载就不用说了,就是赋值。

问题就出现在总是无法将这个切片后的临时对象赋值给等号前的对象,编译后如下:

 

 

 

在网上一番查找后找到一个类似问题

https://blog.csdn.net/u011068702/article/details/64443949

也就是说,在st1(0,4)时存在了一个临时变量,当把这个临时变量传给st时,由于在=重载函数声明中,参数为myString&,而并不是常量引用。

这个错误是C++编译器的一个关于语义的限制。

如果一个参数是以非const引用传入,c++编译器就有理由认为程序员会在函数中修改这个值,并且这个被修改的引用在函数返回后要发挥作用。但如果你把一个临时变量当作非const引用参数传进来,由于临时变量的特殊性,程序员并不能操作临时变量,而且临时变量随时可能被释放掉,所以,一般说来,修改一个临时变量是毫无意义的,据此,c++编译器加入了临时变量不能作为非const引用的这个语义限制

了解这个语义以后就简单了,只需给=重载参数加上const常量限制符

(类中=重载函数声明也别忘了要加上const)

加上以后程序的运行结果

 

可以,很正确。

总结:

c++中临时变量不能作为非const的引用参数

2019/12/14更新

最近看到一个类似问题,即C++11

 

int i=0;
++++i;//这样是可以的
i++++;//这样就是错误的

 

 我们知道前++就是直接对对象自增后返回对象,而后++会先返回记录当前值,在自增,最后返回一个无名的临时对象,那么 i++++就是让第一个后++返回的无名临时对象再自增,这样对C++是无意义的,所以这样就无法编译通过。//ps.这就是常说的  举一隅以三隅反  吧

cannot convert t (type interface {}) to type string: need type assertion

cannot convert t (type interface {}) to type string: need type assertion

问题:
在使用interface表示任何类型时,如果要将interface转为某一类型,直接强制转换是不行的,例如:

var t interface{} = "abc"

s := string(t)

cannot convert t(type interface {}) to type string: need type assertion

这样是不行的,需要进行type assertion类型断言,具体使用方法请参考:
golang 任何类型interface{}

更多信息:
http://www.jb51.cc/article/p-amhitjiw-bnz.html

我们今天的关于Failed to convert property value of type ‘java.lang.String‘ to required type ‘java.lang.Date‘的分享就到这里,谢谢您的阅读,如果想了解更多关于angularjs select number type default value required validate、c# – 如何使用InvariantCulture调用TypeConverter.ConvertTo或ConvertToString但不实现ITypeDescriptorContext、C++之error: cannot bind non-const lvalue reference of type ‘myString&’ to an rvalue of type ‘m...、cannot convert t (type interface {}) to type string: need type assertion的相关信息,可以在本站进行搜索。

本文标签: