这篇文章主要讲解了“SpringBoot集成MyMatis-Generator的使用方法”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“SpringBoot集成MyMatis-Generator的使用方法”吧!
10年积累的成都网站制作、网站设计经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计后付款的网站建设流程,更有柯城免费网站建设让你可以放心的选择与我们合作。
POM依赖
org.springframework.boot spring-boot-starter-web org.mybatis.spring.boot mybatis-spring-boot-starter 2.1.3 MySQL mysql-connector-java runtime 5.1.40 org.projectlombok lombok true org.springframework.boot spring-boot-starter-test test org.junit.vintage junit-vintage-engine
根据实际数据源配置
spring: datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/spring_mybatis_dljd?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2B8&useSSL=false username: root password: 123456
org.springframework.boot spring-boot-maven-plugin org.mybatis.generator mybatis-generator-maven-plugin 1.4.0 mysql mysql-connector-java 5.1.40 ${project.basedir}/src/main/resources/generatorConfig.xml true true src/main/java **/*.xml src/main/resources **/*.yml **/*.properties
注意:
1. 插件中使用的 mysql-connector-java 与application.yml 中保持一致
2.configurationFile 中指定了生成器配置文件 generatorConfig.xml的位置
3.发布时为了将mapper包中sql映射文件xml 导入资源文件中,加入resources。因此导致重新了默认的资源配置,需要额外导入*.yml,*.properties
路径:
src\main\resources\generatorConfig.xml
内容:
1. javaModelGenerator 实体和Example文件指定位置
2. sqlMapGenerator SQL映射文件*.Mapper.xml 所在位置
3. javaClientGenerator 接口文件所在位置
4. tableName="%" 为生成所有表
jdbcConnection driverClass :需与application.yml中保持一致
5.1 点击

5.2 . 生成

@SpringBootApplication@MapperScan("com.zhl.springmybatis.mapper")public class SpringMybatisApplication {public static void main(String[] args) {
SpringApplication.run(SpringMybatisApplication.class, args);
}
}@Data
@ToString
public class Student {....}StudentService:
package com.zhl.springmybatis.service;
import com.zhl.springmybatis.pojo.Student;
import java.util.List;
public interface StudentService {
List getList();
} StudentServiceImpl
@Service
public class StudentServiceImpl implements StudentService {
@Resource
private StudentMapper studentMapper;
@Override
public List getList() {
StudentExample studentExample=new StudentExample();
List list= studentMapper.selectByExample(studentExample);
for (Student s:list) {
System.out.println(s);
}
return list;
}
} 这里引用 Mapper接口 使用 @Resource 避免出现警告红线。
@SpringBootTest
class SpringMybatisApplicationTests {
@Resource
private StudentMapper studentMapper;
@Test
void contextLoads() {
}
@Test
public void GetList(){
StudentExample studentExample=new StudentExample();
List list= studentMapper.selectByExample(studentExample);
for (Student s:list) {
System.out.println(s);
}
}
} 
mybatis-3-mapper.dtd
mybatis-generator-config_1_0.dtd
路径 File | Settings | Languages & Frameworks | Schemas and DTDs
URI 为 网络地址
Location 为 本地文件地址

pom中引入
org.apache.ibatis ibatis-core 3.0
感谢各位的阅读,以上就是“SpringBoot集成MyMatis-Generator的使用方法”的内容了,经过本文的学习后,相信大家对SpringBoot集成MyMatis-Generator的使用方法这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!