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<User> selectUsers();
}

3.Mybatis(-plus)

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

  • [ 解决方法]
    01.检查Mapper.xmlnamespace
<mapper namespace="com.yh.demo.mapper.UserMapper"></mapper>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值