Java SSM框架里面,Mapper.xml文件
(一)#符号生成的sql语句是作为传参的
<!-- 获得数据列表(包括课程相关信息) --> <select id="GetListByUidAndType" resultMap="BaseResultMap" parameterType="Map"> select <include refid="Base_Column_List" /> from my_favorites where uid=#{uid} and type=#{type} <if test="strWhere !=''"> and #{strWhere} </if> <if test="filedOrder!=''"> order by #{filedOrder} </if> limit #{page.startPos},#{page.pageSize} </select>
DEBUG - ==> Preparing: select nid, uid, title,brief, key_value, type, addtime from my_favorites where uid=? and type=? order by ? limit ?,?
DEBUG - ==> Parameters: 1(String), 1(Integer), addtime desc(String), 0(Integer), 10(Integer)
(二)而$符号生成的sql语句是作为占位符显示的
<!-- 获得数据列表(包括课程相关信息) --> <select id="GetListByUidAndType" resultMap="BaseResultMap" parameterType="Map"> select <include refid="Base_Column_List" /> from my_favorites where uid=${uid} and type=${type} <if test="strWhere !=''"> and ${strWhere} </if> <if test="filedOrder!=''"> order by ${filedOrder} </if> limit ${page.startPos},${page.pageSize} </select>
DEBUG - ==> Preparing: select nid, uid, title,brief, key_value, type, addtime from my_favorites where uid=1 and type=1 order by addtime desc limit 0,10
DEBUG - ==> Parameters:
(三)需要注意的是:当strWhere为拼接sql语句字符串时,如status=1,这时候使用#号会查不出结果,必须使用$号作为变量
<select id="GetRecordCount" resultType="java.lang.Integer" parameterType="Map"> select count(*) from course_books <if test="strWhere !=''"> where ${strWhere} </if> <if test="filedOrder!=''"> order by #{filedOrder} </if> </select>