springboot使用mybatis的注解时,可以使用@Mapper注解简单明了,也可以使用@MapperScan
使用@Mapper示例
直接在Mapper类上面添加注解@Mapper,这种方式需要每一个mapper类都添加此注解,有些麻烦
@Mapper @Repository("studentDao") public interface StudentDao { public int addStudent(Student stu); public int editStudent(Student stu); public List<Student> selectStudent(Student stu); public int deleteStudent(Integer id); public int deleteStudents(String ids); public int delsStudents(String[] id); public Student selectStudentById(Integer id); }
使用@MapperScan示例
直接将mapper所在的目录扫描进去就行,一劳永逸
package com.yt; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication @MapperScan({"com.yt.dao"}) public class SpringytApplication { public static void main(String[] args) { SpringApplication.run(SpringytApplication.class, args); } }