b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

sql注入 过滤_mybatis sql注入_sql注入攻击(2)

电脑杂谈  发布时间:2017-03-02 05:05:52  来源:网络整理

MAPPER :

<select id="exists" parameterType="java.util.HashMap" resultType="java.lang.Integer">
		SELECT COUNT(*) FROM USER user
		<where>
			<if test="code != null"> 
				and user.CODE = #{code} 
			</if>
			<if test="id != null"> 
				and user.ID = #{id} 
			</if>
			<if test="idList !=null ">
				and user.ID in (
				<foreach item="guard" index="index" collection="idList"
					separator=","> #{guard} </foreach>
				)
			</if>
		</where>
	</select>

MAP中有list或array时,foreach中的collection必须是具体list或array的变量名。mybatis sql注入比如这里MAP含有一个

名为idList的list,所以MAP中用idList取值,这点和单独传list或array时不太一样。

5. 传入JA对象

JA代码:

public boolean findUserListByDTO(UserDTO userDTO){
		Object count = getSqlSession().selectOne("com.liulanghan.exists", userDTO);
		int totalCount = Integer.parseInt(count.toString());
		return totalCount > 0 ? true : false;
	}

MAPPER :

<select id="findUserListByDTO" parameterType="UserDTO" resultType="java.lang.Integer">
		SELECT COUNT(*) FROM USER user
		<where>
			<if test="code != null"> 
				and user.CODE = #{code} 
			</if>
			<if test="id != null"> 
				and user.ID = #{id} 
			</if>
			<if test="idList !=null ">
				and user.ID in (
				<foreach item="guard" index="index" collection="idList"
					separator=","> #{guard} </foreach>
				)
			</if>
		</where>
	</select>

JA对象中有list或array时,foreach中的collection必须是具体list或array的变量名。比如这里UserDTO含有一个


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-35320-2.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...