springboot整合mybatis
springboot整合mybatis逆向生成插件
1.第一步导入相关的pom依赖
<resources>
<!--解决mybatis-generator-maven-plugin运行时没有将XxxMapper.xml文件放入target文件夹的问题-->
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<!--解决mybatis-generator-maven-plugin运行时没有将jdbc.properites文件放入target文件夹的问题-->
<resource>
<directory>src/main/resources</directory>
<includes>
<include>*.properties</include>
<include>*.xml</include>
<include>*.yml</include>
</includes>
</resource>
</resources>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<dependencies>
<!--使用Mybatis-generator插件不能使用太高版本的mysql驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
</dependencies>
<configuration>
<overwrite>true</overwrite>
</configuration>
</plugin>
2.导入逆向生成文件以及jdbc
3.在事物管理器里面配置字一行,整合mybatis就是这一行代码
4.写一个测试类测试一下查询以及删除的方法
Bookservice类
package com.zhoujun.springboot02.service;
import com.zhoujun.springboot02.entity.Book;
/**
* @author 小俊
* @company 流弊公司董事长
* @create 2020-12-01 11:04
*/
public interface BookService {
int deleteByPrimaryKey(Integer bid);
Book selectByPrimaryKey(Integer bid);
}
Bookserviceimpl类
package com.zhoujun.springboot02.service.impl;
import com.zhoujun.springboot02.entity.Book;
import com.zhoujun.springboot02.mapper.BookMapper;
import com.zhoujun.springboot02.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author 小俊
* @company 流弊公司董事长
* @create 2020-12-01 11:05
*/
@Service
public class BookServiceImpl implements BookService {
@Autowired
private BookMapper bookMapper;
@Override
public int deleteByPrimaryKey(Integer bid) {
return bookMapper.deleteByPrimaryKey(bid);
}
@Override
public Book selectByPrimaryKey(Integer bid) {
return bookMapper.selectByPrimaryKey(bid);
}
}
测试
package com.zhoujun.springboot02.service.impl;
import com.zhoujun.springboot02.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.junit.jupiter.api.Test;
/**
* @author 小俊
* @company 流弊公司董事长
* @create 2020-12-01 11:11
*/
@SpringBootTest
public class BookServiceImplTest {
@Autowired
private BookService bookService;
@Test
public void deleteByPrimaryKey() {
bookService.deleteByPrimaryKey(21);
}
@Test
public void selectByPrimaryKey() {
System.out.println(bookService.selectByPrimaryKey(28));
}
}
测试结果