IDEA创建springBootMaven入门项目整合mybatis踩坑合集

首先项目就是springboot+mybatis+maven搭建的web项目使用工具IDEA,然后就一直报错,于是就出了合集,如果还没解决,请另辟蹊径,谢谢!

  1. controller
  • [ 报错信息]
    controller层,我见的错是启动不报错,访问也不报错就是一个普通页面
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Tue Sep 17 17:26:25 CST 2019
There was an unexpected error (type=Not Found, status=404).
No message available
  • [解决方法 ]
    注解换一下使用:@RestController或者@Controller
    想返回字符串就用RestController
    想返回页面就用Controller
@RestController
@RequestMapping(value = "/user")
public class UserController {


}
  1. Mapper层(Dao层)
  • [报错信息 ]
启动报错
Field userMapper in com.yh.demo.service.impl.UserServiceImpl required a bean of type 'com.yh.demo.mapper.UserMapper' that could not be found.

  • [ 解决方法]
    mapper层注解换一下使用@Mapper 或者 @Repository
@Mapper
public interface UserMapper {

    List selectUsers();
}

3.Mybatis(-plus)

  • [报错信息 ]
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.yh.demo.mapper.UserMapper.selectUsers

  • [ 解决方法]
    01.检查Mapper.xmlnamespace

02.检查application.properties(yml)对mybatis的支持
自己要用的是mybatis还是mybatis-plus
我这引入mybatis的jar包,却开启了Plus的支持

#mybatis
mybatis.mapper-locations=classpath*:mapper/*.xml
mybatis.type-aliases-package = com.yh.demo.entity
  • [报错信息 ]
    访问时报错
java.sql.SQLException: 
The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. 
You must configure either the server or JDBC driver (via the serverTimezone configuration property) 
to use a more specifc time zone value if you want to utilize time zone support.
  • [ 解决方法]
    这是由于数据库和系统时区差异所造成的,在jdbc连接的url后面加上serverTimezone=GMT即可解决问题
spring.datasource.url=jdbc:mysql://localhost:3306/mybatis?serverTimezone=GMT

此文章会不断更新错误,感谢浏览!

你可能感兴趣的:(java,springboot,maven,mybatis)