mySql一个字段的值模糊匹配多表多列的查询

1.dao层
/**
* 分页查询点卡集合信息
* @param tid 游戏类型编号
* @param gid 游戏编号
* @param searchInfo 包括(点卡名称,游戏名称,点卡面值,游戏类型名称)
* @param index
* @param pagesize
* @return
*/
List<Cards> searchList(@Param("tid") int tid,
@Param("gid") int gid,
@Param("searchInfo") String searchInfo,
@Param("index") int index,
@Param("pagesize") int pagesize);
2.mybatis的xml
<select id="searchList" resultType="Cards">
SELECT c.*,g.`gid` AS gid,g.`gName` AS gName
FROM `cards` AS c JOIN `gameOrCard` AS ga ON c.cid=ga.cid
JOIN `games` AS g ON g.`gid`=ga.`gid`
JOIN `gamestype` AS ty ON g.`tId`=ty.`tId`
<where>
<if test="tid>0">AND g.`tid`=#{tid}</if>
<if test="gid>0">AND g.`gid`=#{gid}</if>
<if test="searchInfo != null and searchInfo != ''">
AND CONCAT_WS(
c.`cName`,g.`gName`,c.`iniPrice`,ty.`tName`
)LIKE CONCAT('%',#{searchInfo},'%')
</if>
</where>
AND c.isShelves=0 ORDER BY g.gid
limit #{index},#{pagesize}
</select>
<!--注解:cards点卡信息表;games游戏信息表;gameOrcard游戏与点卡的关系表;gamestype游戏类型表-->
 上述完成了用户输入一个值,可以模糊匹配查询“点卡名称”,“充值游戏”,“点卡的面值”,“游戏的类型名称”来搜索结果。

猜你喜欢

转载自www.cnblogs.com/wen-/p/12408846.html