代码
引入依赖
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>
配置数据源
spring:
datasource:
url: jdbc:mysql://127.0.0.1:3306/auto?useUnicode=true&useSSL=false&characterEncoding=utf8
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver
创建Mapper
public interface UserMapper {
@Select("SELECT * FROM Person WHERE id = #{id}")
Person selectUser(int id);
@Delete("delete from person where id = #{id}")
void deleteByPrimaryKey(int id);
}
启动类
// 扫描该包下的Mapper
@MapperScan("com.fendo.auto.mapper")
@SpringBootApplication
public class AutoApplication {
public static void main(String[] args) {
SpringApplication.run(AutoApplication.class, args);
}
}