concat
属于数据库函数,MySQL 和 Oracle 都支持,用于字符串连接,而且可以使用 #
作为占位符,防止 SQL 注入。
<!--根据产品件号模糊查询机信息 -->
<select id="selectInStockByPartNum" resultType="com.inchlifc.entity.InStock">
SELECT * FROM in_stock
<where>
<if test="partNum!=null">
partNum LIKE CONCAT('%', #{partNum}, '%')
</if>
</where>
ORDER BY createTime desc
</select>
Sql标签用法
<!--Sql标签作用: 抽取公共的部分,可以被其它的Sql引用-->
<sql id="findColumn">
select id,name,age,sex from demo_user
</sql>
<select id="findByLike" resultType="User">
<include refid="findColumn"/> where name like "%"#{key}"%"
</select>