解决一个mybatisplus left join里有ur报错问题

简介: 解决一个mybatisplus left join里有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,
        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相关了。


相关文章
|
6月前
|
SQL XML Java
mybatis 调用修改SQL时 出现了一个问题 没有修改成功也没有报错
mybatis 调用修改SQL时 出现了一个问题 没有修改成功也没有报错
52 0
|
6月前
|
SQL Java 数据库连接
mybatis报错 resultMapException
mybatis报错 resultMapException
238 0
mybatis报错 resultMapException
|
6月前
|
SQL 安全 BI
基于jeecg-boot的nbcio-boot因升级mybatis-plus到3.5.3.1和JSQLParser 到4.6而引起的在线报表配置报错处理
基于jeecg-boot的nbcio-boot因升级mybatis-plus到3.5.3.1和JSQLParser 到4.6而引起的在线报表配置报错处理
163 0
|
5月前
|
Java 数据库连接 mybatis
mybatis参数报错Parameter ‘docId‘ not found. Available parameters are [arg1, arg0, param1, param2]
mybatis参数报错Parameter ‘docId‘ not found. Available parameters are [arg1, arg0, param1, param2]
若依修改,集成mybatisplus报错,若依集成mybatisplus,总是找不到映射是怎么回事只要是用mp的方法就找报,改成mybatisPlus配置一定要改
若依修改,集成mybatisplus报错,若依集成mybatisplus,总是找不到映射是怎么回事只要是用mp的方法就找报,改成mybatisPlus配置一定要改
|
6月前
|
Java 数据库连接 数据库
mybatis-plus报错:Can not find table primary key in Class
mybatis-plus报错:Can not find table primary key in Class
1480 1
|
Java 数据库连接 mybatis
flowable项目启动项目报错:Consider defining a bean of type ‘org.mybatis.spring.SqlSessionTemplate‘ in ……
flowable项目启动项目报错:Consider defining a bean of type ‘org.mybatis.spring.SqlSessionTemplate‘ in ……
310 0
|
6月前
|
前端开发 Java 数据库连接
若依 mybatis报错nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘XXX‘ 错误
若依 mybatis报错nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘XXX‘ 错误
130 0
|
6月前
|
XML Java 数据库连接
调用mybatisplus的封装CURD方法出现报错
调用mybatisplus的封装CURD方法出现报错
35 0
|
6月前
|
Java Apache vr&ar
springmvc报错 nested exception is org.mybatis.spring.MyBatisSystemException:
springmvc报错 nested exception is org.mybatis.spring.MyBatisSystemException: