mybatis整合

【一】pom文件添加:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>2.1.3</version>
</dependency>

  

 

【二】application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=sa
spring.datasource.password=123
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#将下划线转成驼峰
mybatis.configuration.map-underscore-to-camel-case=true

  

【三】创建Mapper和Model(UserMapper和User model)

@Mapper
public interface UserMapper {
@Insert("inser into user(name,accountId,token,gmtCreate,gmtModified) values (#{name},#{accountId},#{token},#{gmtCreate},#{gmtModified})")
void insert(User user);
//普通变量需要添加@Param注解
@Select("select * from user where token = #{token}")
User findByToken(@Param("token") String token);}

 

 

MyBatis 与 SpringBoot 整合:注解和xml两种使用方式介绍

参考:https://blog.csdn.net/solocoder/article/details/84990904

https://blog.csdn.net/seashouwang/article/details/80210780

posted @ 2020-11-04 07:35  Mr_sven  阅读(98)  评论(0编辑  收藏  举报