国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Java在線代碼生成工具,支持JPA、Mybatis、MybatisPlus

這篇具有很好參考價值的文章主要介紹了Java在線代碼生成工具,支持JPA、Mybatis、MybatisPlus。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

【Java代碼生成神器】自動化生成Java實體類、代碼、增刪改查功能!點擊訪問

推薦一個自己每天都在用的Java代碼生成器!這個網(wǎng)站支持在線生成Java代碼,包含完整的Controller\Service\Entity\Dao代碼,完整的增刪改查功能!

還可以自定義自己的代碼模板、自由配置高級選項,指定是否集成Lombok和Swagger等常用庫,一鍵生成,省去了大量時間和精力!
快來試試吧!在線地址
代碼生成器在線,java,mybatis,開發(fā)語言
代碼生成器在線,java,mybatis,開發(fā)語言

一款支持多種ORM框架的Java代碼生成器,基于模板引擎實現(xiàn),具有非常高的自由度,可隨意修改為適合你的代碼風(fēng)格
支持JPA、Mybatis、MybatisPlus等ORM框架

以下為開源版本
源碼:

  • 前端:https://github.com/dengweiping4j/code-generator-ui.git
  • 后端:https://github.com/dengweiping4j/CodeGenerator.git

界面展示:代碼生成器在線,java,mybatis,開發(fā)語言
代碼生成器在線,java,mybatis,開發(fā)語言

關(guān)鍵代碼:

 package com.dwp.codegenerator.utils;

