报错信息1
Parameter index out of range (26 > number of parameters, which is 25)
- 翻译
- 当设置参数时,没有相应的问号与之匹配(或者根本就没有?号)
- 找到了25个问号,却插入了26个值,导致参数越界(根据得到的信息打印将很容易判断数据是否与数据库字段匹配等小问题)。
- 解决1
- 解决2
查看单引号内是否引用使用了#,如果是请改为$
- 比如
- 平时我们写SQL like语句的时候 一般都会写成 like ‘% %’
- 在Mybatis里面写就是应该是
like '%${name} %' 而不是like '%#{name} %'
- 解决3
sql语句中没有?号,在后面用到了set语句。
- 比如:
- 解决4
claType 是数组,是否在sql中或者注释中使用了#,如果是修改成$
<if test="claType != null and claType.size > 0">
and cla_class_type IN
<foreach item="status" collection="claType" open="(" separator="," close=")">
</foreach>
</if>
<if test="claType != null and claType.size > 0">
and cla_class_type IN
<foreach item="status" collection="claType" open="(" separator="," close=")">
${status}
</foreach>
</if>
and cla_class_type IN
(
1
,
2
,
4
)
报错信息2
The content of elements must consist of well-formed character data or markup.
- 翻译
- 不是格式良好的xml
- 也就是我们的书写格式有误,原来是因为编译器自动把sql语句中的小于号当成了开始标签,那就当然会报错了
- 解决1
- 用标签
<![CDATA[你的大于或小于sql ]]>包起来
- 比如:
<![CDATA[
and create_time >=
]]>
报错信息3
Error evaluating expression 'readingStatus != null and readingStatus.size > 0'. Cause: org.apache.ibatis.ognl.NoSuchPropertyException: java.lang.String.size
- 这是我在配置t-service的时候报错的
<if test="readingStatus != null and readingStatus.size > 0">
subject_reading_status IN
<foreach item="status" collection="readingStatus" open="(" separator="," close=")">
</foreach>
</if>
报错信息4
Caused by: org.apache.ibatis.ognl.ParseException: Encountered "<EOF>" at line 1, column 0. Was expecting one of:......................
- 翻译
- 比如,我格式化了一下代码,把if判断中的and格式化成了AND。。。。然后
- 具体报错信息可以参考
Error evaluating expression 'wechatId != null AND wechatId != '''.
Cause: org.apache.ibatis.ognl.ExpressionSyntaxException:
Malformed OGNL expression: wechatId != null AND wechatId != ''
[org.apache.ibatis.ognl.ParseException: Encountered " <IDENT> "AND "" at line 1, column 27.
Was expecting one of: <EOF>
"," ...
"=" ...
"?" ...
"||" ...
"or" ...
"&&" ...
"and" ...
"|" ...
"bor" ...
"^" ...
"xor" ...
"&" ...
"band" ...
"==" ...
"eq" ...
"!=" ...
"neq" ...
"<" ...
"lt" ...
">" ...
"gt" ...
"<=" ...
"lte" ...
">=" ...
"gte" ...
"in" ...
"not" ...
"<<" ...
"shl" ...
">>" ...
"shr" ...
">>>" ...
"ushr" ...
"+" ...
"-" ...
"*" ...
"/" ...
"%" ...
"instanceof" ...
"." ...
"(" ...
"[" ...
<DYNAMIC_SUBSCRIPT> ...
]
Caused by: org.apache.ibatis.ognl.ParseException: Encountered "<EOF>" at line 1, column 0.
Was expecting one of:
":" ...
"not" ...
"+" ...
"-" ...
"~" ...
"!" ...
"(" ...
"true" ...
"false" ...
"null" ...
"#this" ...
"#root" ...
"#" ...
"[" ...
"{" ...
"@" ...
"new" ...
<IDENT> ...
<DYNAMIC_SUBSCRIPT> ...
"\'" ...
"`" ...
"\"" ...
<INT_LITERAL> ...
<FLT_LITERAL> ...
报错信息5
- 问题复现→
<if test="aIn != 'A'" >
- 原因
- 解决1(加.toString())
<if test="aIn != 'A'.toString()" >
- 解决2(改为单引号包双引号)