07.27总结

一。在添加城市页面添加验证信息,修改取消按钮路径。(提示文本框不能为空,文本框变为红色)

1。 添加验证信息

①在WEB-INF/jsp/manager/city/addCity.jsp中修改

 <div class="box-content">

                                <form:form modelAttribute="cityForm" action="addCity" method="post">

                                <div class="alert alert-info">${message}<form:errors path="*"></form:errors></div>

                                    <table class="table table-bordered responsive">

②在CityForm.java中添加

@NotEmpty(field="城市名称",  message="{errors.required}")

private String cityName;

③在CityController.java中添加

@RequestMapping(value = "addCity", method = RequestMethod.POST)

public String executeAddCity(Model model, @Valid @ModelAttribute("cityForm") CityForm cityForm, BindingResult results) throws SQLException, IOException {

if (results.hasErrors()) {

log.info("内容验证出错");

List<Item> provinceList = itemListComponent.getProvinceList();

    model.addAttribute("provinceList", provinceList);

return "manager/city/addCity";}

log.info("添加城市");

boolean result = cityService.addCity(cityForm);

if(!result) {

throw new SQLException("城市添加失败!");

}

2. 修改取消按钮路径

在WEB-INF/jsp/manager/city/addCity.jsp中修改

 <a href="initMenu" class="btn btn-danger">取 消</a>

3.文本框变为红色

在WEB-INF/jsp/manager/city/addCity.jsp中添加

<link href="css/common.css" rel="stylesheet"> //line28

<td style="background-color: #f9f9f9;">城市名称</td>

<td><form:input path="cityName" cssClass="form-control" cssErrorClass="form-control error" ></form:input></span th:error=""></td> //line174

二。在充值页面增加一个验证信息,修改取消的路径

1。 添加验证信息

①在WEB-INF/jsp/manager/charge/addCharge.jsp中修改

<div class="box-content">

                                <form:form modelAttribute="chargeForm" action="addCharge" method="post">

                                <div class="alert alert-info">${message}<form:errors path="*"></form:errors></div>

②在chargeForm.java中修改

@NotEmpty(field="充值金额",  message="{errors.required}")

private String amount;

③在ChargeController.java中添加

if (results.hasErrors()) {

log.info("内容验证出错");

    model.addAttribute("chargeForm", chargeForm);

return "manager/charge/addCharge";}








你可能感兴趣的:(07.27总结)