问题:BeanUtils不能封装Date的类型,他只会把他认为是字符串

解决方法:使用类型转换器转换

//2、指定一个类型转换器(String转换为Date),birthday传过来是String
ConvertUtils.register(new Converter() {

	public Object convert(Class clazz, Object value) {
		//将String转换为Date
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		Date parse = null;
		try {
			parse = format.parse(value.toString());
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return parse;
	}
			
}, Date.class);

BeanUtils——类型转换器

相关文章:

  • 2021-05-29
  • 2021-04-11
  • 2021-11-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-06
猜你喜欢
  • 2022-12-23
  • 2021-07-16
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2021-11-04
  • 2021-07-31
相关资源
相似解决方案