C ා implement code generator [Client]

Time:2020-12-21

After 2 or 3 years of Java Web, there is no way to escape from the so-called basic business, add, delete, modify and check these unchanging things, which wastes a lot of time to write, so a simple code generator is created quickly

In fact, the principle of code generator is very simple. It is based on template, and the template is based on nvilocity.

Part of the code display: [currently only supports mysql, Oracle and SQLite database connections. You can add them if necessary]

sing System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using personal_manage.Common.DAL;
using personal_manage.Common.dto;
using personal_manage.DAL.adapter;
using personal_manage.Models.entity;

namespace personal_manage.BLL.adapter
{
    public class DbBLL
    {
        public List<TableInfo> SelectTableList(CodeProjectDbConfigInfo codeProjectDbConfigInfo, string tableKeyword)
        {
            if (codeProjectDbConfigInfo.DbType == "Mysql" )
            {
              return  DbAdapter.SelectTableNameByMySql(codeProjectDbConfigInfo.DbConnect, codeProjectDbConfigInfo.DbName, tableKeyword);
            }else if(codeProjectDbConfigInfo.DbType == "Oracle")
            {
                return DbAdapter.SelectTableNameByOracle(codeProjectDbConfigInfo.DbConnect, codeProjectDbConfigInfo.DbName, tableKeyword);
            }
            else if (codeProjectDbConfigInfo.DbType == "Sqlite")
            {
                return DbAdapter.SelectTableNameBySqlite(codeProjectDbConfigInfo.DbConnect, codeProjectDbConfigInfo.DbName, tableKeyword);
            }


            return null;
        }


        public List<TableFieldInfo> SelectTableFields(CodeProjectDbConfigInfo codeProjectDbConfigInfo, string tableName)
        {
            if (codeProjectDbConfigInfo.DbType == "Mysql")
            {
                return DbAdapter.SelectTableFieldsByMySql(codeProjectDbConfigInfo.DbConnect, codeProjectDbConfigInfo.DbName, tableName);
            }
            else if (codeProjectDbConfigInfo.DbType == "Oracle")
            {
                return DbAdapter.SelectTableFieldsByOracle(codeProjectDbConfigInfo.DbConnect, codeProjectDbConfigInfo.DbName, tableName);
            }
            else if (codeProjectDbConfigInfo.DbType == "Sqlite")
            {
                return DbAdapter.SelectTableFieldsBySqlite(codeProjectDbConfigInfo.DbConnect, codeProjectDbConfigInfo.DbName, tableName);
            }

            return null;
        }
    }
}

Demo interface:
Database configuration
C ා implement code generator [Client]

Template configuration:

C ා implement code generator [Client]

C ා implement code generator [Client]

Generation:

C ා implement code generator [Client]

There is a set of Java templates built in, which calls the jar package [JDK needs to be installed. All the file storage locations that are said to be C # C + + Java, and the actual generated suffixes are. Java or. JSP. HTML]

C ා implement code generator [Client]
C ා implement code generator [Client]

Source code address:https://gitee.com/ten-ken/per…

This article comes from: programmer Ken, exclusive platforms are CSDN, segmentfault, Jianshu, oschina, diggings. Please indicate the source of reprint.

Recommended Today

DK7 switch’s support for string

Before JDK7, switch can only support byte, short, char, int or their corresponding encapsulation classes and enum types. After JDK7, switch supports string type. In the switch statement, the value of the expression cannot be null, otherwise NullPointerException will be thrown at runtime. Null cannot be used in the case clause, otherwise compilation errors will […]