1.重点易遗漏之处
给在mapper类对应的方法参数加上@Param注解
public List<Song> selectSongListByIds(@Param(value = "songIds") String songIds);
2.在xml中使用${}、#{}皆可,但有细微差别
使用${}在MyBatis中已可直接取到值,与’'结合生成sql格式字符串已是sql语法问题
<select id="selectSongListByIds" parameterType="String" resultMap="SongResult">
<include refid="selectSongVo"/>
<where>
<if test="songIds != null "> regexp_like('${songIds}', concat('(,', song_id, ',)'))</if>
</where>
</select>
使用#{}是取到值的同时直接生成sql格式字符串
<select id="selectSongListByIds" parameterType="String" resultMap="SongResult">
<include refid="selectSongVo"/>
<where>
<if test="songIds != null "> regexp_like(#{songIds}, concat('(,', song_id, ',)'))</if>
</where>
</select>

博客围绕Java和MyBatis的数据持久化展开,指出在mapper类对应方法参数上加@Param注解这一易遗漏重点,还介绍了在xml中使用${}和#{}的情况,${}可直接取值,与''结合涉及sql语法,#{}取值时直接生成sql格式字符串。

8814

被折叠的 条评论
为什么被折叠?



