创建sql片段<sql id=“取名”></sql>
引入sql片段(include)
使用<bind name="val" value="'%'+name+'%'"/>可以进行字符串拼接
<?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>