1.html
@Slf4j java
@RequestMapping("/")編程
@Controller("AlipayController")session
@Autowiredapp
@RequestMapping(value = "replayAlipaySubmit", method = RequestMethod.POST)ui
public String executeReplayAlipaySubmit(Model model, HttpSession session, @Valid @ModelAttribute("alipayForm") AlipayForm alipayForm, BindingResult results, Device device) throws SQLException {spa
GoodsForm goodsForm = new GoodsForm();.net
goodsForm.setType("糧食");code
model.addAttribute("goodsForm", goodsForm);orm
//新建一個goodForm將Type的值設置爲糧食
log.info("從新向支付寶發起支付請求。");
//
if (device.isNormal()) {
model.addAttribute("sHtmlText", alipayRequestWeb(alipayForm));
} else {
model.addAttribute("sHtmlText", alipayRequestMobile(alipayForm));
}
//判斷是PC端訪問仍是手機端訪問
return "manager/charge/alipay";
//返回的頁面
}
@RequestMapping(value = "initDistributorAlipayComfirm", method = RequestMethod.GET)
public String initDistributorAlipayComfirm(Model model, HttpSession session,AlipayForm alipayForm)
{ List<CartForm> cartList = new ArrayList<>();
model.addAttribute("cartList", cartList);
//新建一個購物列表讓值爲空
GoodsForm goodsForm=new GoodsForm();
goodsForm.setType("糧食");
model.addAttribute("goodsForm", goodsForm);
log.info("由分銷商直接推薦的商品銷售頁面初始化。");
//在編程更容易找到位置
UVO uvo= new UVO();
session.setAttribute("UVO",uvo);
//新建一個如同userBean的文件,使得值爲空
model.addAttribute("alipayForm", alipayService.searchAlipay(alipayForm));
//alipayForm是AlipayForm的實例,用來提示判斷是否有要輸入的值爲空
return "mobile/alipay/distributorAlipayConfirm";
//要返回的頁面
}
2.實現對要輸入的框是否爲空,若是爲空要提示什麼值不爲空
html: <span th:if="${#fields.hasErrors('${userBean.*}')}"><span th:errors="${userBean.*}"></span></span> <div align="center"><form action="Update" method="POST"> <div>用戶ID: <span th:text="${userBean.userId}"></span></div> <div><span th:text="姓名"></span> <input name="userName" type="text" th:value="${userBean.userName}" /></div> <div><span th:text="密碼"></span> <input name="userPassword" type="text" /></div> <div><span th:text="確認密碼"></span> <input name="Confirm" type="text" /></div> <div><button name="update" type="submit">修改</button></div> </form></div> 在controller中: @RequestMapping(value = "/Update", method = RequestMethod.POST, params = "update") public String update(UserBean userupdate, Model model, HttpSession session,@Valid @ModelAttribute("userBean") UserBean userBean, BindingResult results) throws SQLException { if (results.hasErrors()) { log.info("內容驗證出錯"); return "userUpdate"; } String pass1 = userupdate.getUserPassword(); String pass2 = userupdate.getConfirm(); if (pass1.equals(pass2)) { int update = helloWorldService.updateResult(userupdate); if (update == 1) { model.addAttribute("userBean", userupdate); model.addAttribute("message", "修改爲功"); return "userUpdate"; } else { model.addAttribute("message", "出現錯誤"); return "userUpdate"; } } else { model.addAttribute("message", "兩次輸入的密碼不對應"); return "userUpdate"; } } 3.userBean和SQL語句: @NotEmpty(field = "用戶ID", message = "{errors.required}") private String userId; @NotEmpty(field = "用戶姓名", message = "{errors.required}") private String userName; @NotEmpty(field = "用戶密碼", message = "{errors.required}") private String userPassword; private String confirm; public int updateResult(UserBean frm) { return updateDao.execute("user.UpdateUser", frm); } <update id="UpdateUser" parameterClass="cn.training.bean.UserBean"> update user set userName =#userName#, userPassword=#userPassword# WHERE userId = #userId# </update