mybatis框架mapper.xml中sql片段的使用

创建sql片段

引入sql片段(include)

使用可以进行字符串拼接

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.software.mapper.StudentMapper">

    <sql id="student_column">id,name,teacher_id</sql>

    <select id="selectById" resultType="Student">
        <bind name="val" value="'%'+name+'%'"/>
        SELECT <include refid="student_column"></include> FROM student WHERE `name` like #{val}
    </select>
</mapper>

你可能感兴趣的:(学习心得,mybatis)