报错信息如下:
17:47:20.743 [https-jsse-nio-8080-exec-9] WARN c.g.p.p.OrderByParser - [converToOrderBySql,70] - 处理排序失败: net.sf.jsqlparser.JSQLParserException: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "," ","
at line 1, column 16.
Was expecting one of:
"&"
"::"
";"
"<<"
">>"
"COLLATE"
"CONNECT"
"EMIT"
"GROUP"
"HAVING"
"INTO"
"START"
"WINDOW"
"["
"^"
"|"
<EOF>
,降级为直接拼接 order by 参数
查找问题所在: 查看我的数据库xml文件会发现如下代码:
<resultMap type="YtLawApply" id="YtLawApplyResult">
<result property="id" column="id" />
<result property="name" column="name" />
<result property="connect" column="connect" />
<result property="argument" column="argument" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
</resultMap>
<sql id="selectYtLawApplyVo">
select id, name, connect, argument, create_by, create_time, update_by, update_time, remark from yt_law_apply
</sql>
<select id="selectYtLawApplyList" parameterType="YtLawApply" resultMap="YtLawApplyResult">
<include refid="selectYtLawApplyVo"/>
<where>
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
<if test="connect != null and connect != ''"> and connect like concat('%', #{connect}, '%')</if>
<if test="argument != null and argument != ''"> and argument like concat('%', #{argument}, '%')</if>
</where>
</select>
修改代码,解决问题:
<sql id="selectYtLawApplyVo">
select id, `name`, `connect`, argument, create_by, create_time, update_by, update_time, remark from yt_law_apply
</sql>
理由: 在MyBatis中,name 和connect可能是作为MyBatis配置或映射文件中的特定属性名或者XML元素名被使用。所以尽量使用user_name,connect_way命名。 对这种可能有冲突的字段名添加反引号(`)解决问题, 避免在大多数情况下产生关键字冲突。