利用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";
}
@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";
}
相关文章推荐
- 用validation验证输入框为空时,输入框变红
- 如何快速成为iOS游戏开发达人
- 文档管理系统,你用了吗?
- 家用净水器哪个好?泊森源用专业的眼光为您选!
- 苹果系统mac下vim编辑器开启代码高亮、行号
- 程序设计方法学基本概念汇总
- birt 报表基本用法
- 程序员修炼指南——引导你成为真正的编程高手
- 《C++编程思想》第四章 初始化与清除(原书代码+习题+解答)
- hdu 1421 搬寝室 解题报告
- hdu 1176 馅饼 解题报告
- 大数据系列修炼-Scala课程03
- 什么牌子的家用净水器好?
- JS~jwPlayer为js预留的回调方法大总结
- 开源框架Pushlet入门_java_web
- 月薪3K也可以理财 工薪阶层如何玩转P2P
- 四季电台应用项目源码
- 类似material design的电影应用源码
- EarthWarrior3D游戏ios源码
- 基于keepalived双主模型的高可用LVS