7.参数绑定-pojo包装类型(传智播客)

需求:根据商品名称模糊匹配商品信息

1.controller层开发

//根据商品名称模糊匹配商品信息
@RequestMapping("/queryItemByItemName")
public ModelAndView queryItemByItemName(ItemsQueryVo itemsQueryVo) throws Exception{
    List<Items> itemsList = itemsService.getItemListByItemName(itemsQueryVo);
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.addObject("itemsList",itemsList);
    modelAndView.setViewName("items/queryItemByItemName");
    return modelAndView;
}

2.service层开发

//ItemsService
//根据商品名称模糊匹配商品信息
List<Items> getItemListByItemName(ItemsQueryVo itemsQueryVo) throws Exception;
//ItemsServiceImpl
//根据商品名称模糊匹配商品信息
@Override
public List<Items> getItemListByItemName(ItemsQueryVo itemsQueryVo) throws Exception {
    return itemsMapperCustom.getItemsListByItemName(itemsQueryVo);
}

3.dao层开发

//mapper接口
//根据商品名称模糊匹配商品信息
List<Items> getItemsListByItemName(ItemsQueryVo itemsQueryVo)throws Exception;
//sql映射文件
<!--根据商品名称模糊匹配商品信息-->
<select id="getItemsListByItemName" parameterType="itemsQueryVo" resultMap="queryItems">
   SELECT  * FROM item
   where item_name like '%${itemsCustom.itemName}%'
</select>
//pojo包装类
public class ItemsQueryVo {
    //为了系统 可扩展性,对原始生成的po进行扩展
    private ItemsCustom itemsCustom;
     //get和set方法......
}

4.web层开发

//提交请求的表单
<form id="itemQueryForm" name="itemQueryForm" method="post">
    查询条件:
    <table width="100%" border=1>
        <tr>
            <td><input type="text" name="itemsCustom.itemName"/></td>
            <td><input type="submit" value="查询" onclick="queryItemByItemName()"/></td>
        </tr>
    </table>
</form>
//显示数据的表单
<form id="itemQueryForm" action="${pageContext.request.contextPath}/items/queryItems" method="post">
    查询条件:
    <table width="100%" border=1>
        <tr>
            <td><input type="text" name="itemsCustom.itemName"/></td>
            <td><input type="submit" value="查询"/></td>
        </tr>
    </table>
    商品列表:
    <table width="100%" border=1>
        <tr>
            <td>商品编号</td>
            <td>商品名称</td>
            <td>商品价格</td>
            <td>商品描述</td>
            <td>操作</td>
        </tr>
        <c:forEach items="${itemsList}" var="item">
            <tr>
                <td>${item.itemId}</td>
                <td>${item.itemName}</td>
                <td>${item.itemPrice}</td>
                <td>${item.itemDetail}</td>
                <td><a href="${pageContext.request.contextPath}/items/selectItem?id=${item.itemId}">修改</a></td>
            </tr>
        </c:forEach>
    </table>
</form>

猜你喜欢

转载自blog.csdn.net/u010286027/article/details/84861787
今日推荐