7月22号总结

一、实现查询功能

1、在UserBar.html中添加一个搜索框和查询按钮

<form action="selectGoods" th:object="${goodsForm}" method="post">

<input type="text" name="commodityName"/>

<input type="submit" value="检索"/>

2、在GoodsController中

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

    public String  selectGoods(Model model,HttpSession session,GoodsForm goodsForm,Device device){

    log.info("检索相关商品");

    List<GoodsForm> list=goodsService.searchGoodsListrelative(goodsForm);

    model.addAttribute("list",list);

    UVO uvo = (UVO)session.getAttribute("UVO");

    if (uvo == null) {

    uvo = new UVO();

    session.setAttribute("UVO", uvo);

    }

    CartForm cartForm = new CartForm();

    cartForm.setGuestId(uvo.getGuestId());

    model.addAttribute("cartList", cartService.searchCartList(cartForm));

    if(device.isNormal()) {

    return "shop/index";

    } else {

    return "mobile/index";

    }

    }

3、在GoodsService中

public List<GoodsForm> searchGoodsListrelative(GoodsForm frm) {

List<GoodsForm> result = queryDao.executeForObjectList("Goods.selectGoodsListrelative", frm);

return result;

}

4、在GoodsSqlMap中

<select id="selectGoodsListrelative"

parameterClass="cn.agriculture.web.form.GoodsForm"

resultClass="cn.agriculture.web.form.GoodsForm">

SELECT commodity.commodity_id as commodityId,

commodity.type as type,

supplier.supplier_name as supplierName,

brand.brand_name as brandName,

commodity.commodity_name as commodityName,

commodity.weight as weight,

commodity.is_gift as isGift,

commodity.specifications as specifications,

commodity.unit as unit,

commodity.benchmark_price as benchmarkPrice,

commodity.guide_price as guidePrice,

commodity.retail_price as retailPrice,

commodity.competition_level as competitionLevel,

commodity.note as note,

commodity.update_time as updateTime,

commodity.update_user as updateUser,

commodity.picture_id as pictureId,

stock.stock as stock

FROM commodity, supplier, brand, stock

WHERE commodity.commodity_id = stock.commodity_id

AND commodity.supplier_id = supplier.supplier_id

AND commodity.brand_id = brand.brand_id

AND commodity.commodity_name LIKE '%$commodityName$%'

</select>

二、实现格式控制

  1、@Null 被注释的元素必须为 null

        @NotNull 被注释的元素必须不为 null

        @AssertTrue 被注释的元素必须为 true

        @AssertFalse 被注释的元素必须为 false

        @Min(value) 被注释的元素必须是一个数字,其值必须大于等于指定的最小值

        @Max(value) 被注释的元素必须是一个数字,其值必须小于等于指定的最大值

        @DecimalMin(value) 被注释的元素必须是一个数字,其值必须大于等于指定的最小值

        @DecimalMax(value) 被注释的元素必须是一个数字,其值必须小于等于指定的最大值

        @Size(max, min) 被注释的元素的大小必须在指定的范围内

        @Digits (integer, fraction) 被注释的元素必须是一个数字,其值必须在可接受的范围内

        @Past 被注释的元素必须是一个过去的日期

        @Future 被注释的元素必须是一个将来的日期

        @Pattern(value) 被注释的元素必须符合指定的正则表达式hibernate对这个规范做了实现和扩展;

        @Email 被注释的元素必须是电子邮箱地址

        @Length 被注释的字符串的大小必须在指定的范围内

        @NotEmpty 被注释的字符串的必须非空

        @Range 被注释的元素必须在合适的范围内

    2、例:对QQ,Email,Zip实现控制

        @Email(message="{errors.email}")

     private String email;

     @Digits(fraction = 0, integer = 11,message="{errors.qq}")

     private String qq;

     @Digits(fraction = 0, integer = 6,message="{errors.zip}")

     @Length(min=6,max=6,message="{errors.zip}")

     private String zip;


你可能感兴趣的:(7月22号总结)