SpringBoot整合Mybatis

  • 依赖

<dependency>
    <groupId>org.mybatis.spring.bootgroupId>
    <artifactId>mybatis-spring-boot-starterartifactId>
    <version>1.3.1version>
dependency>
  • application.yml配置
mybatis:
  type-aliases-package: com.yss.common.domain # 配置别名
  • 扫描mapper
@MapperScan("com.yss.main.mapper") // 配置扫描mapper
  • mepper文件
public interface UserMapper {
    @Insert("INSERT INTO t_user (username, password) VALUES (#{param1},#{param2})")
    void save(String username, String password);
}
  • 测试
@Autowired
UserMapper userMapper;

当然需要配置连接池才能使用,连接池链接请点击

  • 如果想要控制台输出sql语句


<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <logger name="com.yss.main.mapper" level="DEBUG"/>
configuration>

你可能感兴趣的:(SpringBoot)