import com.dwp.codegenerator.domain.ColumnEntity;
import com.dwp.codegenerator.domain.DatabaseColumn;
import com.dwp.codegenerator.domain.GeneratorParams;
import com.dwp.codegenerator.domain.TableEntity;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.WordUtils;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class GeneratorUtil {

    /**
     * 生成代碼
     *
     * @param generatorParams
     * @param zip
     */
    public static void generatorCode(GeneratorParams generatorParams, ZipOutputStream zip) {
        //參數(shù)處理
        TableEntity tableEntity = formatParams(generatorParams);
        //設(shè)置velocity資源加載器
        initVelocity();
        //封裝模板數(shù)據(jù)
        VelocityContext context = getVelocityContext(generatorParams, tableEntity);
        //渲染模板
        apply(context, zip, tableEntity, generatorParams);
    }

    private static void apply(VelocityContext context, ZipOutputStream zip, TableEntity tableEntity, GeneratorParams generatorParams) {
        List<String> templates = getTemplates(generatorParams.getGeneratorType());
        templates.forEach(template -> {
            StringWriter sw = new StringWriter();
            Template tpl = Velocity.getTemplate(template, "UTF-8");
            tpl.merge(context, sw);
            try {
                String fileName = getFileName(template, tableEntity.getUpperClassName(), generatorParams);
                //添加到zip
                zip.putNextEntry(new ZipEntry(fileName));
                IOUtils.write(sw.toString(), zip, "UTF-8");
                IOUtils.closeQuietly(sw);
                zip.closeEntry();
            } catch (IOException e) {
                throw new RuntimeException("渲染模板失敗,表名:" + tableEntity.getTableName(), e);
            }
        });
    }

    /**
     * 使用自定義模板
     *
     * @param generatorType
     * @return
     */
    private static List<String> getTemplates(String generatorType) {
        List<String> templates = new ArrayList<>();
        switch (generatorType) {
            case "jpa":
                templates.add("template/jpa/Repository.java.vm");
                templates.add("template/jpa/Specifications.java.vm");
                templates.add("template/jpa/Service.java.vm");
                templates.add("template/jpa/Controller.java.vm");
                templates.add("template/jpa/Domain.java.vm");
                break;
            case "mybatis":
                templates.add("template/mybatis/Mapper.java.vm");
                templates.add("template/mybatis/Mapper.xml.vm");
                templates.add("template/mybatis/Service.java.vm");
                templates.add("template/mybatis/ServiceImpl.java.vm");
                templates.add("template/mybatis/Controller.java.vm");
                templates.add("template/mybatis/Entity.java.vm");
                templates.add("template/mybatis/EntityParam.java.vm");
                templates.add("template/mybatis/PageResult.java.vm");
                templates.add("template/mybatis/RestResp.java.vm");
                break;
            case "mybatis-plus":
                templates.add("template/mybatis-plus/Mapper.java.vm");
                templates.add("template/mybatis-plus/Mapper.xml.vm");
                templates.add("template/mybatis-plus/Service.java.vm");
                templates.add("template/mybatis-plus/ServiceImpl.java.vm");
                templates.add("template/mybatis-plus/Controller.java.vm");
                templates.add("template/mybatis-plus/Entity.java.vm");
                templates.add("template/mybatis-plus/EntityParam.java.vm");
                templates.add("template/mybatis-plus/PageResult.java.vm");
                templates.add("template/mybatis-plus/RestResp.java.vm");
                break;
        }
        return templates;
    }


    private static String getPackagePath(GeneratorParams generatorParams) {
        //配置信息
        Configuration config = getConfig();
        String packageName = StringUtils.isNotBlank(generatorParams.getPackageName())
                ? generatorParams.getPackageName()
                : config.getString("package");
        String moduleName = StringUtils.isNotBlank(generatorParams.getModuleName())
                ? generatorParams.getModuleName()
                : config.getString("moduleName");
        String packagePath = "main" + File.separator + "java" + File.separator;
        if (StringUtils.isNotBlank(packageName)) {
            packagePath += packageName.replace(".", File.separator) + File.separator + moduleName + File.separator;
        }
        return packagePath;
    }

    private static VelocityContext getVelocityContext(GeneratorParams generatorParams, TableEntity tableEntity) {
        Configuration config = getConfig();
        Map<String, Object> map = new HashMap<>();
        map.put("generatorType", generatorParams.getGeneratorType());
        map.put("tableName", tableEntity.getTableName());
        map.put("comments", tableEntity.getComments());
        map.put("pk", tableEntity.getPk());
        map.put("className", tableEntity.getUpperClassName());
        map.put("classname", tableEntity.getLowerClassName());
        map.put("pathName", tableEntity.getLowerClassName().toLowerCase());
        map.put("columns", tableEntity.getColumns());
        map.put("mainPath", StringUtils.isBlank(config.getString("mainPath")) ? "com.dwp" : config.getString("mainPath"));
        map.put("package", StringUtils.isNotBlank(generatorParams.getPackageName()) ? generatorParams.getPackageName() : config.getString("package"));
        map.put("moduleName", StringUtils.isNotBlank(generatorParams.getModuleName()) ? generatorParams.getModuleName() : config.getString("moduleName"));
        map.put("author", StringUtils.isNotBlank(generatorParams.getAuthor()) ? generatorParams.getAuthor() : config.getString("author"));
        map.put("email", config.getString("email"));
        map.put("datetime", DateUtils.format(new Date(), DateUtils.DATE_TIME_PATTERN));
        VelocityContext context = new VelocityContext(map);
        return context;
    }

    private static void initVelocity() {
        Properties prop = new Properties();
        prop.put("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        Velocity.init(prop);
    }

    /**
     * 表、字段參數(shù)處理
     *
     * @param generatorParams
     * @return
     */
    private static TableEntity formatParams(GeneratorParams generatorParams) {
        TableEntity tableEntity = new TableEntity();
        //表信息
        setTableEntity(tableEntity, generatorParams);
        //設(shè)置列信息
        setColumns(tableEntity, generatorParams);
        //沒主鍵,則第一個字段為主鍵
        if (tableEntity.getPk() == null) {
            tableEntity.setPk(tableEntity.getColumns().get(0));
        }
        return tableEntity;
    }

    private static void setColumns(TableEntity tableEntity, GeneratorParams generatorParams) {
        List<ColumnEntity> columnsList = new ArrayList<>();
        for (DatabaseColumn column : generatorParams.getColumns()) {
            ColumnEntity columnEntity = new ColumnEntity();
            columnEntity.setColumnName(column.getColumnName());
            //列名轉(zhuǎn)換成Java屬性名
            String attrName = columnToJava(column.getColumnName());
            columnEntity.setUpperAttrName(attrName);
            columnEntity.setLowerAttrName(StringUtils.uncapitalize(attrName));
            columnEntity.setComments(column.getColumnComment());

            //列的數(shù)據(jù)類型,轉(zhuǎn)換成Java類型
            Configuration config = getConfig();
            String attrType = config.getString(column.getColumnType(), "unknowType");
            columnEntity.setAttrType(attrType);
            //是否主鍵
            if (column.isPrimary()) {
                tableEntity.setPk(columnEntity);
            }
            columnsList.add(columnEntity);
        }
        tableEntity.setColumns(columnsList);
    }

    private static void setTableEntity(TableEntity tableEntity, GeneratorParams generatorParams) {
        tableEntity.setTableName(generatorParams.getTableName());
        tableEntity.setComments(generatorParams.getTableComment());
        //表名轉(zhuǎn)換成Java類名
        Configuration config = getConfig();
        String className = tableToJava(tableEntity.getTableName(), config.getString("tablePrefix"));
        tableEntity.setUpperClassName(className);
        tableEntity.setLowerClassName(StringUtils.uncapitalize(className));
    }

    /**
     * 列名轉(zhuǎn)換成Java屬性名
     */
    private static String columnToJava(String columnName) {
        return WordUtils.capitalizeFully(columnName, new char[]{'_'}).replace("_", "");
    }

    /**
     * 表名轉(zhuǎn)換成Java類名
     */
    private static String tableToJava(String tableName, String tablePrefix) {
        if (StringUtils.isNotBlank(tablePrefix)) {
            tableName = tableName.replaceFirst(tablePrefix, "");
        }
        return columnToJava(tableName);
    }

    /**
     * 獲取配置信息
     */
    private static Configuration getConfig() {
        try {
            return new PropertiesConfiguration("generator.properties");
        } catch (ConfigurationException e) {
            throw new RuntimeException("獲取配置文件失敗,", e);
        }
    }

    /**
     * 獲取文件名
     */
    private static String getFileName(String templateName, String className, GeneratorParams generatorParams) {
        String packagePath = getPackagePath(generatorParams);
        if (StringUtils.isNotBlank(templateName)) {
            String afterClassName = templateName.substring(templateName.lastIndexOf("/") + 1, templateName.indexOf("."));
            if (templateName.contains("template/jpa/Specifications.java.vm")) {
                return packagePath + "repository" + File.separator + className + "Specifications.java";
            }
            if (templateName.endsWith("Mapper.xml.vm")) {
                return packagePath + afterClassName.toLowerCase() + File.separator + className + afterClassName + ".xml";
            }
            if (templateName.contains("template/jpa/Domain.java.vm")
                    || templateName.endsWith("Entity.java.vm")) {
                return packagePath + afterClassName.toLowerCase() + File.separator + className + ".java";
            }
            if (templateName.endsWith("EntityParam.java.vm")) {
                return packagePath + "entity/param" + File.separator + className + "Param.java";
            }
            if (templateName.endsWith("ServiceImpl.java.vm")) {
                return packagePath + "service/impl" + File.separator + className + afterClassName + ".java";
            }
            if (templateName.endsWith("PageResult.java.vm")) {
                return packagePath + "util" + File.separator + "PageResult.java";
            }
            if (templateName.endsWith("RestResp.java.vm")) {
                return packagePath + "util" + File.separator + "RestResp.java";
            }
            return packagePath + afterClassName.toLowerCase() + File.separator + className + afterClassName + ".java";
        }
        return null;
    }
}

項目地址:
前端:https://github.com/dengweiping4j/code-generator-ui.git
后端:https://github.com/dengweiping4j/CodeGenerator.git文章來源地址http://www.zghlxwxcb.cn/news/detail-826215.html

到了這里,關(guān)于Java在線代碼生成工具,支持JPA、Mybatis、MybatisPlus的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 畢業(yè)設(shè)計——基于java+vue開發(fā)的在線教育平臺,將開發(fā)PC、小程序、手機端,集成RABC權(quán)限+在線考試+文檔預(yù)覽+視頻播放+代碼生成器等功能

    完整項目地址:https://download.csdn.net/download/lijunhcn/88556337 本項目是基于java+vue開發(fā)的[在線教育平臺],將開發(fā)PC、小程序、手機端,集成RABC權(quán)限+在線考試+文檔預(yù)覽+視頻播放+代碼生成器等功能。 版本控制:git 依賴管理:maven 接口文檔:Swagger 權(quán)限驗證:Spring Security 數(shù)據(jù)庫:

    2024年02月03日
    瀏覽(93)
  • css在線代碼生成器

    css在線代碼生成器

    這里收集了許多有意思的css效果在線代碼生成器適合每一位前端開發(fā)者 網(wǎng)格生成器https://cssgrid-generator.netlify.app/ CSS Grid Generator可幫助開發(fā)人員使用CSS Grid創(chuàng)建復(fù)雜的網(wǎng)格布局。網(wǎng)格布局是創(chuàng)建Web頁面的靈活和響應(yīng)式設(shè)計的強大方式。 布局生成器https://layout.bradwoods.io/ CSS布局生

    2024年02月14日
    瀏覽(100)
  • CRC校驗Verilog代碼在線生成

    CRC校驗Verilog代碼在線生成

    ??在FPGA設(shè)計的過程中,在有些場景下,我們需要用到CRC(Cyclic Redundancy Check)校驗碼,比如以太網(wǎng)報文、信道編碼等。對應(yīng)的,我們需要編寫相應(yīng)的Verilog代碼用于計算對應(yīng)的CRC校驗碼。我們可以根據(jù)CRC校驗的原理自己編寫一個產(chǎn)生CRC校驗碼的Verilog模塊,也可以通過在線網(wǎng)站進

    2024年02月11日
    瀏覽(50)
  • springboot整合mybatis代碼快速生成

    springboot整合mybatis代碼快速生成

    特別說明:本次項目整合基于idea進行的,如果使用Eclipse可能操作會略有不同,不過總的來說不影響。 springboot整合之如何選擇版本及項目搭建 springboot整合之版本號統(tǒng)一管理? springboot整合mybatis-plus+durid數(shù)據(jù)庫連接池 springboot整合swagger springboot整合mybatis代碼快速生成 springboot整

    2024年02月02日
    瀏覽(15)
  • 【Mybatis-Plus】代碼生成器

    【Mybatis-Plus】代碼生成器

    目錄 安裝插件 數(shù)據(jù)庫建表? Other Config Database Code Generator 根據(jù)創(chuàng)建好的數(shù)據(jù)庫表,來直接生成代碼 ? 點開之后有兩個功能 1.數(shù)據(jù)庫配置 2.代碼生成 首先點開這個配置數(shù)據(jù)庫 ? ? 配置完數(shù)據(jù)庫后,再點擊這個功能 ? 勾選完畢之后,點擊code generator ? 這幾個包就自動生成出來

    2024年02月06日
    瀏覽(95)
  • Mybatis-plus 代碼生成器

    Mybatis-plus 代碼生成器

    1、pom.xml 2、mybatis-generator.xml 這里可以生成一個example類 什么是example類? Mybatis-Plus的代碼生成器可以自動生成一些基本的代碼文件,其中包括了Example(查詢條件構(gòu)造器)類。如下是Example類的大致解釋和用法: Example類是在Mybatis-Plus中用于構(gòu)建復(fù)雜條件查詢的常用工具類,它是

    2024年02月01日
    瀏覽(92)
  • 5.6 Mybatis代碼生成器Mybatis Generator (MBG)實戰(zhàn)詳解

    5.6 Mybatis代碼生成器Mybatis Generator (MBG)實戰(zhàn)詳解

    本文我們主要實戰(zhàn)Mybatis官方的代碼生成器:Mybatis Generator(MBG),掌握它以后,可以簡化大部分手寫代碼,我們只需要寫復(fù)雜邏輯代碼! 通過前幾篇,我們掌握了在SpringBoot下Mybatis的基本用法,操作步驟回顧一下: 創(chuàng)建與MySQL表對應(yīng)的Java PO對象,字段一一對應(yīng); 創(chuàng)建Mapper接口,

    2024年02月05日
    瀏覽(20)
  • 代碼生成器-mybatis-plus-generator

    代碼生成器-mybatis-plus-generator

    我們平時在開發(fā)的過程中,對于新建的一張表難免會有對其進行增刪改查的操作,而且還要寫Controller、service、Mapper、Mapper.xml、PO、VO等等。如果每次都要去寫這些跟業(yè)務(wù)毫不相干但是卻又耗時耗力的重復(fù)代碼這不僅是讓開發(fā)人員不能專注于業(yè)務(wù)邏輯甚至可能由于不注意導(dǎo)致字

    2023年04月25日
    瀏覽(21)
  • 在SpringBoot使用MyBatis-Plus代碼生成器

    在SpringBoot使用MyBatis-Plus代碼生成器

    文章目錄 前言 一、引入依賴 二、使用步驟 1.創(chuàng)建一個類(例如CodeGenerator) 2.編輯生成模板 三、一鍵生成代碼 ?結(jié)尾 在SpringBoot中,通過引入MyBatis-Plus 實現(xiàn)數(shù)據(jù)庫代碼生成器,我還寫好了一些模板方法,可一鍵生成。 注意 適用版本:mybatis-plus-generator 3.5.1 及其以上版本 在

    2024年02月02日
    瀏覽(28)
  • mybatis-generator代碼生成器的使用與配置

    mybatis-generator代碼生成器的使用與配置

    官網(wǎng)的MyBatis Generator使用介紹,請點擊下面的鏈接: 鏈接 MyBatis Generator 生成的文件包含三類: (1)Model實體文件,一個數(shù)據(jù)庫表對應(yīng)生成一個 Model 實體; (2)Mapper接口文件,數(shù)據(jù)數(shù)操作方法都在此接口中定義; (3)Mapper?XML配置文件 在pom.xml文件添加如下依賴: 代碼如下

    2024年02月14日
    瀏覽(18)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包