今天调试没有注意写了下面语句
select sns.send_id, sns.notice_id, sns.user_id, sns.read_flag, sa.notice_title as notice_title, sa.notice_content as notice_content, sa.sender as sender, sa.priority as priority, sa.notice_type as notice_type, sa.send_time as send_time from sys_notice_send sns left join sys_notice sa ON sns.notice_id = sa.notice_id left join sys_user ur ON sns.user_id = ur.user_id where sa.send_status = '1' and sa.status = '0' and sns.user_id = #{noticeSendModel.userId}
结果报错,如下:
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427) ... 109 common frames omitted Caused by: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Failed to process, Error SQL: select sns.send_id, sns.notice_id, sns.user_id, sns.read_flag, sa.notice_title as notice_title, sa.notice_content as notice_content, sa.sender as sender, sa.priority as priority, sa.notice_type as notice_type, sa.send_time as send_time from sys_notice_send sns left join sys_notice sa ON sns.notice_id = sa.notice_id left join sys_user ur ON sns.user_id = ur.user_id where sa.send_status = '1' and sa.status = '0' and sns.user_id = ? order by sns.read_flag,sa.send_time desc at com.baomidou.mybatisplus.core.toolkit.ExceptionUtils.mpe(ExceptionUtils.java:39) at com.baomidou.mybatisplus.extension.parser.JsqlParserSupport.parserSingle(JsqlParserSupport.java:52) at com.ruoyi.framework.interceptor.PlusDataPermissionInterceptor.beforeQuery(PlusDataPermissionInterceptor.java:49) at com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor.intercept(MybatisPlusInterceptor.java:78) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:62) at com.sun.proxy.$Proxy251.query(Unknown Source) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:151) ... 116 common frames omitted Caused by: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "ur" <K_ISOLATION> at line 14, column 24.
开始没有注意,以为是sql语句有问题,后来在navicat里执行好像也没有错误。
后来再仔细看后,发现说ur是关键字?不能用ur,果然用下面语句就好了。
select sns.send_id, sns.notice_id, sns.user_id, sns.read_flag, sa.notice_title as notice_title, sa.notice_content as notice_content, u.nick_name as sender, sa.priority as priority, sa.notice_type as notice_type, sa.send_time as send_time from sys_notice_send sns left join sys_notice sa ON sns.notice_id = sa.notice_id left join sys_user u ON sns.user_id = u.user_id where sa.send_status = '1' and sa.status = '0' and sns.user_id = #{noticeSendModel.userId}
注意出错日志里有这句Caused by: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "ur" <K_ISOLATION>
说明是跟ur相关了。