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); } }