1.org.springframework.jdbc.BadSqlGrammarException
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 'desc,status FROM n_note WHERE id=1' at line 1
### The error may exist in com/an/notepad/mapper/NoteMapper.java (best guess)
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: SELECT id,created,title,user_id,content,desc,status FROM n_note WHERE id=?
### 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 'desc,status FROM n_note WHERE id=1' 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 'desc,status FROM n_note WHERE id=1' at line 1
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:235) ~[spring-jdbc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) ~[spring-jdbc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:74) ~[mybatis-spring-2.0.2.jar:2.0.2]
这个异常属于低级SQL异常 BadSqlGrammarException
解决方法:去数据库查看有没有和SQL关键字冲突的字段名。
在数据库中,亮颜色的就是sql关键字;
2.SpringBoot中@Autowired报红
报红的原因是@Autowired 是Spring 的注解,提示找不到对他的bean,因为你没有显示的将userMapper注入到Spring容器中去管理。
解决方法:
1.一种方式就是直接将@Autowired 换成@Resource 注解,此注解是JDK中的注解,不会向@Autowired 那样去Spring容器中寻找bean。
2.接口上添加@Repository 注解即可,此注解是Spring的注解,将当前类注册到Spring容器中实例化为一个bean,所以@Autowired 就能找到此bean了。
?
3.SpringBoot加上@Data注解 get/set方法不起作用?
首先在pom.xml文件中添加了lombok依赖
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
之后,发现@Data注解 get/set方法不起作用?
解决方案:
需要下载插件
操作流程:
?
?
?
|