开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
codeutil
/
src
/
main
/
java
/
templet
/
ClientTempletUtil.java
codeutil
/
src
/
main
/
java
/
templet
/
ClientTempletUtil.java
ClientTempletUtil.java 7.03 KB
一键复制 编辑 原始数据 按行查看 历史
皇叔 提交于 2019年01月24日 17:59 +08:00 . 'x'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
package templet;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import entity.Column;
import entity.Table;
/**
* 模板处理类 用于替换内容
* @author Administrator
*
*/
public class ClientTempletUtil {
/**
* 根据目录查找所有子模板
* @param basePath
* @return
*/
public static Map<String ,String > getTempletList(String basePath)
{
Map<String ,String> map=new HashMap();
//递归显示C盘下所有文件夹及其中文件
File root = new File(basePath);
try {
map=showAllFiles(basePath,root);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return map;
}
static Map<String ,String > showAllFiles( String basePath, File dir) throws Exception
{
Map<String ,String> map=new HashMap();
File[] fs = dir.listFiles();
for(int i=0; i<fs.length; i++){
File file=new File(fs[i].getAbsolutePath());
//将读取的子模板的内容放在map集合中
if(fs[i].isDirectory()){
try{
map.putAll( showAllFiles(basePath,fs[i]) );
}catch(Exception e)
{
}
}else
{
map.put(file.getName(), FileUtil.getContent(fs[i].getAbsolutePath()) ) ;
}
}
return map;
}
/**
* 替换列级模板
* @param oldContent 原文本
* @param map 子替换符号列表
* @return
*/
public static String createContent(String oldContent, Map<String,String> map ,Table table)
{
//循环所有子替换符
for(String ks :map.keySet() )
{
String thf="<"+ks+">";//替换符号
if(oldContent.indexOf(thf)>=0)
{
String foreachContent=map.get(ks);//循环体
StringBuilder createContent= new StringBuilder();
for( Column column : table.getColumns() )
{
boolean b=true;//控制开关
//只循环主键
if(ks.indexOf(".key")>=0)
{
if(!column.getColumnKey().equals("PRI"))
{
b=false;//不是主键
}
}
//只循环非主键
if(ks.indexOf(".nokey")>=0)
{
if(column.getColumnKey().equals("PRI"))
{
b=false;//不是主键
}
}
//只循环String 类型
if(ks.indexOf(".String")>=0)
{
if(!column.getColumnType().equals("String"))
{
b=false;//不是String
}
}
//只循环String 类型
if(ks.indexOf(".Integer")>=0)
{
if(!column.getColumnType().equals("Integer"))
{
b=false;//不是String
}
}
//只循环Long类型
if(ks.indexOf(".Long")>=0)
{
if(!column.getColumnType().equals("Long"))
{
b=false;//不是String
}
}
//只循环Date 类型
if(ks.indexOf(".Date")>=0)
{
if(!column.getColumnType().equals("java.util.Date"))
{
b=false;//不是String
}
}
//根据模板生成新内容
if(b)
{
System.out.println("替换符号内容:"+foreachContent);
String newContent= foreachContent.replace("[column]", column.getColumnName());
newContent=newContent.replace("[Column]", Utils.getClassName(column.getColumnName()) );
newContent=newContent.replace("[column2]", column.getColumnName2() );
newContent=newContent.replace("[Column2]", Utils.getClassName(column.getColumnName2()) );
newContent=newContent.replace("[type]", column.getColumnType());//java类型
newContent=newContent.replace("[dbtype]", column.getColumnDbType());//数据库类型
if(column.getColumnComment()==null || column.getColumnComment().equals("")){
column.setColumnComment(column.getColumnName());//设置为名称
}
newContent= newContent.replace("[columnComment]", column.getColumnComment());//备注
createContent.append(newContent);
System.out.println("替换后内容:"+newContent);
}
}
oldContent=oldContent.replace(thf, createContent.toString());//替换主体内容
}
}
oldContent= oldContent.replace("[table]", table.getName());
oldContent= oldContent.replace("[Table]", Utils.getClassName(table.getName()) );
oldContent= oldContent.replace("[table2]", table.getName2());
oldContent= oldContent.replace("[Table2]", Utils.getClassName(table.getName2()) );
if(table.getComment()==null || table.getComment().equals("")){
table.setComment(table.getName2());
}
oldContent= oldContent.replace("[comment]", table.getComment());//备注
if(table.getKey()!=null){
oldContent= oldContent.replace("[key]", table.getKey());// 主键
}
if(table.getKey2()!=null){
oldContent= oldContent.replace("[key2]", table.getKey2());//主键驼峰
}
if(table.getKeyType()!=null){
oldContent= oldContent.replace("[keyType]", table.getKeyType());//主键类型
}
if(table.getKey2Upper()!=null){
oldContent= oldContent.replace("[Key2]", table.getKey2Upper());//大写主键
}
return oldContent;
}
/**
* 替换表级模板
* @param oldContent 原文本
* @param map 子替换符号列表
* @return
*/
public static String createContentForTable(String oldContent, Map<String,String> map ,List<Table> tables )
{
//循环所有子替换符
for(String ks :map.keySet())
{
String thf="<"+ks+">";//替换符号
if(oldContent.indexOf(thf)>=0)
{
String foreachContent=map.get(ks);//循环体
StringBuilder createContent= new StringBuilder();
for( Table table : tables )
{
boolean b=true;//控制开关
//根据模板生成新内容
if(b)
{
String newContent= foreachContent.replace("[table]", table.getName());
newContent=newContent.replace("[Table]", Utils.getClassName(table.getName()) );
newContent=newContent.replace("[table2]", table.getName2() );
newContent=newContent.replace("[Table2]", Utils.getClassName(table.getName2()));
if(table.getKey()!=null){
oldContent= oldContent.replace("[key]", table.getKey());//备注
}
if(table.getKey2()!=null){
oldContent= oldContent.replace("[key2]", table.getKey2());//备注
}
if(table.getKeyType()!=null){
oldContent= oldContent.replace("[keyType]", table.getKeyType());//备注
}
if(table.getKey2Upper()!=null){
oldContent= oldContent.replace("[Key2]", table.getKey2Upper());//大写主键
}
if(table.getComment()==null || table.getComment().equals("")){
table.setComment(table.getName2());
}
newContent= newContent.replace("[comment]", table.getComment());//备注
createContent.append(newContent);
}
}
oldContent=oldContent.replace(thf, createContent.toString());//替换主体内容
}
}
return oldContent;
}
/**
* 替换全局替换符
* @param oldContent
* @param map
* @return
*/
public static String createContent(String oldContent,Map<String,String> map)
{
//循环所有子替换符
for(String ks :map.keySet())
{
oldContent= oldContent.replace("["+ ks + "]", map.get(ks));
}
return oldContent;
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

《黑马架构师》一款基于自主研发的模板引擎的"代码生成神器"。即便是一个工程几百个表,也可以瞬间完成基础代码的构建!用户只需建立数据库表结构,简单的几步操作就可以快速生成可以运行的一整套代码,可以极大地缩短开发周期,降低人力成本。《黑马架构师》内置了当前java和前端主流的架构模板,如SSM+dubbo 、springBooot+springCloud+springData 、前后端分离的vue+elementUI 模板、swagger API模板、数据库文档模板等。 用户通过自己开发模板也可以实现生成php、python、C# 、c++、数据库存储过程等其它编程语言的代码。
暂无标签
Apache-2.0
使用 Apache-2.0 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/windmagic/codeutil.git
git@gitee.com:windmagic/codeutil.git
windmagic
codeutil
黑马架构师(代码生成器)
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /