模拟sql注入以及当中遇到的问题

Hibernate模拟sql注入

不使用?占位符以及其他set之类的防止注入的方法,直接字符串拼接。不支持多语句hibernate会产生异常,异常类型:org.hibernate.QueryException: unexpected char: ';'

 

Mybatis模拟sql注入

         不使用#{} ,而使用${}${}不参与sql编译并且不会加’’,和hibernate同样,mybatis也不支持多语句,产生异常:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax;

参数类型为String时,使用中遇见的问题

参考帖子:http://blog.csdn.net/qing_gee/article/details/47122227

1)         直接使用#{example } 不会出现问题,但是用到<when test=" example!= null">,你有一个对应的test判断语句,也可能是if。此时项目运行该查询语句时,就会抛出There is no getter for property named example in 'class java.lang.String'错误!

解决方法

a)    方法一:

判断语句后面用_parameter代替example,即<when test="_parameter!= null">,语句内的不变,为#{example}

b)    方法二:

intercface层参数前使用@Param(“example”),xml中就可以直接使用example来作为参数名称了

2)    直接使用${example}的时候就会产生异常

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'example ' in 'class java.lang.String'

         其他问题同上,解决的方法也同上。

猜你喜欢

转载自whenjun.iteye.com/blog/2379021