一个列表的模块统一

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 {

	@Autowired
	private 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);
		
		// 返回ModelAndView
		ModelAndView 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;


实现

	@Autowired
	private ItemsMapper itemsMapper;

	// 列表
	@Override
	public 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值