1、在editDistributorPrice.jsp页面中
<link href="css/common.css" rel="stylesheet"> 这句代码是用来引用一个样式,让输入框没有填写内容是变红
<div> <ul class="breadcrumb">
<li><a href="#">首页</a></li>
<li><a href="#">修改终端价格</a></li> </ul> </div>
<div class="row"> <div class="box col-md-12">
<div class="box-inner">
<div class="box-header well" data-original-title=""> <h2>
<i class="glyphicon glyphicon-edit"></i> 终端价格</h2>
<div class="box-icon"> <a href="#" class="btn btn-setting btn-round btn-default">
<i class="glyphicon glyphicon-cog"></i></a> <a href="#" class="btn btn-minimize btn-round btn-default">
<i class="glyphicon glyphicon-chevron-up"></i></a> <a href="#"class="btn btn-close btn-round btn-default">
<i class="glyphicon glyphicon-remove"></i></a> </div> </div>
<div class="box-content">
<form:form modelAttribute="distributorPriceForm" action="editDistributorPrice" method="post">
<form:hidden path="commodityId" value="${distributorPriceForm.commodityId}" />
<form:hidden path="distributorPriceId" value="${distributorPriceForm.distributorPriceId}" />
关键代码 :判断错误信息 <div class="alert alert-info">${message}<form:errors path="*"></form:errors></div>
<table class="table table-bordered responsive"><tr>
<td style="background-color: #f9f9f9;">商品名称</td>
<td>${distributorPriceForm.commodityName}</td>
<td style="background-color: #f9f9f9;">指导价</td>
<td>${distributorPriceForm.guidePrice}</td>
<td style="background-color: #f9f9f9;">终端价<span style="color:red">*</span></td>
关键代码:使用css <td><form:input path="retailPrice" cssClass="form-control" cssErrorClass="form-control error" value="${distributorPriceForm.retailPrice}"/></td></tr> </table>
<div class="input-group has-success col-md-12" align="right">
<button type="submit" class="btn btn-success">提 交</button>
关键代码:给<a href="initDistributorPriceEdit" class="btn btn-danger">取 消</a></div> </form:form>
</div></div> </div>
2、在DistributorPriceController.java
@RequestMapping(value = "initEditDistributorPrice", method = RequestMethod.GET)
public String initEditDistributorPrice(Model model, HttpSession session, DistributorPriceForm distributorPriceForm) {
log.info("修改分销商价格初始化");
UVO uvo = (UVO)session.getAttribute("UVO");
distributorPriceForm.setDistributorId(uvo.getUserId());
model.addAttribute("distributorPriceForm", distributorPriceService.searchDistributorPrice(distributorPriceForm));
return "manager/distributorPrice/editDistributorPrice"; 从这里可以看出是调用的那个方法,返回到自己想要的页面
}
@RequestMapping(value = "editDistributorPrice", method = RequestMethod.POST)
public String executeEditDistributorPrice(Model model, HttpSession session, @Valid @ModelAttribute("distributorPriceForm") DistributorPriceForm distributorPriceForm,BindingResult results) throws SQLException { 利用validation的关键代码
if(results.hasErrors())
{
log.info("修改分销商价格");
model.addAttribute("message", "请输入修改价格"); 输入框是否为空的关键代码
return "manager/distributorPrice/editDistributorPrice";
}
3、在DistributorPriceForm.java中
@NotEmpty(field="终端价", message="{errors.required}") 输出一个错误信息
private String retailPrice;