Fork me on GitHub

异常处理

1、异常:Field bookMapper in com.aaa.lee.springboot.service.BookService required a bean of type 'com.aaa.lee.springboot.mapper.BookMapper' that could not be found.

原因:在service中使用@Autowired注解注入了mapper,最终mapper没有注入成功,也就是mapper并没有以bean的形式配置进application.xml配置文件(没有mapper的扫描器)
            需要添加@Mapper注解;

 

 

 

2、使用注解的形式写上SQL语句,实体类的属性和数据库的字段映射问题:

  当使用@Select @Update @Delete @Insert来替代mapper.xml的时候,需要把数据库表中字段名和实体类的属性要完全一致!

 1 package com.aaa.liu.springboot.mapper;
 2 
 3 import com.aaa.liu.springboot.model.Book;
 4 import org.apache.ibatis.annotations.Delete;
 5 import org.apache.ibatis.annotations.Insert;
 6 import org.apache.ibatis.annotations.Select;
 7 import org.apache.ibatis.annotations.Update;
 8 
 9 import java.util.List;
10 
11 
12 /**
13  * @Author 刘其佳
14  * 2019/8/16 -- 20:48
15  * @Version 1.0
16  */
17 public interface BookMapper {
18     //查询
19     @Select("select id,book_name bookName,book_price bookPrice from book ")
20     List<Book> selectAll();
21 
22     //添加
23     @Insert("insert into book(book_name,book_price) values(#{bookName},#{bookPrice})")
24     int addBook(Book book);
25 
26     //根据ID进行查询
27     @Select("select id,book_name bookName,book_price bookPrice from book where id=#{id}")
28     List<Book> selectById(int id);
29 
30     //修改
31     @Update("update book set book_name=#{bookName},book_price=#{bookPrice} where id=#{id}")
32     int updateBook(Book book);
33 
34     //删除
35     @Delete("delete from book where id=#{id}")
36     int deleteBook(int id);
37 }

 

 

 

3、更换idea版本后运行Springboot项目时出现异常:

1 Error:java: 错误: 不支持发行版本 5

 

网上的方法有两种:

  1、file-project Structure-project中的:

  2、file-project Structure- module中的:

这一部分的具体说明可以参照百度:

https://blog.csdn.net/qq_22076345/article/details/82392236

 本人自己碰到这个问题时,网上的方法不好使,自己的解决办法是:

file-sitting-build,Execution,Deployment-Compiler-Java Compiler:中的Project bytecode version手动改成1.6

 

posted @ 2019-08-18 21:17  秋刀  阅读(240)  评论(0编辑  收藏  举报