SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4529fa91]

本文记录了在使用MyBatis框架时遇到的表达式语法错误问题,详细描述了错误信息及定位过程,最终在mapper.xml文件中找到了问题所在,即在条件判断语句中使用了不正确的表达式格式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

控制台日志如下

DEBUG - Creating a new SqlSession
DEBUG - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4529fa91] was not registered for synchronization because synchronization is not active
DEBUG - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4529fa91]

并没有看出错误原因是什么,可以断定是SQL语句那里的,随即在SQL语句上加上try catch查看

try {
    dao.saveWithKey("com.test.mapper.SingleWindowVehicleMapper.addSheet2", body);
} catch (Exception e) {
    e.printStackTrace();
}

catch查看异常如下

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 'createDate != null''. Cause: org.apache.ibatis.ognl.ExpressionSyntaxException: Malformed OGNL expression: createDate != null' [org.apache.ibatis.ognl.TokenMgrError: Lexical error at line 1, column 20.  Encountered: <EOF> after : ""]

检查mapper.xml果然这里有问题

<if test="createDate != null'">#{createDate},</if>

 

Creating a new SqlSession SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6d2bf1a5] was not registered for synchronization because synchronization is not active JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@4dae0fa1] will not be managed by Spring ==> Preparing: SELECT * FROM t_product_category WHERE parent_id=? ==> Parameters: 290(Integer) <== Columns: id, parent_id, name, status, sort_order, is_parent, created_time, modified_time, created_user, modified_user <== Row: 291, 290, 钟表, 1, 1, 1, 2017-10-25 15:00:55, 2017-10-25 15:00:55, admin, admin <== Total: 1 Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6d2bf1a5] 当前业务耗费3ms Creating a new SqlSession SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6d40077d] was not registered for synchronization because synchronization is not active JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@4dae0fa1] will not be managed by Spring ==> Preparing: SELECT * FROM t_product_category WHERE parent_id=? ==> Parameters: 438(Integer) <== Columns: id, parent_id, name, status, sort_order, is_parent, created_time, modified_time, created_user, modified_user <== Row: 439, 438, 维修保养, 1, 1, 1, 2017-10-25 15:00:55, 2017-10-25 15:00:55, admin, admin <== Row: 456, 438, 车载电器, 1, 2, 1, 2017-10-25 15:00:55, 2017-10-25 15:00:55, admin, admin <== Row: 467, 438, 美容清洗, 1, 3, 1, 2017-10-25 15:00:55, 2017-10-25 15:00:55, admin, admin <== Row: 474, 438, 汽车装饰, 1, 4, 1, 2017-10-25 15:00:55, 2017-10-25 15:00:55, admin, admin <== Row: 486, 438, 安全自驾, 1, 5, 1, 2017-10-25 15:00:55, 2017-10-25 15:00:55, admin, admin <== Total: 5 Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6d40077d] 当前业务耗费4ms
06-04
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值