问题描述
表单中一些字段为空的话,如果POJO定义该属性为int型就会报400.
实体类:
public class Teacher {
private int id; //教师编号
private String name; //教师姓名
private String sex; //性别
private List<Course> courseList; //课程列表
//省略get,set方法与构造器
}
前端的表单:
<form method="post" action="${pageContext.request.contextPath}/teacher/queryTeacher">
教师号:<input type="number" name="id" id="id">
姓名:<input type="text" name="name" id="name" value="">
性别:<label><input name="sex" type="radio" value="男" />男 </label>
<label><input name="sex" type="radio" value="女" />女 </label>
<input type="submit" value="查询" />
</form>
当id为空时,会报400。
解决方案
将实体类中int改为Integer
https://ask.csdn.net/questions/658351