spring 模糊查询,查询

MyBatis模糊查询配置


https://www.5ceo.cn 更多技术博文点击查看




<select id="find" parameterType="com.sfbm.carmall.persistent.model.brand.Brand"

resultType="map">
SELECT
t.brand_id brandId,
t.brand_name brandName,
t.description
description,
t.url url
FROM
t_brand t where t.delFlag=0
<if test="brand_name!=null and  ''!=brand_name ">
and t.brand_name like '%${brand_name}%'
</if>
</select>
resultType

为map集合,参数类型可以为,string,entity,以及map 

1.如果参数类型为string  那么 brand_name like '%${value}%'此处必须为value,如果为其他属性将报no Getter的错误

2.如果是对象entity,则parameterType必须是“package.class”的格式,并且 "%${}%"中的属性必须是entity中的属性。

3.如果参数为map,则parameterType是Java.util.Map,并且"%${}%"中的属性必须是map中的key。

*如果jsp页面用对象传值到control,则jsp页面应该这样写:

<input name="brand_name"> brand_name必须是entity中的属性。并且不用entity.brand_name这样的方式

*control中必须用@ModelAttribute绑定该对象

@ModelAttribute("entity") Entity entity

模糊查询时,%${brand_name}% {}前面不能是#,必须是${}

或者Oracle 用concat(concat('%',#{}),'%')mysql:concat('%',#{},‘%’)

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值