一个列表的模块统一

来源:互联网 发布:华傲数据借壳天源迪科 编辑:程序博客网 时间:2024/05/22 17:29

1

<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.name }</td><td>${item.price }</td><td><fmt:formatDate value="${item.createtime}" pattern="yyyy-MM-dd HH:mm:ss"/></td><td>${item.detail }</td><td><a href="${pageContext.request.contextPath }/items/editItems.action?id=${item.id}">修改</a></td></tr></c:forEach></table>


2

@Controller@RequestMapping("/items")public class ItemsController {@Autowiredprivate ItemsService itemsService;// 商品查询列表@RequestMapping("/queryItems")public ModelAndView queryItems(HttpServletRequest request) throws Exception {//测试forward后request是否可以共享System.out.println(request.getParameter("id"));// 调用service查找 数据库,查询商品列表List<ItemsCustom> itemsList = itemsService.findItemsList(null);// 返回ModelAndViewModelAndView modelAndView = new ModelAndView();// 相当 于request的setAttribut,在jsp页面中通过itemsList取数据modelAndView.addObject("itemsList", itemsList);modelAndView.setViewName("items/itemsList");return modelAndView;}


3

接口

<span style="white-space:pre"></span>// R.商品查询列表/** *  * <p>Title: findItemsById</p> * <p>Description: </p> * @param 商品查询列表 * @return * @throws Exception */public List<ItemsCustom> findItemsList(ItemsQueryVo itemsQueryVo) throws Exception;


实现

@Autowiredprivate ItemsMapper itemsMapper;// 列表@Overridepublic List<ItemsCustom> findItemsList(ItemsQueryVo itemsQueryVo)throws Exception {//通过ItemsMapperCustom查询数据库return itemsMapperCustom.findItemsList(itemsQueryVo);}


4

接口

public interface ItemsMapperCustom {// 商品查询列表public List<ItemsCustom> findItemsList(ItemsQueryVo itemsQueryVo)throws Exception;}
实现

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" ><mapper namespace="com.wyz.ssm.mapper.ItemsMapperCustom" >   <!-- 定义商品查询的sql片段,就是商品查询条件 -->   <sql id="query_items_where">   <!-- 使用动态sql,通过if判断,满足条件进行sql拼接 -->   <!-- 商品查询条件通过ItemsQueryVo包装对象 中itemsCustom属性传递 -->   <if test="itemsCustom!=null">   <if test="itemsCustom.name!=null and itemsCustom.name!=''">   items.name LIKE '%${itemsCustom.name}%'   </if>   </if>   </sql>    <!-- 商品列表查询 -->  <!-- parameterType传入包装对象(包装了查询条件)  resultType建议使用扩展对象   -->  <select id="findItemsList" parameterType="com.wyz.ssm.po.ItemsQueryVo"   resultType="com.wyz.ssm.po.ItemsCustom">  SELECT items.* FROM items    <where>  <include refid="query_items_where"></include>  </where>  </select>  </mapper>


5

6

0 0
原创粉丝点击