首页 技术 正文
技术 2022年11月18日
0 收藏 498 点赞 2,322 浏览 788 个字

查阅了好多资料, 最后才发现原来只是添加一个方法就能解决的问题, 但是看了半天又没看明白, 只是知道这么写就能成功, 先记下来, 以后再研究吧, 在配置好springMVC的时候, 可以在前台的form表单传递一个实体类, 后台spring会自动将name传递来的属性自动装配给实体类的class, 但是有一点, 如果实体类中有一个属性是一个date型的, 就会报出400的错误, “客户端传递的参数中有语法错误”, 最后在controller的那个控制类里面机上这样一段代码, 但不知道是什么意思

    @org.springframework.web.bind.annotation.InitBinder
public void InitBinder(/*HttpServletRequest request, */ServletRequestDataBinder binder) {
// 不要删除下行注释!!! 将来"yyyy-MM-dd"将配置到properties文件中
// SimpleDateFormat dateFormat = new
// SimpleDateFormat(getText("date.format", request.getLocale()));
System.out.println("执行了InitBinder方法");
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, null, new CustomDateEditor(dateFormat, true));
}

使用@InitBinder标签, spring在将参数传递到后台的controller的时候就可以自动转换成日起类型的格式了

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,085
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902