package com.reapal.controller;
import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
import com.reapal.conf.CustomerVelocityTemplateEngine;
import com.reapal.conf.MySqlTypeConvertExt;
import com.reapal.dao.DbConfigDao;
import com.reapal.dao.TableStrategyConfigDao;
import com.reapal.dao.TemplateDao;
import com.reapal.model.*;
import com.reapal.service.CodeService;
import com.reapal.utils.FileUtils;
import com.reapal.utils.ZipFileUtils;
import org.apache.tools.zip.ZipOutputStream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.util.*;
@Controller
@RequestMapping
public class CodeController extends BaseController{
@Autowired
private CodeService codeService;
@Autowired
private DbConfigDao dbConfigDao;
@Autowired
private Environment env;
@Autowired
private TemplateDao templateDao;
@Autowired
private TableStrategyConfigDao tableStrategyConfigDao;
@RequestMapping("/index")
public String init(HttpServletRequest request) throws UnknownHostException {
if(request.getSession().getAttribute("user") == null){
return "redirect:/login";
}
final String hostAddress = InetAddress.getLocalHost().getHostAddress();
String port = env.getProperty("server.port");
final HttpSession session = request.getSession();
session.setAttribute("wsUrl","ws://"+hostAddress+":"+port+"/chat");
return "/views/index/index";
}
@GetMapping("/getDbList")
@ResponseBody
public JSONObject getDbList(Model model){
List<DbConfig> dbConfigList = dbConfigDao.findAll();
return respJson(0,null,dbConfigList);
}
@GetMapping("/getByDbId")
@ResponseBody
public JSONObject getByDbId(Long id) throws IOException {
DbConfig dbConfig = dbConfigDao.getOne(id);
return respJson(0, "", dbConfig);
}
/**
* 显示Table列表
*/
@RequestMapping(value = "/database-list",method=RequestMethod.GET)
public String databaseList(Model model,DbConfig dbConfig){
return "/views/db/database_list";
}
/**
* 显示Table列表
*/
@RequestMapping(value = "/edit",method=RequestMethod.PUT)
@ResponseBody
public JSONObject edit(@RequestBody DbConfig dbConfig){
dbConfigDao.save(dbConfig);
return respJson(0, "修改成功", true);
}
/**
* 测试数据库配置
*/
@ResponseBody
@RequestMapping(value = "/test",method=RequestMethod.POST)
public JSONObject test( DbConfig dbConfig){
String result = codeService.testConnection(dbConfig);
if(StringUtils.isEmpty(result)){
return respJson(0,"测试成功",result);
}else{
return respJson(1,"数据库链接失败",result);
}
}
/**
* 显示Table列表
*/
@RequestMapping(value = "/save",method=RequestMethod.POST)
@ResponseBody
public JSONObject save(@RequestBody DbConfig dbConfig){
dbConfigDao.save(dbConfig);
return respJson(0,"添加成功",true);
}
/**
* 显示Table列表
*/
@RequestMapping(value = "/delete",method=RequestMethod.GET)
@ResponseBody
public JSONObject delete(Model model,DbConfig dbConfig){
dbConfigDao.delete(dbConfig.getId());
return respJson(0, "删除成功", true);
}
@GetMapping("/to-table-list")
public String toTableList(Model model) throws IOException {
return "/views/db/tables_list";
}
@GetMapping("/table-list")
@ResponseBody
public JSONObject tableList(Long id) throws IOException {
List<TableInfo> tableList = null;
try {
DbConfig dbConfig = dbConfigDao.getOne(id);
tableList = codeService.getAllTables(dbConfig);
} catch (Exception e) {
return respJson(500, "数据库链接失败",null);
}
return respJson(0, "succ", tableList);
}
@GetMapping("/to-column-list")
public String toColumnList(){
return "/views/db/column_list";
}
@GetMapping("/column-list")
@ResponseBody
public JSONObject columnList(String tableName,Long id) throws IOException {
DbConfig dbConfig = dbConfigDao.getOne(id);
TableInfo tableInfo = codeService.getAllColumns(tableName,dbConfig);
return respJson(0, "succ", tableInfo);
}
@GetMapping("/get-table-strategy")
@ResponseBody
public JSONObject getTableStrategy(String tableName,Long id) throws IOException {
return respJson(0, "succ", tableStrategyConfigDao.findByDbIdAndTableName(id,tableName));
}
/**
* 保存配置信息
*/
@RequestMapping(value = "/columnsave",method=RequestMethod.POST)
@ResponseBody
public JSONObject save(Long id , String tableName,String comments , TableStrategyConfig tableStrategyConfig){
String[] remarks = request.getParameterValues("remarks[]");
DbConfig dbConfig = dbConfigDao.getOne(id);
TableInfo tableInfo = new TableInfo();
tableInfo.setTableName(tableName);
tableInfo.setComments(comments);
List<ColumnInfo> listItem = new ArrayList<ColumnInfo>();
for(String remark:remarks){
System.out.println(remark);
String[] mark = remark.split("@");
ColumnInfo item = new ColumnInfo();
item.setColName(mark[0]);
item.setColType(mark[1]);
if(mark.length >= 3) {
item.setComments(mark[2]);
}
if (mark.length >= 4) {
item.setExtra(mark[3]);
}
if (mark.length >= 5) {
item.setNullable("true".equalsIgnoreCase(mark[4]));
}
if (mark.length >= 6) {
item.setDefaultValue(mark[5]);
}
listItem.add(item);
}
tableInfo.setListColumn(listItem);
codeService.saveComment(tableInfo,dbConfig);
tableStrategyConfig.setDbId(id);
tableStrategyConfig.setTableName(tableName);
tableStrategyConfigDao.save(tableStrategyConfig);
return respJson(0, "保存成功", true);
}
@GetMapping("/batchGenerate")
public String batchGenerate(String jsonStr,Long id,HttpServletResponse response){
TableStrategyConfig tableStrategyConfig = JSON.parseObject(jsonStr, TableStrategyConfig.class);
DbConfig dbConfig = dbConfigDao.getOne(id);
this.buildCodes(response, dbConfig, tableStrategyConfig);
return null;
}
/**
* 生成代码
*/
@RequestMapping(value="/generate",method=RequestMethod.GET)
public String generate(String tableName, Long id, HttpServletResponse response) throws IOException {
DbConfig dbConfig = dbConfigDao.getOne(id);
TableStrategyConfig tableStrategyConfig = tableStrategyConfigDao.findByDbIdAndTableName(id, tableName);
this.buildCodes(response, dbConfig, tableStrategyConfig);
return null;
}
/**
* 生成代码的核心逻辑
* @param response
* @param dbConfig
* @param tableStrategyConfig
*/
private void buildCodes(HttpServletResponse response, DbConfig dbConfig, TableStrategyConfig tableStrategyConfig) {
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
String outPutDir = request.getSession().getServletContext().getRealPath("/") + "/WEB-INF/upload/" + request.getSession().getId();
gc.setOutputDir(outPutDir);
gc.setFileOverride(true);
gc.setActiveRecord(true);
gc.setEnableCache(false);// XML 二级缓存
gc.setBaseResultMap(true);// XML ResultMap
gc.setBaseColumnList(false);// XML columList
gc.setAuthor(tableStrategyConfig.getAuthor());
gc.setEntityName(tableStrategyConfig.getEntityName());
gc.setMapperName(tableStr
没有合适的资源?快使用搜索试试~ 我知道了~
基于mybatisplus的在线代码生成工具
共560个文件
js:250个
html:150个
css:76个
需积分: 5 2 下载量 60 浏览量
2022-04-13
11:32:09
上传
评论
收藏 53.09MB ZIP 举报
温馨提示
- 基于内存数据库存储 - 在线生成代码并下载 - 一次配置多次重复使用 - 支持单表/多表批量生成代码 - 基于element-ui编写的漂亮界面
资源详情
资源评论
资源推荐
收起资源包目录
基于mybatisplus的在线代码生成工具 (560个子文件)
mvnw.cmd 5KB
element-ui.css 227KB
animate.css 84KB
markdown.css 46KB
FormMaking.css 36KB
ambiance.css 26KB
util.css 11KB
codemirror.css 8KB
solarized.css 5KB
mdn-like.css 5KB
player.css 4KB
liquibyte.css 4KB
merge.css 3KB
index.css 3KB
xq-dark.css 3KB
lint.css 3KB
duotone-light.css 3KB
lesser-dark.css 3KB
duotone-dark.css 3KB
icecoder.css 2KB
material.css 2KB
pastel-on-dark.css 2KB
darcula.css 2KB
ttcn.css 2KB
shadowfox.css 2KB
tomorrow-night-eighties.css 2KB
erlang-dark.css 2KB
oceanic-next.css 2KB
xq-light.css 2KB
monokai.css 2KB
twilight.css 2KB
vibrant-ink.css 2KB
base16-light.css 2KB
base16-dark.css 2KB
mbo.css 2KB
paraiso-dark.css 2KB
paraiso-light.css 2KB
3024-night.css 2KB
midnight.css 2KB
dracula.css 2KB
seti.css 2KB
zenburn.css 2KB
3024-day.css 2KB
abcdef.css 2KB
the-matrix.css 2KB
blackboard.css 2KB
lucario.css 2KB
yeti.css 2KB
tern.css 2KB
panda-syntax.css 2KB
rubyblue.css 2KB
tomorrow-night-bright.css 2KB
night.css 2KB
gruvbox-dark.css 2KB
cobalt.css 2KB
colorforth.css 2KB
idea.css 2KB
railscasts.css 1KB
hopscotch.css 1KB
isotope.css 1KB
bespin.css 1KB
simplescrollbars.css 1KB
v-charts.min.css 1KB
eclipse.css 1KB
neo.css 947B
main.css 929B
elegant.css 781B
ssms.css 751B
neat.css 688B
show-hint.css 623B
dialog.css 507B
tiki.css 439B
foldgutter.css 435B
tiddlywiki.css 220B
matchesonscrollbar.css 188B
fullscreen.css 116B
ambiance-mobile.css 103B
Dockerfile 225B
使用说明.docx 1.13MB
icomoon.eot 15KB
iconfont.8efbc988.eot 12KB
.gitignore 249B
scala.html 28KB
editor.html 26KB
index.html 22KB
flow_chart.html 18KB
index.html 17KB
template-set.html 15KB
index.html 13KB
index.html 13KB
index.html 12KB
index.html 12KB
index.html 10KB
index.html 10KB
state_chart.html 10KB
index.html 9KB
index.html 9KB
index.html 8KB
column_list.html 8KB
index.html 8KB
共 560 条
- 1
- 2
- 3
- 4
- 5
- 6
hellomotojava
- 粉丝: 3
- 资源: 29
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0