1.<button type="button" onclick="window.history.back();" class="btn btn-danger">取 消</button>css
這裏的取消按鈕是返回上一級java
2.<a type="button" href="initPlaceOrder" class="btn btn-danger">取 消</a>session
這裏的取消按鈕是返回到須要返回的頁面app
3.editUser.jsp頁面文本框填寫後顯示提示信息,而且未填寫信息的文本框爲紅色jsp
首先在editUser.jsp頁面添加超連接讓文本框顯示爲紅色ui
關鍵代碼:spa
<tr> <td style="background-color: #f9f9f9;">用戶ID<span style="color:red;">*</span></td> <td><form:input path="userId" cssClass="form-control" cssErrorClass="form-control error" value="${userForm.userId}"/></td> <td style="background-color: #f9f9f9;">用戶密碼<span style="color:red;">*</span></td> <td><form:input path="password" type="password" cssClass="form-control" cssErrorClass="form-control error"/></td> <td style="background-color: #f9f9f9;">確認密碼</td> <!-- <td><input type="password" name="passwordConfirm" class="form-control" id="inputSuccess1" /></td> --> <td><form:input path="passwordConfirm" type="password" cssClass="form-control" cssErrorClass="form-control error"/></td> </tr> <tr> <td style="background-color: #f9f9f9;">用戶姓名<span style="color:red;">*</span></td> <!-- <td><input name="userName" class="form-control" id="inputSuccess1" value="${userForm.userName}" /></td> --> <td><form:input path="userName" cssClass="form-control" cssErrorClass="form-control error" value="${userForm.userName}"/></td> <td style="background-color: #f9f9f9;">出生年月</td> <!-- <td><input name="birthday" class="form-control" id="birthday" value="${userForm.birthday}" data-date-format="yyyy-mm-dd" /></td> --> <td><form:input path="birthday" cssClass="form-control" cssErrorClass="form-control error" value="${userForm.birthday}"/></td> <td style="background-color: #f9f9f9;">性別</td> <td> <div class="controls"> <form:select path="gender" id="selectError" data-rel="chosen"> <form:option value="未知"> 未知 </form:option> <form:option value="男"> 男 </form:option> <form:option value="女"> 女 </form:option> </form:select> </div> </td> </tr> <tr> <td style="background-color: #f9f9f9;">住址</td> <!-- <td colspan="5"><input name="address" class="form-control" id="inputSuccess1" value="${userForm.address}" /></td> --> <td colspan="5"><form:input path="address" cssClass="form-control" cssErrorClass="form-control error"/></td> </tr> <tr> <td style="background-color: #f9f9f9;">身份證號<span style="color:red;">*</span></td> <!-- <td><input name="idCard" class="form-control" id="inputSuccess1" value="${userForm.idCard}" /></td> --> <td><form:input path="idCard" cssClass="form-control" cssErrorClass="form-control error" value="${userForm.idCard}"/></td> <td style="background-color: #f9f9f9;">電子郵箱</td> <!-- <td><input name="email" class="form-control" id="inputSuccess1" value="${userForm.email}" /></td> --> <td><form:input path="email" cssClass="form-control" cssErrorClass="form-control error" value="${userForm.email}"/></td> <td style="background-color: #f9f9f9;">電話<span style="color:red;">*</span></td> <!-- <td><input name="telephone" class="form-control" id="inputSuccess1" value="${userForm.telephone}" /></td> --> <td><form:input path="telephone" cssClass="form-control" cssErrorClass="form-control error" value="${userForm.telephone}"/></td> </tr> <tr> <td style="background-color: #f9f9f9;">所在部門</td> <!-- <td><input name="department" class="form-control" id="inputSuccess1" value="${userForm.department}" /></td> --> <td><form:input path="department" cssClass="form-control" cssErrorClass="form-control error" value="${userForm.department}"/></td> <td style="background-color: #f9f9f9;">職位</td> <!-- <td><input name="position" class="form-control" id="inputSuccess1" value="${userForm.position}" /></td> --> <td><form:input path="position" cssClass="form-control" cssErrorClass="form-control error" value="${userForm.position}"/></td> <td style="background-color: #f9f9f9;">所屬公司</td> <!-- <td><input name="companyName" class="form-control" id="inputSuccess1" value="${userForm.companyName}" /></td> --> <td><form:input path="companyName" cssClass="form-control" cssErrorClass="form-control error" value="${userForm.companyName}"/></td> </tr>
UserController.java頁面主要代碼
code
@RequestMapping(value = "editUser", method = RequestMethod.POST) public String executeEdit(Model model, HttpSession session, @Valid @ModelAttribute("userForm") UserForm userForm, BindingResult results) throws SQLException { if (results.hasErrors()) { log.info("內容驗證出錯"); return "manager/editUser"; } if (!userForm.getPassword().equals(userForm.getPasswordConfirm())) { log.info("密碼驗證出錯"); model.addAttribute("message", "密碼和密碼確認必須一致!"); return "manager/editUser"; } log.info("修改客戶信息"); UVO uvo = (UVO)session.getAttribute("UVO"); userForm.setUpdateUser(uvo.getUserName()); Date date = new Date(); SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); userForm.setUpdateTime(dateformat.format(date)); boolean result = userService.editUser(userForm); if(!result) { throw new SQLException("客戶信息添加失敗!"); } return "manager/menu"; }//錯誤信息的驗證
在UserForm.java中設置文本框信息不爲空
orm
@Data public class UserForm { @NotEmpty(field="用戶ID", message="{errors.required}") private String userId; @NotEmpty(field="用戶姓名", message="{errors.required}") private String userName; @NotEmpty(field="用戶密碼", message="{errors.required}") private String password; @NotEmpty(field="確認密碼", message="{errors.required}") private String passwordConfirm; @NotEmpty(field="身份證號", message="{errors.required}") private String idCard; @NotEmpty(field="出生年月", message="{errors.required}") private String birthday; private String gender; @NotEmpty(field="所屬公司", message="{errors.required}") private String companyName; @NotEmpty(field="住址", message="{errors.required}") private String address; @NotEmpty(field="電子郵箱", message="{errors.required}") private String email; @NotEmpty(field="聯繫電話", message="{errors.required}") private String telephone; @NotEmpty(field="所在部門", message="{errors.required}")} private String department; @NotEmpty(field="職位", message="{errors.required}") private String position;
在運行時遇到一個問題,就是密碼自動顯示,要設置成不顯示密碼,就要將SQL文中密碼一行刪除,讓其再也不初始化顯示。
ci