1、添加依赖
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>4.0.0</version>
</dependency>
2、配置bean
package com.canteen.adminService.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import tk.mybatis.spring.annotation.MapperScannerRegistrar;
import tk.mybatis.spring.mapper.MapperScannerConfigurer;
import java.util.Properties;
@Configuration
public class AdminConfiguration {
@Bean
public MapperScannerConfigurer mapperScannerConfigurer(){
MapperScannerConfigurer mapperScannerConfigurer=new MapperScannerConfigurer();
mapperScannerConfigurer.setBasePackage("com.canteen.adminService.dao");
Properties properties=new Properties();
properties.setProperty("mappers","tk.mybatis.mapper.common.Mapper");
mapperScannerConfigurer.setProperties(properties);
return mapperScannerConfigurer;
}
}
三、配置mapper文件
package com.canteen.adminService.dao;
import com.canteen.common.pojo.User;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;
@Repository
public interface UserMapper extends Mapper<User> {
public Integer batchDel(@Param("userList") String[] userList);
}
4、应用启动项配置,注意MapperScan包是tk的
package com.canteen.adminService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import tk.mybatis.spring.annotation.MapperScan;
@SpringBootApplication
@EnableEurekaClient
@MapperScan("com.canteen.adminService.dao")
public class adminServiceApp {
public static void main(String[] args) {
SpringApplication.run(adminServiceApp.class,args);
}
}
现在就可以开始使用了