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

sql注入 过滤_mybatis sql注入_sql注入攻击

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

sql注入 过滤_sql注入攻击_mybatis sql注入

Parameter

1. 传入简单类型

JA代码:

public User get(Long id) {	
	return (User) getSqlSession().selectOne("com.liulanghan.get" , id);
}

MAPPER :

<select id="findUserListByIdList" parameterType="java.lang.Long" resultType="User">
		select * from user where  id = #{id};
</select>

2. 传入List

JA代码:

public List<Area> findUserListByIdList(List<Long> idList) {
		return getSqlSession().selectList("com.liulanghan.findUserListByIdList", idList);
	}

MAPPER :

    <select id="findUserListByIdList" parameterType="java.util.ArrayList" resultType="User">
		select * from user user
		<where>
			user.ID in (
			<foreach item="guard" index="index" collection="list"
				separator=","> #{guard} </foreach>
			)
		</where>
	</select> 

单独传入list时,foreach中的collection必须是list,不不管变量的具体名称是什么。比如这里变量名为idList,

collection却是是list。

3. 传入数组

JA代码:

public List<Area> findUserListByIdList(int[] ids) {
		return getSqlSession().selectList("com.liulanghan.findUserListByIdList", ids);
	}

MAPPER :

 <select id="findUserListByIdList" parameterType="java.util.HashList" resultType="User">
		select * from user user
		<where>
			user.ID in (
			<foreach item="guard" index="index" collection="array"
				separator=","> #{guard} </foreach>
			)
		</where>
	</select>   

单独传入数组时,foreach中的collection必须是array,不不管变量的具体名称是什么。比如这里变量名为ids,

collection却是是array

sql注入攻击_mybatis sql注入_sql注入 过滤

4. 传入map

JA代码:

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


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

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

    • 梁国栋
      梁国栋

      太夸张了

    • 贺军翔
      贺军翔

      知道为什么中共对所谓的岛内运动不屑一顾吗

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