mysql实践操作总结

抽取公共的sql语句

在mybatis的动态sql编写中,通过<sql>标签抽取可重用的sql片段,常见于可重复利用的查询语句,实现语句复用;在使用时,通过<include refid="sql_id"></include>引入,可达到跟写在同一个查询语句中一样的效果。

<!-- =====================公共sql语句===================== -->
<!-- 用于读者移动端,根据关键字搜索(类型,图书名,作者) -->
<sql id="searchBy">
	<where>
		<if test="bookType!= null and bookType !=''">
			and instr(book_type,#{bookType})>0
		</if>
		<if test="searchContent!= null and searchContent !=''">
			and instr(book_name,#{searchContent})>0 or instr(book_auth,#{searchContent})>0
		</if>
		and book_status=0
	</where>
</sql>

<!-- =====================读者移动端====================== -->
<!--按分类或关键字查找  -->
<select id="findBooksBy" resultMap="BookResultMap">
		select * from t_ts_book
		<include refid="searchBy"></include>
		limit #{start},#{end}
</select>

mysql中INSTR函数的用法

INS

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值