1.在controller頁面編寫:填寫更新標註@RequestMapping,從helloWorldService調用update(userBean)中的值。value="/update"java
@RequestMapping(value = "/update", method = RequestMethod.POST) public String updateLogin(UserBean userBean,Model model) { int result=helloWorldService.update(userBean); //使用了一個選擇語句。若是數據庫數據更新的結果數據庫中沒有,就返回消息"NO" , 如有返回"yes" if(result!=1) {model.addAttribute("message","NO"); return "result"; } else {model.addAttribute("message","yes"); } return "result";
model.addAttribute向模塊中添加輸入的"NO"值。數據庫
2.HelloWorldService.java:數據更新的與法規則app
public int update(UserBean frm) { return updateDao.execute("User.userupdate",frm); }
3.UserSqlMessage.xml:編寫SELECT語句,格式很重要jsp
SELECT userid as userId, username as userName FROM user WHERE userid = #userId# //更新的數據庫語法 規則<update id="userupdate" parameterClass="cn.training.bean.UserBean"> //parameterClass參數類型 UPDATE user SET userName=#userName# WHERE userid = #userId# </update>
4.login.xmlspa
<input type="text" name="userId" value="${userBean.userId}"/> //value用來接收userBean中存儲的值,條件是userId <input type="text" name="userName" value="${userBean.userName}"/>
1.login.jspcode
<c:forEach items="${list}" var="user" varStatus="s">xml
${user.userId}input
${user.userName}</c:forEach>it
2,controller.java:列表的檢索使用RequestMethod.POST的方法class
@RequestMapping(value = "/init", method = RequestMethod.POST)
public String initLogin(UserBean userBean,Model model) {
//int update=helloWorldService.update(userBean);
//int insert=helloWorldService.insert(userBean);
List<UserBean> result = helloWorldService.searchUser(userBean);
model.addAttribute("list", result);
return "login";}
,3.UserSqlMap.xml:查詢數據庫中數值代碼:從user表中選擇條件是userid和username
SELECTuserid as userId,
username as userName
FROM
user
4.controller.java:檢索數據庫中的整個列表用List<UserBean>,並用querDao.executeForObjectList("User.selectUser",frm)的方法
public List<UserBean>searchUser(UserBean frm)
{
List<UserBean> result=queryDao.executeForObjectList("User.selectUser",frm);
return result;
}