从零学springboot——springboot快速集成mybatis

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mazhen1991/article/details/79520124
  • 添加mybatis依赖
<dependency>
       <groupId>org.mybatis.spring.boot</groupId>
       <artifactId>mybatis-spring-boot-starter</artifactId>
       <version>1.1.1</version>
</dependency>
  • 在启动类上添加扫描注解,值为要扫描的dao,如有多个则逗号隔开
@MapperScan("springboot.learn.dao")
  • 编写一个Mapper接口,并添加方法(类名不一定需要以Mapper结尾)
public interface PersonMapper {

    @Insert("insert into Person(name,age) values(#{name},#{age})")
    public int savePerson(Person person);
}
  • 编写service,并在service中直接注入该接口,调用其方法即可

猜你喜欢

转载自blog.csdn.net/mazhen1991/article/details/79520124
今日推荐