springboot配置第一个项目出现的问题

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报红

报红的原因是@AutowiredSpring的注解,提示找不到对他的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方法不起作用 

解决方案:

需要下载插件

操作流程:

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值