开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 131

bercz/codeMan

forked from 小螺旋丸/codeMan
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
标签 (2)
master
v2.35
v2.33
master
分支 (1)
标签 (2)
master
v2.35
v2.33
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 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)
标签 (2)
master
v2.35
v2.33
codeMan
/
src
/
main
/
java
/
codeMaker
/
MutiTableConfig.java
codeMan
/
src
/
main
/
java
/
codeMaker
/
MutiTableConfig.java
MutiTableConfig.java 15.69 KB
一键复制 编辑 原始数据 按行查看 历史
zhangruixuann 提交于 2022年04月10日 18:56 +08:00 . feat:版本更新
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 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
package codeMaker;
import codeMaker.impl.MakeCodeImpl;
import com.sun.org.apache.regexp.internal.REUtil;
import constant.ChildWindowConstant;
import constant.CodeConstant;
import constant.Constant;
import entity.DataSourceModel;
import entity.DatabaseModel;
import org.apache.commons.lang3.StringUtils;
import javax.swing.*;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.util.Map;
/**
* 多数据源配置
*
* @author zrx
*/
public class MutiTableConfig extends JFrame {
private static MutiTableConfig frame = null;
private static final String DATA_SOURCE_REGX = "^(?=.{1,10}$)[a-zA-Z]{1,10}\\d{0,10}$";
/**
* serialVersionUID
*/
public static final long serialVersionUID = -872842032932282858L;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(() -> {
try {
//如果已经打开过了,关闭之前的
if (frame != null) {
frame.dispose();
frame = null;
}
frame = new MutiTableConfig();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
});
}
/**
* Create the frame.
*/
private MutiTableConfig() {
//组件
JPanel contentPane = new JPanel();
JLabel chooseDataSourceLabel = new JLabel("选择数据源");
JLabel dataBaseTypeLabel = new JLabel("数据库类型");
JComboBox<String> dataBaseTypeBox = new JComboBox<>();
JLabel ipLabel = new JLabel("数据库ip");
JTextField ipText = new JTextField();
JLabel portLabel = new JLabel("端口");
JTextField portText = new JTextField();
JLabel userNameLabel = new JLabel("用户名");
JTextField userNameText = new JTextField();
JLabel pwdLabel = new JLabel("密码");
JTextField pwdText = new JTextField();
JLabel databaseNameLabel = new JLabel("数据库名称(SERVICE NAME/SID)");
JTextField databaseNameText = new JTextField();
JLabel dataSourceLabel = new JLabel("数据源名称");
JTextField dataSourceText = new JTextField();
JComboBox<String> chooseDataSourceBox = new JComboBox<>();
//获取主界面的dataSourcecBoxModelMain
DefaultComboBoxModel<String> dataSourcecBoxModelMain = (DefaultComboBoxModel<String>) MakeCodeImpl.getInstance().dataSouceBox.getModel();
DefaultComboBoxModel<String> dataSourcecBoxModelCloudSys = (DefaultComboBoxModel<String>) MakeCodeImpl.getInstance().cloudSysDsComboBox.getModel();
DefaultComboBoxModel<String> dataSourcecBoxModel = new DefaultComboBoxModel<>();
for (int i = 0; i < dataSourcecBoxModelMain.getSize(); i++) {
dataSourcecBoxModel.addElement(dataSourcecBoxModelMain.getElementAt(i));
}
chooseDataSourceBox.setModel(dataSourcecBoxModel);
JLabel tableNameLabel = new JLabel("数据表(多个用 # 隔开)");
JTextField tableNameText = new JTextField();
tableNameText.setColumns(10);
JLabel lblNewLabel = new JLabel("<html><body style='color:red'>以上除数据表皆为必填项,配置完之后点击保存即可在主界面选择</body></html>");
JButton saveSourceBtn = new JButton("保存");
JButton delBtn = new JButton("删除");
//配置
setResizable(true);
setTitle("数据源配置");
setIconImage(Toolkit.getDefaultToolkit().getImage(MakeCode.class.getResource(
"/org/pushingpixels/substance/internal/contrib/randelshofer/quaqua/images/color_wheel.png")));
setBounds(100, 100, 595, 435);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
dataBaseTypeBox.setModel(new DefaultComboBoxModel<>(new String[]{"mysql", "oracle", "postgresql", "sqlserver"}));
ipText.setColumns(10);
portText.setColumns(10);
userNameText.setColumns(10);
pwdText.setColumns(10);
databaseNameText.setColumns(10);
dataSourceText.setColumns(10);
//保存listener
saveSourceBtn.addActionListener(e -> {
//如果校验不通过
if (!checkNecessary(ipText, portText, userNameText, pwdText, databaseNameText, dataSourceText)) {
JOptionPane.showMessageDialog(null, "请把输入框填写完毕 && 数据源名称由字母或数字组成,必须以字母开头,长度不要超过10位", "警告",
JOptionPane.WARNING_MESSAGE);
return;
}
//如果已经存在该数据源
String dataSourceName = dataSourceText.getText();
if (ChildWindowConstant.dataSourceModelMap.containsKey(dataSourceName)) {
//如果不覆盖,直接return
if (JOptionPane.showConfirmDialog(null,
"该数据源已存在,是否覆盖?覆盖后原来配置的数据项等信息将自动失效,需要重新配置!",
"提示", JOptionPane.YES_NO_OPTION) != 0) {
return;
}
}
//设置数据源信息并添加到全局变量
DataSourceModel dataSourceModel = new DataSourceModel();
dataSourceModel.setDataSourceName(dataSourceName);
dataSourceModel.setDataBaseTypeVal((String) dataBaseTypeBox.getSelectedItem());
dataSourceModel.setDataBaseIpVal(ipText.getText());
dataSourceModel.setDataBasePortVal(portText.getText());
dataSourceModel.setDataBasePwdVal(pwdText.getText());
dataSourceModel.setDataBaseNameVal(databaseNameText.getText());
dataSourceModel.setDataBaseUserNameVal(userNameText.getText());
String tableName = tableNameText.getText();
for (Map.Entry<String, DataSourceModel> entry : ChildWindowConstant.dataSourceModelMap.entrySet()) {
String sourceName = entry.getKey();
DataSourceModel model = entry.getValue();
String modelTableName = model.getTableName();
String[] modelTableNameArr = modelTableName.split("#");
String[] tableNameArr = tableName.split("#");
//如果不是自己
if (!sourceName.equals(dataSourceName)) {
for (String name : tableNameArr) {
for (String modelName : modelTableNameArr) {
//如果发现不同的数据源有配置的相同的表,给予提示
if (name.equals(modelName)) {
JOptionPane.showMessageDialog(null, "数据源 " + sourceName + " 中已经配置了 " + name + " 表,暂不支持不同数据源配置相同名称的表" + CodeConstant.NEW_LINE + CodeConstant.NEW_LINE +
"猜测您是想配置多数据源主从读写分离,在代码生成后直接修改对应 service 层的 @DBType 注解即可动态选择方法执行主库或从库,所以只需要配置主数据源的表即可" + CodeConstant.NEW_LINE + CodeConstant.NEW_LINE +
"也可以通过修改 DynamicDataSourceAspect 切面来定制数据源的个性化切换!", "提示",
JOptionPane.WARNING_MESSAGE);
return;
}
}
}
}
}
dataSourceModel.setTableName(tableName);
//放入全局变量
ChildWindowConstant.dataSourceModelMap.put(dataSourceName, dataSourceModel);
//先移除,再添加
dataSourcecBoxModel.removeElement(dataSourceName);
dataSourcecBoxModel.addElement(dataSourceName);
//同步主界面多数据源
dataSourcecBoxModelMain.removeElement(dataSourceName);
dataSourcecBoxModelMain.addElement(dataSourceName);
//同步系统服务数据源
dataSourcecBoxModelCloudSys.removeElement(dataSourceName);
dataSourcecBoxModelCloudSys.addElement(dataSourceName);
JOptionPane.showMessageDialog(null, "保存成功!", "提示",
JOptionPane.INFORMATION_MESSAGE);
});
//数据源下拉listener
chooseDataSourceBox.addItemListener(e -> {
if (e.getStateChange() != ItemEvent.SELECTED) {
return;
}
String dataSoucrce = (String) chooseDataSourceBox.getSelectedItem();
//如果选择请选择
if (CodeConstant.PLEASE_CHOOSE.equals(dataSoucrce)) {
ipText.setText("");
dataBaseTypeBox.setSelectedItem("mysql");
portText.setText("");
userNameText.setText("");
pwdText.setText("");
databaseNameText.setText("");
dataSourceText.setText("");
tableNameText.setText("");
return;
}
DataSourceModel dataSourceModel = ChildWindowConstant.dataSourceModelMap.get(dataSoucrce);
ipText.setText(dataSourceModel.getDataBaseIpVal());
dataBaseTypeBox.setSelectedItem(dataSourceModel.getDataBaseTypeVal());
portText.setText(dataSourceModel.getDataBasePortVal());
userNameText.setText(dataSourceModel.getDataBaseUserNameVal());
pwdText.setText(dataSourceModel.getDataBasePwdVal());
databaseNameText.setText(dataSourceModel.getDataBaseNameVal());
dataSourceText.setText(dataSourceModel.getDataSourceName());
tableNameText.setText(dataSourceModel.getTableName());
});
/**
* 删除监听器
*/
delBtn.addActionListener(e -> {
String dataSoucrce = (String) chooseDataSourceBox.getSelectedItem();
if (CodeConstant.PLEASE_CHOOSE.equals(dataSoucrce)) {
JOptionPane.showMessageDialog(null, "请选择需要删除的数据源再进行删除!", "警告",
JOptionPane.WARNING_MESSAGE);
return;
}
dataSourcecBoxModel.removeElement(dataSoucrce);
dataSourcecBoxModelMain.removeElement(dataSoucrce);
//同步删除
dataSourcecBoxModelCloudSys.removeElement(dataSoucrce);
//删除全局变量
ChildWindowConstant.dataSourceModelMap.remove(dataSoucrce);
JOptionPane.showMessageDialog(null, "删除成功!", "提示",
JOptionPane.INFORMATION_MESSAGE);
});
//样式
GroupLayout glContentPane = new GroupLayout(contentPane);
glContentPane.setHorizontalGroup(
glContentPane.createParallelGroup(Alignment.TRAILING)
.addGroup(glContentPane.createSequentialGroup()
.addGap(154)
.addComponent(saveSourceBtn, GroupLayout.PREFERRED_SIZE, 91, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(delBtn, GroupLayout.PREFERRED_SIZE, 91, GroupLayout.PREFERRED_SIZE)
.addContainerGap(227, Short.MAX_VALUE))
.addGroup(glContentPane.createSequentialGroup()
.addContainerGap()
.addGroup(glContentPane.createParallelGroup(Alignment.LEADING)
.addComponent(lblNewLabel, GroupLayout.DEFAULT_SIZE, 445, Short.MAX_VALUE)
.addGroup(glContentPane.createSequentialGroup()
.addComponent(tableNameLabel)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(tableNameText, GroupLayout.DEFAULT_SIZE, 304, Short.MAX_VALUE))
.addGroup(glContentPane.createSequentialGroup()
.addGroup(glContentPane.createParallelGroup(Alignment.LEADING)
.addGroup(glContentPane.createSequentialGroup()
.addGroup(glContentPane.createParallelGroup(Alignment.LEADING)
.addGroup(glContentPane.createSequentialGroup()
.addComponent(ipLabel)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(ipText, GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE)
.addGap(18)
.addComponent(portLabel))
.addGroup(glContentPane.createSequentialGroup()
.addComponent(chooseDataSourceLabel)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(chooseDataSourceBox, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(glContentPane.createParallelGroup(Alignment.LEADING)
.addGroup(glContentPane.createSequentialGroup()
.addGap(4)
.addComponent(portText, GroupLayout.PREFERRED_SIZE, 46, GroupLayout.PREFERRED_SIZE)
.addGap(29)
.addComponent(userNameLabel)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(userNameText, GroupLayout.PREFERRED_SIZE, 48, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
.addComponent(pwdLabel)
.addGap(4))
.addGroup(glContentPane.createSequentialGroup()
.addGap(24)
.addComponent(dataBaseTypeLabel)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(dataBaseTypeBox, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE))))
.addGroup(glContentPane.createSequentialGroup()
.addComponent(databaseNameLabel)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(databaseNameText, GroupLayout.PREFERRED_SIZE, 55, GroupLayout.PREFERRED_SIZE)
.addGap(27)
.addComponent(dataSourceLabel)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(dataSourceText, GroupLayout.PREFERRED_SIZE, 52, GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(pwdText, GroupLayout.PREFERRED_SIZE, 47, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)))
.addGap(127))
);
glContentPane.setVerticalGroup(
glContentPane.createParallelGroup(Alignment.LEADING)
.addGroup(glContentPane.createSequentialGroup()
.addGap(18)
.addGroup(glContentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(chooseDataSourceLabel)
.addComponent(chooseDataSourceBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(dataBaseTypeLabel)
.addComponent(dataBaseTypeBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addGroup(glContentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(ipLabel)
.addComponent(pwdLabel)
.addComponent(ipText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(pwdText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(portLabel)
.addComponent(portText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(userNameLabel)
.addComponent(userNameText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addGroup(glContentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(databaseNameLabel)
.addComponent(dataSourceLabel)
.addComponent(dataSourceText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(databaseNameText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addGroup(glContentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(tableNameLabel)
.addComponent(tableNameText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addComponent(lblNewLabel)
.addGap(18)
.addGroup(glContentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(saveSourceBtn)
.addComponent(delBtn))
.addContainerGap(154, Short.MAX_VALUE))
);
contentPane.setLayout(glContentPane);
}
/**
* 检查参数是否完整
*
* @return
*/
private boolean checkNecessary(JTextField ipText, JTextField portText, JTextField userNameText, JTextField pwdText, JTextField databaseNameText, JTextField dataSourceText) {
if (StringUtils.isBlank(ipText.getText())
|| StringUtils.isBlank(portText.getText()) || StringUtils.isBlank(userNameText.getText())
|| StringUtils.isBlank(pwdText.getText()) || StringUtils.isBlank(databaseNameText.getText())
|| StringUtils.isBlank(dataSourceText.getText())) {
return false;
}
//检查数据源名称是否由英文和数字组成
return dataSourceText.getText().matches(DATA_SOURCE_REGX);
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

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

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

取消
提交

简介

代码生成器源码,可一键生成controller,service,dao,实体类,单表、多表的sql语句,日志处理、事务支持等,同时可以生成dubbo和springCloud脚手架方便开发微服务项目,能在很大程度上提高开发效率,节约开发时间。代码生成完毕后即为一个前台到后台的完整项目。目前后台支持SSM/SpringBoot,数据库支持mysql/postgresql/oracle,前台样式使用BootStrap,js支持jquery/vue,导入eclipse/idea便可运行,可根据需求自由扩展!
暂无标签
Apache-2.0
使用 Apache-2.0 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/bercz/codeMan.git
git@gitee.com:bercz/codeMan.git
bercz
codeMan
codeMan
master
点此查找更多帮助

搜索帮助

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

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