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

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>

&nbsp;&nbsp;&nbsp;&nbsp;

关键代码:让页面有值<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";

    }

   



转载于:https://my.oschina.net/u/2411775/blog/484613

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值