三月 01, 2017 11:14:40 上午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [spring] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException:
### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' and 1=1 ' limit 0,5' at line 3
### The error may exist in com/lsj/mapper/FinanceProducts.xml
### The error may involve
### The error occurred while setting parameters
### SQL: select * from financeProducts f,jiekuanType j,huankuanfangshi h,user u where f.jiekuanTypeId=j.jiekuanTypeId and f.huankuanfangshiId=h.huankuanfangshiId and f.productReleaserId=u.uid ? limit ?,?
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' and 1=1 ' limit 0,5' at line 3
; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' and 1=1 ' limit 0,5' at line 3] with root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' and 1=1 ' limit 0,5' at line 3
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
上面的错误解决需要熟悉 #与$
的差别(参下)
MyBatis/Ibatis中#和$的区别
http://blog.youkuaiyun.com/downkang/article/details/12499197/
结合以上(关键错误点 near ” and 1=1 ’ limit 0,5’ at line 3)
我的解决办法将#替为$(不推荐)
推荐写法(在Controller层中 将要搜索的条件put进Map 集合 然后传参 在mapper.xml 中遍历 这样更安全 )
顺便熟悉一下mybatis 传参
一、单个参数:
public List getXXBeanList(String xxCode);
select t.* from tableName t where t.id= #{id}
其中方法名和ID一致,#{}中的参数名与方法中的参数名一直
select 后的字段列表要和bean中的属性名一致, 如果不一致的可以用 as 来补充。
二、多参数:
public List getXXXBeanList(String xxId, String xxCode);
select t.* from tableName where id = #{0} and name = #{1}
由于是多参数那么就不能使用parameterType, 改用#{index}是第几个就用第几个的索引,索引从0开始
三、Map封装多参数:
public List getXXXBeanList(HashMap map);
select 字段… from XXX where id=#{xxId} code = #{xxCode}
其中hashmap是mybatis自己配置好的直接使用就行。map中key的名字是那个就在#{}使用那个
四、List封装in:
public List getXXXBeanList(List list);
select 字段… from XXX where id in
#{item}
foreach 最后的效果是select 字段… from XXX where id in (‘1’,’2’,’3’,’4’)