<button type="button" onclick="window.history.back();" class="btn btn-danger">取 消</button>
將代碼修改成:java
<a class="btn btn-danger" href="initExpressList"> 取 消</a>
initExpressList爲本頁面。在controller中 @RequestMapping(value = "initExpressList", method = RequestMethod.GET) public String initExpressList(Model model) { log.info("快遞單號列表初始化"); model.addAttribute("list", expressListService.searchExpressListList()); return "manager/expressList/expressListList"; }
2.點擊追加提交按鈕時web
@RequestMapping(value = "addExpressList", method = RequestMethod.POST) public String executeAddExpressList(Model model, HttpSession session, @Valid @ModelAttribute("expressListForm") ExpressListForm expressListForm, BindingResult results) throws SQLException, IOException { log.info("添加快遞單號信息"); UVO uvo = (UVO)session.getAttribute("UVO"); expressListForm.setUpdateUser(uvo.getUserName()); Date date = new Date(); SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); expressListForm.setUpdateTime(dateformat.format(date)); if (results.hasErrors()) { log.info("內容驗證出錯"); //model.addAttribute("message", "該畫面全部項目都是必填項,請認真填寫!"); List<Item> expressList = itemListComponent.getExpressList(); model.addAttribute("expressList", expressList); return "manager/expressList/addExpressList"; } 用到的文件和代碼: a. package cn.agriculture.web.form; import cn.agriculture.common.validator.constraints.NotEmpty; import lombok.Data; @Data public class ExpressListForm { private String expressListId; private String expressId; private String expressName; private String isUsed; private String orderId; private String usedDate; private String note; private String storage; @NotEmpty(field="快遞單號開始", message="{errors.required}") private String expressListIdStart; @NotEmpty(field="快遞單號結束", message="{errors.required}") private String expressListIdEnd; private String updateTime; private String updateUser; } b. public List<Item> getExpressList() { return queryDao.executeForObjectList("Common.selectExpress", null); } c. 在ValidationMessages.properties文件中: errors.required={field}爲必須輸入項目 errors.email=email格式不正確 errors.qq=qq格式不正確 errors.zip=zip必須爲數字格式 errors.length=zip長度必須爲六位 errors.mobile=手機輸入格式不正確 errors.date=日期格式不正確