使用maven 插件 generate生成MyBatis相关文件
成都创新互联专注于海宁企业网站建设,成都响应式网站建设,成都商城网站开发。海宁网站建设公司,为海宁等地区提供建站服务。全流程定制开发,专业设计,全程项目跟踪,成都创新互联专业和态度为您提供的服务
在项目中增加 maven 依赖
<?xml version="1.0" encoding="UTF-8"?>4.0.0 com.wangSpringBoot demo 0.0.1-SNAPSHOT jar demo Demo project for Spring Boot org.springframework.boot spring-boot-starter-parent 2.0.3.RELEASE UTF-8 UTF-8 1.8 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-configuration-processor true org.projectlombok lombok 1.16.18 provided org.springframework.boot spring-boot-devtools true org.springframework.boot spring-boot-starter-test test org.mybatis.spring.boot mybatis-spring-boot-starter 1.3.1 mysql mysql-connector-java org.springframework.boot spring-boot-maven-plugin true org.mybatis.generator mybatis-generator-maven-plugin 1.3.7 Generate MyBatis Artifacts generate org.hsqldb hsqldb 2.3.4 src/main/java **/*.xml src/main/resources **/*.* src/main/webapp META-INF/resources **/*.*
SpringBoot 项目中application.properties 配置
mybatis.mapper-locations=classpath:com/wangspringboot/demo/mapper/*.xml spring.datasource.username=root spring.datasource.password=root spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/wt?useUnicode=true&characterEncoding=utf8&useSSL=false
resources 下配置 generatorConfig.xml
此项内容为直接修改相关配置即可
<?xml version="1.0" encoding="UTF-8" ?>
创建相关目录

查看插件

执行
选中maven 下 generator 双击运行

SpringBootMyBatis 使用
在 service 的实现类上添加 @Service 注解
@Service
public class TqServiceImpl implements TqService {
@Autowired
private TqMapper tqmapper;
@Override
public Tq insTq() {
Tq t = new Tq();
t.setZ(12.0);
t.setY(12.0);
t.setX(12.0);
tqmapper.insert(t);
return t;
}
}相关调用
@RestController
public class MyBatisController {
@Autowired
private TqService tqService;
@GetMapping("/boot/tq")
public Object tq(){
return tqService.insTq();
}
}启动SpringBoot WEB项目后 访问
{
x: 12,
y: 12,
z: 12
}
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对创新互联的支持。如果你想了解更多相关内容请查看下面相关链接