Mybatis Auto Code Generation
Mybatis Auto Code Generation
熊大信了熊二的话 发表于1年前
Mybatis Auto Code Generation
  • 发表于 1年前
  • 阅读 22
  • 收藏 0
  • 点赞 0
  • 评论 0

腾讯云 十分钟定制你的第一个小程序>>>   

摘要: 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文件. 小工具类

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文件. 小工具类

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));
    }
}

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";
}

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>

完整示例参考

https://github.com/leelance/code-generation

共有 人打赏支持
粉丝 39
博文 7
码字总数 3352
×
熊大信了熊二的话
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: