itemsCustom里的配置:
<?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="cn.yrtd.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>
<!-- 最重要的是sql语句 -->
<!-- 商品列表查询 -->
<!-- parameterType传输的东西可能不止只有 商品信息 可能还有与之相关的东西 -->
<select id="findItemsList" parameterType="cn.yrtd.ssm.po.ItemsQueryVo"
resultType="cn.yrtd.ssm.po.ItemsCustom">
<!-- 返回的对象resultType要使用可扩展的类 因为如果之后查询条件等改变了 使用items就不管用了 -->
SELECT * FROM Items
</select>
</mapper>
查询所有的时候能查询出来 页面显示结果:
查询条件改为
SELECT * FROM Items
<where>
Items.name LIKE '%笔记本%'
</where>
</select>
就查不出结果了
网页显示:
控制台显示:
数据库里同样条件查询结果: