您的位置:首页 > 其它

利用validation 验证数字输入格式 和 省区

2015-07-28 00:00 323 查看
1、在ExpressPriceForm.java 这是数字验证

@Digits(fraction = 2, integer = 10,message="{errors.separateWeight}")

private String separateWeight;

@Digits(fraction = 2, integer = 10,message="{errors.firstHeavyPrice}")

private String firstHeavyPrice;

@Digits(fraction = 2, integer = 10,message="{errors.continuedHeavyPrice}")

private String continuedHeavyPrice;

1、1在ValidationMessages.properties的页面中

errors.separateWeight=分割重量必须为正确数字格式

errors.firstHeavyPrice=首重量必须为正确数字格式

errors.continuedHeavyPrice=续重量必须为正确数字格式

2、在addExpressPrice.jsp

<td style="background-color: #f9f9f9;">分隔重量g<span style="color:red;">*</span></td>

<td><input name="separateWeight" class="form-control" /></td>

<td style="background-color: #f9f9f9;">首重费(元)<span style="color:red;">*</span></td>

<td><input name="firstHeavyPrice" class="form-control" /></td></tr>

<tr><td style="background-color: #f9f9f9;">续重费(元)<span style="color:red;">*</span></td>

<td><input name="continuedHeavyPrice" class="form-control" /></td>

<td style="background-color: #f9f9f9;">状态</td>

<td><div class="controls">

<form:select path="status">

<form:option value="启用">启用</form:option>

<form:option value="备用">备用</form:option>

</form:select></div></td>

<td style="background-color: #f9f9f9;">备注</td>

<td><input name="note" class="form-control" /></td></tr> </table>

<div class="input-group has-success col-md-12" align="right">

<button type="submit" class="btn btn-success">提 交</button>

    

关键代码:让页面有值<a href="initExpressPrice? expressId=${expressPriceForm.expressId}" class="btn btn-danger">取 消</a> </div> 提醒:如果取消后页面页面没有内容,用此条代码

在ExpressPriceController.java中

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

public String executeAddExpressPrice(Model model, HttpSession session, @Valid @ModelAttribute("expressPriceForm") ExpressPriceForm expressPriceForm, BindingResult results) throws SQLException {validation 的验证

if(results.hasErrors()) validation 的验证

{

List<Item> provinceList = itemListComponent.getProvinceList(); 前台页面显示可以选择选哪个省

model.addAttribute("provinceList", provinceList);

return "manager/expressPrice/addExpressPrice";

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: