check . validition .出错变红

Contrallor里面加验证信息及对省市进行初始化:

if (results.hasErrors()) {
			 
             List<Item> provinceList = itemListComponent.getProvinceList();
         	model.addAttribute("provinceList", provinceList); 
         	List<Item> cityList = itemListComponent.getCityList(distributorForm.getProvinceId());
        	model.addAttribute("cityList", cityList);
			 return "manager/distributor/editDistributor";}

在Form中定义一个需要验证的变量:

@NotEmpty(field="地址",  message="{errors.required}")

对应的显示页面editDistributor.jsp中

<td><input name="address" class="form-control" value="${distributorForm.address}" /></td>

改为

<td><form:input path="address" cssClass="form-control" cssErrorClass="form-control error" 
value="${distributorForm.address}" />  </td>

还应在页面中添加Link

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

还有要检查下是否有用来显示的common.css

@CHARSET "UTF-8";
.error{
	background-color:red;
}

必填项加“*

地址<span style="color:red;">*</span>


你可能感兴趣的:(check . validition .出错变红)