spring-boot 代码生成工具

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值