spring boot 整合mybatis (tk.mybatis)解决的一些问题

时区不统一,但是我和北京时区换算 +8 并没有起作用。

  • nested exception is org.apache.ibatis.exceptions.PersistenceException: \r\n### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is 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.\r\n### The error may exist in com/hcg/mybatis/mapper/UserMapper.java (best guess)\r\n### The error may involve com.hcg.mybatis.mapper.UserMapper.findById\r\n### The error occurred while executing a query\r\n### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is 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.",
#mysql连接加上  &serverTimezone=UTC  即可

jdbc:mysql://localhost:3306/hcg?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC

 

  • "message": "Invalid bound statement (not found): com.hcg.mybatis.mapper.UserMapper.findById",    "message": "Invalid bound statement (not found): com.hcg.mybatis.mapper.UserMapper.findById",
#******** yml **********
#如果引入了 tk.mybatis 在扫包的时候需要加入这个注解
mapper:
  mappers:
    - com.hcg.mybatis.common.business.CommonMapper #mappers
    - com.hcg.mybatis.common.business.*Mapper #mappers 
  notEmpty: false
  identity: MYSQL


#******** properties **********
#mappers 多个接口时逗号隔开
mapper.mappers=tk.mybatis.mapper.common.CommonMapper,tk.mybatis.mapper.common.*Mapper
mapper.notEmpty=true

 

  • Error invoking SqlProvider method (tk.mybatis.mapper.provider.base.BaseSelectProvider.dynamicSQL).  Cause: java.lang.InstantiationException: tk.mybatis.mapper.provider.base.BaseSelectProvider
// 如果引入了 tk.mybatis 在扫包的时候需要加入这个注解
import tk.mybatis.spring.annotation.MapperScan;

//import org.mybatis.spring.annotation.MapperScan;

@Slf4j
@SpringBootApplication
@MapperScan(basePackages = "com.hcg.mybatis.mapper",markerInterface = CommonMapper.class)
public class Application {

 

  • 在引入 tk.mybatis 数据库表名称要和实体类要建立关联,否则执行SQL报错。 如果没有引入的话不需要加额外的注解。
import javax.persistence.*;
import java.io.Serializable;

@Data // @Data = @Getter + @Setter
@ToString
@Table(name = "user")
public class User implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long uid;
    @Column(name = "nickname")
    private String nickname;
    @Column(name = "name")
    private String name;

    @Column(name = "password")
    private String password;
    @Column(name = "salt")
    private String salt;
    @Column(name = "mobile")
    private String mobile;
}

 

你可能感兴趣的:(数据库开发)