使用隐藏域input,提交表单未设置默认值,提交报错400

来源:互联网 发布:全部网络歌曲试听 编辑:程序博客网 时间:2024/06/06 17:52

1、 html表单如下:

红色为正确代码,蓝色为出错代码

<form action="operate_addenterandexit.html" method="post"><div id="hidden" ><label>班组/个人进退场记录</label><span><select name="type"><option value="2" <c:if test="${type==2}">selected</c:if> style="width:60px">班组</option><option value="1" <c:if test="${type==1}">selected</c:if> style="width:60px">个人</option></select></span></div><div><label>班组名称</label><span><select name="teamName"><c:forEach items="${teamList}" var="team"><option value="${team.name}">${team.name}</option></c:forEach></select></span></div><div><label>姓名</label><span><input name="name" type="text"/></span></div><div><label>联系方式</label><span><input name="cId" type="text"/></span></div><div><label>性质</label><span><select id="eqtime" name=""><!-- 目前这个字段自用来通过js控制前端的页面 --><option value="">进场</option><option value="">退场</option></select></span></div><div class="enter"><label>进场时间</label><span><input name="startTime" type="text" value=""/></span></div><div class="quit"><div><label>退场时间</label><span><input name="endTime" type="text" value="" /></span></div><div class="star"><label>技能</label><ul><li data-star=-5><img src="resource/images/u663.fw.png" alt="" /></li><li data-star=-2><img src="resource/images/u663.fw.png" alt="" /></li><li data-star=0><img src="resource/images/u663.fw.png" alt="" /></li><li data-star=2><img src="resource/images/u663.fw.png" alt="" /></li><li data-star=5><img src="resource/images/u663.fw.png" alt="" /></li></ul><input type="hidden" name="score1" value='0'/><!--<input type="hidden" name="score1" />--><!--<input type="hidden" name="score1" value=''/>--></div><div class="star"><label>勤劳度</label><ul><li data-star=-5><img src="resource/images/u663.fw.png" alt="" /></li><li data-star=-2><img src="resource/images/u663.fw.png" alt="" /></li><li data-star=0><img src="resource/images/u663.fw.png" alt="" /></li><li data-star=2><img src="resource/images/u663.fw.png" alt="" /></li><li data-star=5><img src="resource/images/u663.fw.png" alt="" /></li></ul><input type="hidden" name="score2" value='0'/><!--<input type="hidden" name="score2" />--><!--<input type="hidden" name="score2" value=''/>--></div><div class="star"><label>工作态度</label><ul><li data-star=-5><img src="resource/images/u663.fw.png" alt="" /></li><li data-star=-2><img src="resource/images/u663.fw.png" alt="" /></li><li data-star=0><img src="resource/images/u663.fw.png" alt="" /></li><li data-star=2><img src="resource/images/u663.fw.png" alt="" /></li><li data-star=5><img src="resource/images/u663.fw.png" alt="" /></li></ul><input type="hidden" name="score3" value='0'/><!--<input type="hidden" name="score3" />--><!--<input type="hidden" name="score3" value='' />--></div><div><label>差评记录</label><span><input name="desc" type="text" /></span></div></div><input type="submit" class="identy" value="保存" /><input type="reset" id="cancel" class="cancel" value="取消" /></form>

2、后台springmvc 直接用model实体类接收,input表单中的三个type为hidden的input标签 提交的字段是int型,score1,score2,score3,model实体中有默认值为0

报错:

后台代码如下:

@RequestMapping(value="operate_addenterandexit.html")public String addEnterAndExit(CommentsModel commentsModel){commentsService.addOneEnterAndExit(commentsModel);return "forward:operate_enterandexit.html";}

实体类model

public class CommentsModel implements BaseIdModel {private String id;private String startTime;// 201509private String endTime;// 201509private String projectName;private String teamName;private String name; //项目管理——员工/班组 进退场 (12月13日)private int score1 = 0;//技能评价  \材料质量评价private int scoreStr1;private int score2 = 0;//勤劳评价  \材料价格评价private int scoreStr2;private int score3 = 0;//态度评价 \ 材料售后评价private int scoreStr3;private String desc;private Date createTime = new Date();private int type;// 1-个人 2-班组 3-材料商 4-设备商private String cId;// tId or userId 如果是班组长的话cId就是tId,如果是个人用户的话cId就是userIdprivate String pId; // 项目的ID




1 0