spring mvc 接收data值报400

来源:互联网 发布:女士手套品牌 知乎 编辑:程序博客网 时间:2024/06/04 22:47

1创建 BaseController类(类型解析类)直接复制即可
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import sun.beans.editors.DoubleEditor;
import sun.beans.editors.FloatEditor;
import sun.beans.editors.IntEditor;
import sun.beans.editors.LongEditor;
public class BaseController {
@InitBinder
public void initBinder(WebDataBinder binder) {

binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat(“yyyy-MM-dd”), true));
binder.registerCustomEditor(int.class, new IntEditor());
binder.registerCustomEditor(long.class, new LongEditor());
binder.registerCustomEditor(double.class, new DoubleEditor());
binder.registerCustomEditor(float.class, new FloatEditor());
}
}
2 xxx extends BaseController
3 data类型加入
@DateTimeFormat(pattern = “yyyy-MM-dd”)
private Date ahregistrardate;

原创粉丝点击