SpringBoot整合Mybatis-Plus报错 cause: java.sql.SQLSyntaxErrorException

本文探讨了Java中因实体类驼峰命名变量转为下划线在数据库查询时遇到的`SQLSyntaxErrorException: Unknown column`问题,重点在于如何理解命名规则差异并提供解决方案。

cause: java.sql.SQLSyntaxErrorException: Unknown column 'e_id' in 'field list'

原因:实体类中以驼峰规则命名的变量会转换为下划线规则到数据库中进行查找

eg. 实体类:Integer userName 自动转换为 user_name 然后在数据库中进行查找列名为user_name的列

org.springframework.jdbc.BadSqlGrammarException: ### Error querying database. Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 20' at line 1 ### The error may exist in cn/iocoder/gmy/module/dataplatform/dal/mysql/indicatordict/IndicatorDictMapper.java (best guess) ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: SELECT id,comment,english_name,business_domain,associated_topic,indicator_type,description,time_column,time_granularity,naming_convention,circular_dependency,function_type_matching,expression_compilation,source_accessibility,dimensional_constraints,model_id,model_key,status,version,scan_volume,time_consuming,number_lines,expression_prompt,create_time,update_time,creator,updater,deleted FROM dp_indicator_dict WHERE deleted=0 AND (create_time BETWEEN ? AND ?) ORDER BY id DESC LIMIT ? LIMIT ? ### Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 20' at line 1 ; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 20' at line 1 at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:236) ~[spring-jdbc-5.3.39.jar:5.3.39] at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) ~[spring-jdbc-5.3.39.jar:5.3.39] at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:92) ~[mybatis-spring-2.1.2.jar:2.1.2] at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:439) ~[mybatis-spring-2.1.2.jar:2.1.2] at com.sun.proxy.$Proxy176.selectList(Unknown Source) ~[na:na] at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224) ~[mybatis-spring-2.1.2.jar:2.1.2] at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForMany(MybatisMapperMethod.java:164) ~[mybatis-plus-core-3.5.10.1.jar:3.5.10.1] at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:77) ~[mybatis-plus-core-3.5.10.1.jar:3.5.10.1] at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:155) ~[mybatis-plus-core-3.5.10.1.jar:3.5.10.1] at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:92) ~[mybatis-plus-core-3.5.10.1.jar:3.5.10.1] at com.sun.proxy.$Proxy234.selectList(Unknown Source) ~[na:na] at com.baomidou.mybatisplus.core.mapper.BaseMapper.selectPage(BaseMapper.java:458) ~[mybatis-plus-core-3.5.10.1.jar:3.5.10.1] at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627) ~[na:1.8.0_281] at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$DefaultMethodInvoker.invoke(MybatisMapperProxy.java:171) ~[mybatis-plus-core-3.5.10.1.jar:3.5.10.1] at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:92) ~[mybatis-plus-core-3.5.10.1.jar:3.5.10.1] at com.sun.proxy.$Proxy234.selectPage(Unknown Source) ~[na:na] at cn.iocoder.gmy.framework.mybatis.core.mapper.BaseMapperX.selectPage(BaseMapperX.java:51) ~[classes/:na] at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627) ~[na:1.8.0_281] at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$DefaultMethodInvoker.invoke(MybatisMapperProxy.java:171) ~[mybatis-plus-core-3.5.10.1.jar:3.5.10.1] at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:92) ~[mybatis-plus-core-3.5.10.1.jar:3.5.10.1] at com.sun.proxy.$Proxy234.selectPage(Unknown Source) ~[na:na] at cn.iocoder.gmy.framework.mybatis.core.mapper.BaseMapperX.selectPage(BaseMapperX.java:39) ~[classes/:na] at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627) ~[na:1.8.0_281] at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$DefaultMethodInvoker.invoke(MybatisMapperProxy.java:171) ~[mybatis-plus-core-3.5.10.1.jar:3.5.10.1] at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:92) ~[mybatis-plus-core-3.5.10.1.jar:3.5.10.1] at com.sun.proxy.$Proxy234.selectPage(Unknown Source) ~[na:na] at cn.iocoder.gmy.module.dataplatform.dal.mysql.indicatordict.IndicatorDictMapper.selectPage(IndicatorDictMapper.java:22) ~[classes/:na] at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627) ~[na:1.8.0_281] at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$DefaultMethodInvoker.invoke(MybatisMapperProxy.java:181) ~[mybatis-plus-core-3.5.10.1.jar:3.5.10.1] at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:92) ~[mybatis-plus-core-3.5.10.1.jar:3.5.10.1] at com.sun.proxy.$Proxy234.selectPage(Unknown Source) ~[na:na] at cn.iocoder.gmy.module.dataplatform.service.indicatordict.IndicatorDictServiceImpl.getIndicatorDictPage(IndicatorDictServiceImpl.java:148) ~[classes/:na] at cn.iocoder.gmy.module.dataplatform.service.indicatordict.IndicatorDictServiceImpl$$FastClassBySpringCGLIB$$ed638cae.invoke(<generated>) ~[classes/:na] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.39.jar:5.3.39] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:792) ~[spring-aop-5.3.39.jar:5.3.39] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.39.jar:5.3.39] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762) ~[spring-aop-5.3.39.jar:5.3.39]
10-29
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值