Giter Site home page Giter Site logo

autogen's Introduction

autogen

pasering sql by alibaba druid and generate swagger api simply.by default records in table config_controller are generation by sql with index cloumns as conditions ,('') as default values each indexes will generate one relative record in table config_controller,and two api url neither in Datainfo format or List<> format.

first, get the source code

git clone https://github.com/wzpabc/autogen.git

cd autogen&&ls

chmod 755 ./install.sh

second,modify the db connections

modify the db connections from files install.sh and application.properties, piont to you mysql database

  • install.sh

Image text

  • application.properties

Image text

then, testing

pase the sql script below in your database, pick up the one works ,to make sure ./src/main/resources/sql/mysql_config_controller.sql is correct

  • for Server version: 5.5.60-MariaDB MariaDB Server or mysql(not community version)
SELECT
        concat('_group_',substring_index( t.name,'_',1)) `group_id`,
        database() table_schema,
        t.name table_name,
        'table' table_type,
        concat('desc','_',t.name) table_desc,
        concat('api','_',t.name) api_value,
        concat('notes','_',t.name) notes,
        concat('\"',t.name,'\"')flag,
        'application/json' producers,
        'true' required,
        0 isdisabled,
        'no' construct,
        0 ignored,
        i.name request_path,
        'GET'request_method,
        i.name function_name,
        concat('select * from ',t.name,' where ',GROUP_CONCAT(concat(f.name,'=\'\'') ORDER BY f.pos separator ' and ') ) query,
        case when i.name like '%uniq%' then 1 else 0 end isunique,
        0 auth,
        CURRENT_TIMESTAMP() update_date
FROM information_schema.innodb_sys_tables t
        JOIN information_schema.innodb_sys_indexes i USING (table_id)
        JOIN information_schema.innodb_sys_fields f USING (index_id)
WHERE t.schema = database()
        and t.name<>'config_controller'
        and i.name<>'PRIMARY'
        and i.name like 'idx%'
        and t.name like 'temp_test_autogen%'
        GROUP BY t.name,i.name limit 2
  • for Server version: 5.6.39 MySQL Community Server (GPL)

please select those indexes that make sense by changing the where condition clause , such as and i.name like 'idx%'

SELECT
       concat('_group_', substring_index( substring_index(t.name,'/',-1) ,'_',1) ) `group_id`,
       database() table_schema,
        substring_index(t.name,'/',-1)  table_name,
       'table' table_type,
       concat('desc','_', substring_index(t.name,'/',-1) ) table_desc,
       concat('api','_', substring_index(t.name,'/',-1) ) api_value,
       concat('notes','_', substring_index(t.name,'/',-1) ) notes,
       concat('\"', substring_index(t.name,'/',-1) ,'\"')flag,
       'application/json' producers,
       'true' required,
       0 isdisabled,
       'no' construct,
       0 ignored,
       i.name request_path,
       'GET'request_method,
       i.name function_name,
       concat('select * from ', substring_index(t.name,'/',-1) ,' where ',GROUP_CONCAT(concat(f.name,'=\'\'') ORDER BY f.pos  separator ' and ') ) query,
       case when i.name like '%uniq%' then 1 else 0 end isunique,
       0 auth,
       CURRENT_TIMESTAMP() update_date
FROM information_schema.innodb_sys_tables t
	  JOIN information_schema.tables x on x.table_name=substring_index(t.name,'/',-1) and x.table_schema=substring_index(t.name,'/',1)
       JOIN information_schema.innodb_sys_indexes i USING (table_id)
       JOIN information_schema.innodb_sys_fields f USING (index_id)
WHERE x.table_schema = database() and substring_index(t.name,'/',-1) <>'config_controller'
  and i.name<>'PRIMARY'
  and i.name like 'idx%'
  and substring_index(t.name,'/',-1) like 'temp_test_autogen%'
   /*and i.name   like 'idx%'*/
GROUP BY t.name,i.name limit 10
;

finally, run shell script

locate to root folder of project then

./install.sh

demo

http://localhost:8085/auto/swagger-ui.html

Image text

Please know that

also can modify table config_controller manually to make it more beautifull,

  • clear it first. source code in github already clean.

mvn test -Dtest=com.tupperware.auto.controller.ConfigControllerControllerTest#clear

  • generate the api again when finish modification

mvn clean

mvn test -Dtest=com.tupperware.auto.controller.ConfigControllerControllerTest#execute

sleep 5

mvn clean

mvn package -Dmaven.test.skip=true

ps aux | grep "autogen-1.0.1-RELEASE.jar" |grep -v grep| cut -c 9-15 | xargs kill -9 >/dev/null 2>&1

nohup java -Xmx1024m -jar ./target/autogen-1.0.1-RELEASE.jar >/dev/null 2>&1 &

#!/bin/bash
git clone https://github.com/wzpabc/autogen.git
cd autogen
mysql -uroot -proot gen_mysql < ./src/main/resources/sql/mysql_config_controller.sql
mvn clean
mvn test -Dtest=com.tupperware.auto.controller.ConfigControllerControllerTest#clear
mvn test -Dtest=com.tupperware.auto.controller.ConfigControllerControllerTest#execute
sleep 5
mvn clean
mvn package -Dmaven.test.skip=true
ps aux | grep "autogen-1.0.1-RELEASE.jar" |grep -v grep| cut -c 9-15 | xargs kill -9 >/dev/null 2>&1
echo killing
sleep 5
nohup java -Xmx1024m -jar ./target/autogen-1.0.1-RELEASE.jar  >/dev/null 2>&1 &
echo start

点击前往谷歌搜索

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.