问题:Mybatis提示Tag name expected
原因:
- 小于
<
<
相当于 小于
<
注意:分号记得加上去
- 小于等于
≤
<=
相当于 小于等于
<=
解決方式一:
使用预定义字符來代替,直接填写预定义字符:
字符 | 预定义字符 |
---|---|
< | < |
> | > |
" | " |
’ | ' |
& | & |
解决方法二:
使用 <![CDATA[ ]]>
语法
?CDATA說明:
在方括号内 [ ] 输入之前会报错的字符,比如是小于号,那么就在方括号内写入小于号 <
如下所示:
<![CDATA[<]]>
相当于 小于号,能够让 xml 文件内的小于号 <
被识别,否则就会报Tag name expected
的错误。
具体例子:
条件是 数据库内某个表 test_table 限定查询条件是该表的字段名 number 必须是小于等于 ≤ 传参的值 #{number}
,而且前提是传参的 #{number}
,必须不能为 null
和空字符串 ''
<select id="getTestDate" resultType="com.test.entity.TestEntity">
SELECT * FROM test_table
<where>
<if test="number!=null and number.trim() neq ''">
AND number <![CDATA[<=]]> #{number}
</if>
</where>
</select>
参考链接
1. Mybatis提示Tag name expected的问题
2. Tag name expected 解决
3. idea編輯XML文件出現:Tag name expected報錯
4. batis映射文件xml不能使用"<",tag name expected
5. idea編輯XML文件出現:Tag name expected報錯