<!-- 删除之主键删除id
注意:如果参数类型是基本数据类型,那么sql语句的参数名称可以随便起
--><deleteid="deleteProductById"parameterType="int">
delete from product where id=#{asfdsafasd}
</delete><!-- 删除之参数类型是pojo类
注意:如果参数类型是pojo类类型,那么sql语句的参数名称不可以随便起,必须和当前实体类中的属性名称相对应
--><deleteid="deleteProductByPojo"parameterType="product">
delete from product where id=#{id}
</delete>
//模糊查询之普通类型public List selectProductBySearch(String name);//模糊查询之pojopublic List selectProductBySearch1(Product product);//模糊查询之pojo2public List selectProductBySearch2(Product product);//模糊查询之mappublic List selectProductBySearch3(Map map);
3.2 sql映射文件
<!-- 1. 如果说参数类型是普通类型,那么在执行模糊查询的时候,只能使用#{}进行拼接查询 --><selectid="selectProductBySearch"parameterType="java.lang.String"resultType="products">
select
<includerefid="basesql"/>
from product
where name like CONCAT(CONCAT('%',#{name},'%'))
</select><!-- 2.模糊查询之模糊查询 之以${}形式
参数必须是实体类类型,sql语句中参数名称不可以随意起,必须是实体类的属性名称 --><selectid="selectProductBySearch1"parameterType="products"resultType="products">
select
<includerefid="basesql"/>
from product
where name like '%${name}%'
</select><!-- 3.采用#{} --><selectid="selectProductBySearch2"parameterType="products"resultType="products">
select
<includerefid="basesql"/>
from product
where name like "%"#{name}"%"
</select><!--4.如果参数类型是map类型,那么sql语句中参数值一定是map集合中的key值 --><selectid="selectProductBySearch3"parameterType="map"resultType="products">
select
<includerefid="basesql"/>
from product
where name like CONCAT(CONCAT('%',#{aaa},'%'))
</select>