解决奖惩信息更新页面信息id不能传到controler层,其他都可以

来源:互联网 发布:wps文字软件下载 编辑:程序博客网 时间:2024/05/16 16:12

<form name="institutionForm" method="post" action="modifyinstitution.do?action=updateInstitution"      onSubmit="return institutionValidate()">    <div class="MainDiv">        <table width="99%" border="0" cellpadding="0" cellspacing="0" class="CContent">            <tr>                <th class="tablestyle_title">修改奖惩信息</th>            </tr>            <tr>                <td class="CPanel">                    <table border="0" cellpadding="0" cellspacing="0" style="width:80%" align="center">                        <tr>                            <td align="left">                                <input type="button" value="返回"  onclick="tiaozhuan()" class="button"/>                            </td>                        </tr>                        <tr>                            <td width="100%">                                <fieldset style="height:100%;">                                    <legend>修改奖惩信息</legend><input type="hidden" name="id" value=""/ >                                    <table border="0" cellpadding="2" cellspacing="1" style="width:100%">                                        <tr>                                            <td nowrap align="right" width="11%">奖惩对象:</td>                                            <td width="89%"><input name="name" type="text" class="input" value="${updateDetail.username}"                                                                   placeholder="请选择" onclick="chooseUser('1')"                                                                   data-toggle="modal"  data-target="#myModal" id="userName"                                            />                                                <span class="red">*</span></td>                                        </tr>                                        <tr>                                            <input id="usernameTemp" type="hidden"  value="" />                                            <input id="userIdTemp" type="hidden" name="userid" value=""/>                                        </tr>                                        <tr>                                            <td nowrap align="right" width="11%">奖惩类型:</td>                                            <td><input name="type" type="text" class="input"                                                       value="${updateDetail.type}"/>                                                <span class="red">*</span></td>                                        </tr>                                        <tr>                                            <td width="11%" nowrap align="right">奖惩说明:</td>                                            <td><textarea name="content" cols="100" rows="6" class="input"                                                              id="explain" ><c:out value="${updateDetail.content}"/></textarea></td>                                        </tr>                                        <tr>                                            <input  name="id" value="${updateDetail.id}"/>                                            <input  name="msgid" value="${updateDetail.msgid}"/>                                            <input  name="userid" value="${updateDetail.userid}"/>                                        </tr>                                    </table>                                </fieldset>                            </td>                        </tr>                    </table>                </td>            </tr>            <tr>                <td colspan="2" align="center" height="50px">                    <input name="提交" type="submit" class="button" value="保存"/>                     <input name="重置" type="reset" class="button" value="重置"/></TD>            </tr>            </table>        </table>    </div></form>
用form表单提交我的其他实体里面的东西都传过来了,就是id传不过来。开始查错,

第一,怀疑没拿到返回到更新奖惩信息的页面。把type="hidden"删除,发现可以打印出来,就证明不是这里的原因。怀疑是id这个名字有问题,如果修改了前台以前name为id的input,修改成name="rapid" ,好的,修改了这里的name,后台controler接受的是institutuion实体,要想接受到该值,就必须修改实体,两种方法

1)添加一个实体Rap,在实体里面加入rapid字段,查看返回的rapid,发现可以接受到,好吧,我开始觉得问题出id名字上面了。

2)在实体institution里面添加rapid字段。把前端传过来的rapid接收

package com.jointem.hrm.entity;import java.beans.Transient;import java.io.Serializable;import java.util.Date;public class Institution implements Serializable {private Integer msgid;private Integer id;private Integer userid;private String type;private String content;private Date  createtime;private Users users;private Message message;@Transientprivate Integer repid;public Integer getId() {if(null != repid){return id = repid;}else{return id;}}public void setId(Integer id) {this.id = id;}public Integer getUserid() {return userid;}public void setUserid(Integer userid) {this.userid = userid;}public String getType() {return type;}public void setType(String type) {this.type = type;}public String getContent() {return content;}public void setContent(String content) {this.content = content;}public Date getCreatetime() {return createtime;}public void setCreatetime(Date createtime) {this.createtime = createtime;}public Users getUser() {return users;}public void setUser(Users user) {this.users = users;}public Message getMessage() {return message;}public void setMessage(Message message) {this.message = message;}public Integer getMsgid() {return msgid;}public void setMsgid(Integer msgid) {this.msgid = msgid;}public Integer getRepid() {return repid;}public void setRepid(Integer repid) {this.repid = repid;}@Overridepublic String toString() {return "Institution [msgid=" + msgid + ", id=" + id + ", userid=" + userid + ", type=" + type + ", content="+ content + ", createtime=" + createtime + "]";}}

看我加粗的那段代码逻辑,可是传过来的还是id是null,问题就不是出现在id名字问题上了。在更新页面上查是不是“id”这个name与其他的冲突了,发现果然是。看我第一段代码,其中加粗标红的也是id为name,且value值是Null,还排在hidden的input前面,所以不管怎样我获取到的id都是null.把那个重复的删除即可。


阅读全文
0 0
原创粉丝点击