`
lihao312
  • 浏览: 482356 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

spring-boot 代码生成工具

    博客分类:
  • java
阅读更多
Mybatis Auto Code Generation Mapper/Service/Domain/SQL.xml, 主要是针对某个数据库所有表[参考配置文件ConfigConstants], 统一生成Domain/Service/Mapper,以及SQL.xml文件, 如:针对t_customer, 通过该应用生成CustonerInfo.java, CustomerSerivce.java/CustomerServiceImpl.java, CustomerMapper.java 以及 Customer-mapper.xml文件. 小工具类

1.Project run MainTest
@RunWith(SpringRunner.class)
@SpringBootTest(classes=SimpleApplication.class)
public class MainTest {
    Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private TableService tableService;

    @Test
    public void main() {
        long startTime = System.currentTimeMillis();
        logger.info("...........start application.........");

        tableService.run();

        logger.info("...end application...Time: {}",(System.currentTimeMillis()-startTime));
    }
}

2.Generate Code Config
public interface ConfigConstants {
    /**定义Schema*/
    String SCHEMA = "longchou-loan";

    /**移除表前缀*/
    String REMOVE_TABLE_PREFIX = "t_";

    /**Domain后缀, CustomerInfo*/
    String DOMAIN_SUFFIX = "";

    /**生成文件路径*/
    String FILE_PATH = "E:\\gitwork\\code-generation\\src\\main\\java";

    /**MyBatis SQL生成文件路径*/
    String SQL_PATH = "E:\\gitwork\\code-generation\\src\\main\\resources\\mappers";

    /**生成Mapper.xml后缀名字, EX: customer-mapper.xml*/
    String SQL_MAPPER_SUFFIX = "-mapper";

    /**生成包名称*/
    String ROOT_PACKAGE = "com.lance.code";

    /**JavaBean包名称*/
    String DOMAIN_PACKAGE = "domain";

    /**service包名称*/
    String SERVICE_PACKAGE = "service";

    /**serviceImpl包名称*/
    String SERVICE_impl_PACKAGE = "serviceImpl";

    /**mapper包名称*/
    String MAPPER_PACKAGE = "mapper";
}

3.Add dependencies to pom
<parent>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-parent</artifactId>
   <version>1.4.0.RELEASE</version>
</parent>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Mybatis -->
<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>1.1.1</version>
</dependency>
<!-- MYSQL -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.2.12</version>
</dependency>
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.4</version>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <scope>test</scope>
</dependency>


4.spring-boot config
# IDENTITY (ContextIdApplicationContextInitializer)
spring.application.index=Code.v1.1
spring.application.name=Code Boot

#MYBATIS
mybatis.type-aliases-package=com.lance.code.generation.domain
mybatis.mapper-locations=classpath*:/mapper/*Mapper.xml
mybatis.configuration.map-underscore-to-camel-case=true
mybatis.configuration.use-generated-keys=true
mybatis.configuration.default-fetch-size=100
mybatis.configuration.default-statement-timeout=30

spring.datasource.url=jdbc:mysql://localhost:3306/loan
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver


5.项目完整代码示例
https://github.com/leelance/code-generation
分享到:
评论

相关推荐

    spring-boot-1.5.3.RELEASE

    2. `Spring Initializr`:在线初始化工具,帮助开发者快速生成项目结构,包括POM.xml或build.gradle文件,以及必要的源代码目录结构。 二、自动配置 1. Auto-configuration:Spring Boot通过扫描类路径中的特定...

    spring-boot-cli-1.4.3.RELEASE-bin.zip

    2. **创建项目**:使用`spring init`命令可以快速生成一个新的Spring Boot项目结构,只需提供如groupId、artifactId、dependencies等基本信息。 3. **运行应用**:编写完`src/main/groovy`目录下的Groovy脚本后,...

    spring-boot-reference.pdf

    其核心优势包括自动配置、无需代码生成以及可与Spring生态系统无缝集成。文档的描述指明,这是当前的稳定版(GA)版本,即2.5.6版本,是经过充分测试并可供生产环境使用的一个版本。 标签“SpringBoot”强调了这份...

    spring-boot-starter-mybatis-spring-boot-2.0.1.zip

    总结,"spring-boot-starter-mybatis-spring-boot-2.0.1.zip"为开发者提供了一个快速集成MyBatis到Spring Boot 2.0.1项目的工具。通过理解和掌握上述内容,你可以有效地利用这一资源,构建出高效的Java应用。同时,...

    spring-boot-tutorials-master.zip

    Spring Boot 是一个由 Pivotal Team 开发的 Java 框架,用于简化Spring应用程序的初始搭建以及开发过程。...通过学习这些教程,你可以更好地掌握Spring Boot如何与其他流行技术协同工作,提高开发效率和代码质量。

    spring-boot-cli-2.0.0.M5-bin.zip

    Spring Boot CLI(Command Line Interface,命令行接口)是Spring框架为简化Spring应用程序开发而推出的一个强大的工具。它允许开发者通过命令行快速创建、运行和测试Spring应用,无需配置大量XML或Java代码。2.0.0....

    spring-boot-api-project-seed-master.zip

    Spring Initializr是一个在线工具,用于快速生成基于Spring Boot的新项目结构,包括Maven或Gradle构建系统、所需依赖等。 3. **项目结构解析** 该项目包含典型的Spring Boot项目结构: - `src/main/java`: 存放...

    spring-boot-excel springboot整合easyexcel 有注释 打开可以运行

    在项目"spring-boot-excel"中,由于提到"有注释",这意味着源代码应该是清晰易懂的,这对于初学者或者团队协作来说是非常友好的。开发者可以通过阅读这些注释来理解如何设置和使用EasyExcel的各种特性,例如自定义...

    spring-boot-reference2.0

    Spring Boot 提供了一个命令行工具,可以用来运行、测试和创建 Spring 应用。CLI 提供了强大的命令补全和历史记录功能。 8. **测试支持** Spring Boot 提供了内置的测试支持,包括 `@SpringBootTest` 注解用于...

    Spring-Boot+Mybatis1.26完成的框架

    6. **逆向工程与代码生成** 本框架提到的"数据中标的反向生成"可能是指Mybatis的逆向工程(Mybatis Generator),它可以自动生成Model、Mapper接口和XML文件,减少手动编写这些代码的工作量。配置好generatorConfig...

    spring-boot-starter-mybatis-spring-boot-2.1.4.zip

    例如,对于Spring Boot 2.1.4版本,添加如下代码: ```xml &lt;groupId&gt;org.springframework.boot &lt;artifactId&gt;spring-boot-starter-data-jdbc &lt;groupId&gt;org.mybatis.spring.boot &lt;artifactId&gt;mybatis-...

    spring-boot-test示例程序

    这些工具可以自动运行测试,并生成测试报告,帮助团队监控代码质量。 综上所述,"spring-boot-test"示例程序涵盖了Spring Boot中测试的核心概念,包括Rest Controller的集成测试、单元测试的策略以及测试工具的使用...

    基于spring-boot实现自动化配置的支付对接.zip

    文档生成工具可以自动生成代码注释文档,便于团队内外理解和使用项目代码。 API管理工具则方便开发者创建、测试、发布和维护API接口。 持续集成与持续部署(CI/CD): Jenkins、Travis CI、GitHub Actions等...

    spring-boot-master.zip

    执行 `mvn eclipse:eclipse` 命令会生成 Eclipse 项目所需的配置文件,使得你可以方便地在 Eclipse 中浏览、编辑和调试代码。如果你使用的是 IntelliJ IDEA,可以执行 `mvn idea:idea` 来导入到 IDEA。 Spring Boot...

    spring-boot-中文参考手册 SpringBoot中文文档 springboot 中文 文档

    spring-boot-中文参考手册 SpringBoot中文文档 springboot 中文 文档 SpringBoot 帮助您创建可以独立运行的、基于 Spring 的生产级应用程序。我们对 Spring 平台和第三方库有自己...不要代码生成,也不需要 XML 配置。

    spring-boot-cli-2.0.3.RELEASE-bin.zip

    Spring Boot 2.0.3.RELEASE是该工具的一个稳定版本,适合初学者使用。 在深入探讨Spring Boot CLI之前,我们先了解一下Spring Boot。Spring Boot简化了Spring应用程序的初始设置和配置,它内置了服务器、数据源、...

    spring-boot

    6. **Spring Boot CLI**:Spring Boot 提供了一个命令行工具,可以快速地创建、运行和测试 Spring 应用程序。 7. **测试支持**:Spring Boot 提供了方便的测试支持类,如 `@SpringBootTest` 和 `@WebMvcTest`,用于...

    spring-boot (spring-boot实战随书源码—汪云飞)

    在压缩包"SourceCode"中,包含了书中各个章节的示例代码,这些代码可以帮助读者深入理解Spring Boot的工作原理和实践方法。以下将详细解析Spring Boot的一些关键知识点: 1. **起步依赖(Starter)**:Spring Boot...

    dubbo-spring-boot-autoconfigure-2.7.8.zip

    `dubbo-spring-boot-autoconfigure-2.7.8-sources.jar`提供了模块的源代码,开发者可以通过阅读源码深入了解自动配置的实现细节,包括如何加载配置、如何创建Bean以及如何将Dubbo的配置项映射到Spring Boot的配置...

    spring-boot-plus-master.zip

    - **API文档**:可能集成了Swagger等工具,自动生成RESTful API文档。 - **安全框架集成**:如Spring Security,提供身份验证和授权功能。 - **数据库支持**:可能包括对JPA、MyBatis等持久层框架的支持,以及...

Global site tag (gtag.js) - Google Analytics