form表单传日期400
来源:互联网 发布:mysql union or in 编辑:程序博客网 时间:2024/06/08 11:36
1.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>test here</title>
</head>
<body>
<form method="post" action="testAdd" id="form">
<input type="text" name="users[0].id"/>
<input type="text" name="users[0].userName"/>
<input type="text" name="users[0].time"/>
<input type="text" name="users[1].id"/>
<input type="text" name="users[1].userName"/>
<input type="text" name="users[1].time"/>
<input type="submit" value="submit"/>
</form>
</body>
</html>
2.对象
package com.lucene.model;
import java.util.Date;
public class User {
private Integer id;
private String userName;
private Date time;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public Date getTime() {
return time;
}
public void setTime(Date time) {
this.time = time;
}
}
package com.lucene.model;
import java.util.List;
public class UserModel {
private List<User> users;
public List<User> getUsers() {
return users;
}
public void setUsers(List<User> users) {
this.users = users;
}
}
3控制器
@RequestMapping(value = "/testAdd", method ={RequestMethod.POST})
public String testAdd(UserModel userModel) {
return "test";
}
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
simpleDateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(simpleDateFormat, true));
}
4.解决在控制器增加如下方法
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
simpleDateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(simpleDateFormat, true));
}
5.结果
- form表单传日期400
- form表单传值
- Form表单传值
- C#Form表单传值
- form表单传参注意事项
- FORM表单
- 表单form
- form表单
- form表单
- form表单
- 表单(form)
- 表单form
- form 表单
- form表单
- [表单]form
- Form 表单
- form表单
- form表单
- Android 混淆详解
- AS出现Error:Cause: peer not authenticated
- 辗转相除求最大公约数
- Mysql数据类型---日期时间
- python学习之文件管理
- form表单传日期400
- makefile处理源文件对头文件的依赖
- linux开机启动程序
- Git基本操作
- js字符串函数
- 201703-1 分蛋糕
- redis主从复制失败的坑
- python设计模式之适配器
- Mysql数据类型---TIMESTAMP