├── .classpath ├── .gitignore ├── .project ├── .settings ├── org.eclipse.core.resources.prefs └── org.eclipse.jdt.core.prefs ├── META-INF └── MANIFEST.MF ├── README.md ├── bin ├── .gitignore └── com │ └── thinkgem │ └── jeesite │ └── autocode │ └── crud │ └── template │ ├── entity.ftl │ └── service.ftl ├── build.properties ├── dist └── plugins │ └── com.thinkgem.jeesite.autocode_1.0.0.beta.jar ├── icons ├── about.png ├── checked.png ├── curd.png ├── database.png ├── down.png ├── report.png ├── tree.png ├── unchecked.png └── up.png ├── lib ├── blancosqlformatter-0.1.0.jar ├── freemarker.jar ├── mysql-connector-java-5[1].1.5-bin.jar ├── ojdbc5.jar └── swing2swt.jar ├── plugin.xml ├── screenshot ├── crud-page-a.jpg ├── crud-page-b.jpg └── crud-page-c.jpg ├── src ├── com │ └── thinkgem │ │ └── jeesite │ │ └── autocode │ │ ├── Activator.java │ │ ├── about │ │ └── AboutDialog.java │ │ ├── actions │ │ ├── AboutAction.java │ │ ├── CrudModAction.java │ │ ├── DataSourceAction.java │ │ ├── ReportModAction.java │ │ └── TreeModAction.java │ │ ├── crud │ │ ├── PageOne.java │ │ ├── PageThree.java │ │ ├── PageTwo.java │ │ ├── StartCurdWizard.java │ │ └── template │ │ │ ├── action.ftl │ │ │ ├── edit.ftl │ │ │ ├── entity.ftl │ │ │ ├── hbm.ftl │ │ │ ├── list.ftl │ │ │ ├── qry.ftl │ │ │ ├── service.ftl │ │ │ ├── serviceImpl.ftl │ │ │ ├── struts.ftl │ │ │ └── view.ftl │ │ ├── datasource │ │ ├── DataSourceDailog.java │ │ └── SelectionUpdateValueStrategy.java │ │ ├── model │ │ ├── AbstractModelObject.java │ │ ├── ColumnModel.java │ │ ├── DataSource.java │ │ ├── TableConfigModel.java │ │ └── TableModel.java │ │ ├── ms │ │ ├── PageOne.java │ │ ├── PageThree.java │ │ ├── PageTwo.java │ │ ├── StartMsWizard.java │ │ └── template │ │ │ ├── controller.ftl │ │ │ ├── dao.ftl │ │ │ ├── entity.ftl │ │ │ ├── service.ftl │ │ │ ├── viewForm.ftl │ │ │ └── viewList.ftl │ │ ├── report │ │ ├── PageOne.java │ │ ├── PageThree.java │ │ ├── PageTwo.java │ │ └── StartReportWizard.java │ │ ├── tree │ │ ├── PageOne.java │ │ ├── PageThree.java │ │ ├── PageTwo.java │ │ ├── StartTreeWizard.java │ │ └── template │ │ │ ├── action.ftl │ │ │ ├── edit.ftl │ │ │ ├── entity.ftl │ │ │ ├── hbm.ftl │ │ │ ├── list.ftl │ │ │ ├── qry.ftl │ │ │ ├── service.ftl │ │ │ ├── serviceImpl.ftl │ │ │ ├── struts.ftl │ │ │ └── view.ftl │ │ └── util │ │ ├── AutoCodeDbUtils.java │ │ ├── CharSequenceUtils.java │ │ ├── DbUtils.java │ │ ├── FileUtils.java │ │ ├── FreeMakerUtils.java │ │ ├── GetterSetterUtils.java │ │ ├── SQLFormatter.java │ │ ├── StringUtils.java │ │ ├── XmlObjectCrud.java │ │ ├── XmlObjectReport.java │ │ ├── XmlObjectTree.java │ │ └── XmlObjectUtils.java └── org │ └── eclipse │ └── wb │ └── swt │ ├── ResourceManager.java │ └── SWTResourceManager.java └── swing2swt.jar /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Package Files # 4 | *.war 5 | *.ear 6 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | jeeautocode 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.pde.PluginNature 26 | org.eclipse.jdt.core.javanature 27 | 28 | 29 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Mon May 20 15:30:07 CST 2013 2 | eclipse.preferences.version=1 3 | encoding//src/com/thinkgem/jeesite/autocode/util/FreeMakerUtils.java=UTF-8 4 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Mon May 20 17:41:10 CST 2013 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.5 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.source=1.5 13 | -------------------------------------------------------------------------------- /META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: jeesite autocode 4 | Bundle-SymbolicName: com.thinkgem.jeesite.autocode; singleton:=true 5 | Bundle-Version: 1.0.0.beta 6 | Bundle-Activator: com.thinkgem.jeesite.autocode.Activator 7 | Require-Bundle: org.eclipse.ui, 8 | org.eclipse.core.runtime, 9 | org.eclipse.core.databinding, 10 | org.eclipse.core.databinding.beans, 11 | org.eclipse.core.databinding.observable, 12 | org.eclipse.core.databinding.property, 13 | org.eclipse.jface.databinding, 14 | com.ibm.icu 15 | Bundle-ActivationPolicy: lazy 16 | Bundle-RequiredExecutionEnvironment: J2SE-1.5 17 | Bundle-ClassPath: lib/mysql-connector-java-5[1].1.5-bin.jar, 18 | ., 19 | lib/freemarker.jar, 20 | lib/swing2swt.jar, 21 | lib/blancosqlformatter-0.1.0.jar, 22 | lib/ojdbc5.jar 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 基于eclipse插件的JeeSite框架代码生成器 2 | 3 | 程序安装方法: 4 | 将dist/plugins/com.thinkgem.jeesite.autocode_1.0.0.beta.jar插件文件拷贝至eclipse安装目录下的plugin目录中 5 | 重启eclispe,在菜单栏将看到JEESITE菜单. 6 | 7 | 提供增删改查、报表、树状结构、主从表、excel导入文件功能代码的生成。 8 | 9 | 截屏一: 10 | 11 | 12 | 截屏二: 13 | 14 | -------------------------------------------------------------------------------- /bin/.gitignore: -------------------------------------------------------------------------------- 1 | /com 2 | -------------------------------------------------------------------------------- /bin/com/thinkgem/jeesite/autocode/crud/template/entity.ftl: -------------------------------------------------------------------------------- 1 | package ${table.topPackage}.entity; 2 | 3 | import java.util.Date; 4 | 5 | import com.calf.framework.util.DateUtil; 6 | import com.calf.framework.util.FormateUtil; 7 | 8 | public class ${table.tableJavaName?cap_first} implements java.io.Serializable { 9 | /** 10 | * 11 | */ 12 | private static final long serialVersionUID = 7210248768007789556L; 13 | 14 | <#list columnList as x> 15 | <#if x.key> 16 | /** 17 | * 主键 18 | * <#if x.comment??>${x.comment} 19 | **/ 20 | ${x.javaType} ${x.javaName}; 21 | <#else> 22 | /** 23 | * <#if x.comment??>${x.comment} 24 | **/ 25 | ${x.javaType} ${x.javaName}; 26 | 27 | 28 | 29 | public ${table.tableJavaName?cap_first}(){ 30 | } 31 | 32 | <#list columnList as x> 33 | public ${x.javaType} get${x.javaName?cap_first}(){ 34 | return this.${x.javaName}; 35 | } 36 | public void set${x.javaName?cap_first}(${x.javaType} ${x.javaName}){ 37 | this.${x.javaName} = ${x.javaName}; 38 | } 39 | 40 | 41 | <#list columnList as x> 42 | <#if x.javaType=='Double'> 43 | public String get${x.javaName?cap_first}Str(){ 44 | return FormateUtil.getInstance().formateDouble(this.${x.javaName}); 45 | } 46 | 47 | <#if x.javaType=='Date'> 48 | public String get${x.javaName?cap_first}Str(){ 49 | return DateUtil.getInstance().dateToString(this.${x.javaName},DateUtil.patternA); 50 | } 51 | 52 | 53 | 54 | <#list columnList as x> 55 | <#if x.dictKey!=""> 56 | public String get${x.javaName?cap_first}Str(){ 57 | return FormateUtil.getInstance().getNameByCode("${x.dictKey}", ${x.javaName}); 58 | } 59 | 60 | 61 | 62 | public boolean isCanDelete(){ 63 | return "1".equals(this.dataStatus); 64 | } 65 | } -------------------------------------------------------------------------------- /bin/com/thinkgem/jeesite/autocode/crud/template/service.ftl: -------------------------------------------------------------------------------- 1 | package ${table.topPackage}.services; 2 | 3 | import java.util.List; 4 | 5 | import com.calf.framework.services.BaseService; 6 | import ${table.topPackage}.entity.${table.tableJavaName?cap_first}; 7 | import ${table.topPackage}.qry.${table.functionNameEn?cap_first}Qry; 8 | import com.calf.framework.vo.Page; 9 | 10 | public interface ${table.functionNameEn?cap_first}Service extends BaseService{ 11 | /** 12 | * 保存 13 | **/ 14 | public String save${table.functionNameEn?cap_first}(${table.tableJavaName?cap_first} entity); 15 | /** 16 | * 删除 17 | */ 18 | public String delete${table.functionNameEn?cap_first}(${table.tableJavaName?cap_first} entity); 19 | /** 20 | * 查找分页信息 21 | */ 22 | public Page find${table.functionNameEn?cap_first}Page(${table.functionNameEn?cap_first}Qry qry); 23 | 24 | /** 25 | * 判断编码是否唯一 26 | * @return 27 | */ 28 | public boolean isUnique(${table.key.javaType} ${table.key.javaName}); 29 | } -------------------------------------------------------------------------------- /build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/ 2 | output.. = bin/ 3 | bin.includes = plugin.xml,\ 4 | META-INF/,\ 5 | .,\ 6 | icons/,\ 7 | lib/,\ 8 | lib/blancosqlformatter-0.1.0.jar,\ 9 | lib/ojdbc5.jar 10 | -------------------------------------------------------------------------------- /dist/plugins/com.thinkgem.jeesite.autocode_1.0.0.beta.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thinkgem/jeesite_autocode/485b381db107e63aa1341a8a5d2b6489b162e791/dist/plugins/com.thinkgem.jeesite.autocode_1.0.0.beta.jar -------------------------------------------------------------------------------- /icons/about.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thinkgem/jeesite_autocode/485b381db107e63aa1341a8a5d2b6489b162e791/icons/about.png -------------------------------------------------------------------------------- /icons/checked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thinkgem/jeesite_autocode/485b381db107e63aa1341a8a5d2b6489b162e791/icons/checked.png -------------------------------------------------------------------------------- /icons/curd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thinkgem/jeesite_autocode/485b381db107e63aa1341a8a5d2b6489b162e791/icons/curd.png -------------------------------------------------------------------------------- /icons/database.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thinkgem/jeesite_autocode/485b381db107e63aa1341a8a5d2b6489b162e791/icons/database.png -------------------------------------------------------------------------------- /icons/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thinkgem/jeesite_autocode/485b381db107e63aa1341a8a5d2b6489b162e791/icons/down.png -------------------------------------------------------------------------------- /icons/report.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thinkgem/jeesite_autocode/485b381db107e63aa1341a8a5d2b6489b162e791/icons/report.png -------------------------------------------------------------------------------- /icons/tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thinkgem/jeesite_autocode/485b381db107e63aa1341a8a5d2b6489b162e791/icons/tree.png -------------------------------------------------------------------------------- /icons/unchecked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thinkgem/jeesite_autocode/485b381db107e63aa1341a8a5d2b6489b162e791/icons/unchecked.png -------------------------------------------------------------------------------- /icons/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thinkgem/jeesite_autocode/485b381db107e63aa1341a8a5d2b6489b162e791/icons/up.png -------------------------------------------------------------------------------- /lib/blancosqlformatter-0.1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thinkgem/jeesite_autocode/485b381db107e63aa1341a8a5d2b6489b162e791/lib/blancosqlformatter-0.1.0.jar -------------------------------------------------------------------------------- /lib/freemarker.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thinkgem/jeesite_autocode/485b381db107e63aa1341a8a5d2b6489b162e791/lib/freemarker.jar -------------------------------------------------------------------------------- /lib/mysql-connector-java-5[1].1.5-bin.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thinkgem/jeesite_autocode/485b381db107e63aa1341a8a5d2b6489b162e791/lib/mysql-connector-java-5[1].1.5-bin.jar -------------------------------------------------------------------------------- /lib/ojdbc5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thinkgem/jeesite_autocode/485b381db107e63aa1341a8a5d2b6489b162e791/lib/ojdbc5.jar -------------------------------------------------------------------------------- /lib/swing2swt.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thinkgem/jeesite_autocode/485b381db107e63aa1341a8a5d2b6489b162e791/lib/swing2swt.jar -------------------------------------------------------------------------------- /plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 11 | 14 | 16 | 17 | 18 | 24 | 25 | 32 | 33 | 40 | 41 | 49 | 50 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /screenshot/crud-page-a.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thinkgem/jeesite_autocode/485b381db107e63aa1341a8a5d2b6489b162e791/screenshot/crud-page-a.jpg -------------------------------------------------------------------------------- /screenshot/crud-page-b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thinkgem/jeesite_autocode/485b381db107e63aa1341a8a5d2b6489b162e791/screenshot/crud-page-b.jpg -------------------------------------------------------------------------------- /screenshot/crud-page-c.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thinkgem/jeesite_autocode/485b381db107e63aa1341a8a5d2b6489b162e791/screenshot/crud-page-c.jpg -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/Activator.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.net.URL; 6 | 7 | import org.eclipse.jface.resource.ImageDescriptor; 8 | import org.eclipse.ui.plugin.AbstractUIPlugin; 9 | import org.osgi.framework.BundleContext; 10 | 11 | import com.thinkgem.jeesite.autocode.crud.StartCurdWizard; 12 | import com.thinkgem.jeesite.autocode.tree.StartTreeWizard; 13 | import com.thinkgem.jeesite.autocode.util.FileUtils; 14 | import com.thinkgem.jeesite.autocode.util.XmlObjectCrud; 15 | 16 | /** 17 | * The activator class controls the plug-in life cycle 18 | */ 19 | public class Activator extends AbstractUIPlugin { 20 | 21 | // The plug-in ID 22 | public static final String PLUGIN_ID = "com.thinkgem.jeesite.autocode"; //$NON-NLS-1$ 23 | 24 | // The shared instance 25 | private static Activator plugin; 26 | 27 | /** 28 | * The constructor 29 | */ 30 | public Activator() { 31 | } 32 | 33 | /* 34 | * (non-Javadoc) 35 | * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) 36 | */ 37 | public void start(BundleContext context) throws Exception { 38 | super.start(context); 39 | plugin = this; 40 | initFtlFile(); 41 | } 42 | 43 | /* 44 | * (non-Javadoc) 45 | * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) 46 | */ 47 | public void stop(BundleContext context) throws Exception { 48 | plugin = null; 49 | super.stop(context); 50 | } 51 | 52 | /** 53 | * Returns the shared instance 54 | * 55 | * @return the shared instance 56 | */ 57 | public static Activator getDefault() { 58 | return plugin; 59 | } 60 | 61 | /** 62 | * Returns an image descriptor for the image file at the given 63 | * plug-in relative path 64 | * 65 | * @param path the path 66 | * @return the image descriptor 67 | */ 68 | public static ImageDescriptor getImageDescriptor(String path) { 69 | return imageDescriptorFromPlugin(PLUGIN_ID, path); 70 | } 71 | 72 | private void initFtlFile(){ 73 | copyCrudFtl(); 74 | //copyTreeFtl(); 75 | } 76 | 77 | /** 78 | * 拷贝增删查改结构生成配置 79 | */ 80 | private void copyCrudFtl(){ 81 | String ftlPath = XmlObjectCrud.getFtlPath(); 82 | //copyCrudFtlSingle(ftlPath,"controller.ftl"); 83 | //copyCrudFtlSingle(ftlPath,"dao.ftl"); 84 | copyCrudFtlSingle(ftlPath,"entity.ftl"); 85 | //copyCrudFtlSingle(ftlPath,"service.ftl"); 86 | //copyCrudFtlSingle(ftlPath,"viewForm.ftl"); 87 | //copyCrudFtlSingle(ftlPath,"viewList.ftl"); 88 | } 89 | 90 | private void copyCrudFtlSingle(String ftlPath,String fileName){ 91 | URL from = StartCurdWizard.class.getResource("template\\"+fileName); 92 | File dist = new File(ftlPath+"\\"+fileName); 93 | if(!dist.exists()){ 94 | try { 95 | FileUtils.copyURLToFile(from, dist); 96 | } catch (IOException e) { 97 | e.printStackTrace(); 98 | } 99 | } 100 | } 101 | 102 | /** 103 | * 拷贝树形结构生成配置 104 | */ 105 | private void copyTreeFtl(){ 106 | String ftlPath = XmlObjectCrud.getFtlPath(); 107 | copyTreeFtlSingle(ftlPath,"controller.ftl"); 108 | copyTreeFtlSingle(ftlPath,"dao.ftl"); 109 | copyTreeFtlSingle(ftlPath,"entity.ftl"); 110 | copyTreeFtlSingle(ftlPath,"service.ftl"); 111 | copyTreeFtlSingle(ftlPath,"viewForm.ftl"); 112 | copyTreeFtlSingle(ftlPath,"viewList.ftl"); 113 | } 114 | 115 | private void copyTreeFtlSingle(String ftlPath,String fileName){ 116 | URL from = StartTreeWizard.class.getResource("template\\"+fileName); 117 | File dist = new File(ftlPath+"\\"+fileName); 118 | if(!dist.exists()){ 119 | try { 120 | FileUtils.copyURLToFile(from, dist); 121 | } catch (IOException e) { 122 | e.printStackTrace(); 123 | } 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/about/AboutDialog.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.about; 2 | 3 | import org.eclipse.jface.dialogs.IDialogConstants; 4 | import org.eclipse.jface.dialogs.TitleAreaDialog; 5 | import org.eclipse.swt.SWT; 6 | import org.eclipse.swt.graphics.Point; 7 | import org.eclipse.swt.layout.GridData; 8 | import org.eclipse.swt.widgets.Composite; 9 | import org.eclipse.swt.widgets.Control; 10 | import org.eclipse.swt.widgets.Shell; 11 | import org.eclipse.swt.layout.GridLayout; 12 | import org.eclipse.swt.widgets.Label; 13 | import org.eclipse.swt.layout.FillLayout; 14 | import org.eclipse.swt.widgets.Text; 15 | import org.eclipse.wb.swt.SWTResourceManager; 16 | 17 | public class AboutDialog extends TitleAreaDialog { 18 | private Text txtSdfdSdfs; 19 | 20 | /** 21 | * Create the dialog. 22 | * @param parentShell 23 | */ 24 | public AboutDialog(Shell parentShell) { 25 | super(parentShell); 26 | } 27 | 28 | /** 29 | * Create contents of the dialog. 30 | * @param parent 31 | */ 32 | @Override 33 | protected Control createDialogArea(Composite parent) { 34 | setMessage("Version: v0.8.1.beta"); 35 | setTitle("JEESITE代码生成器"); 36 | Composite area = (Composite) super.createDialogArea(parent); 37 | Composite container = new Composite(area, SWT.NONE); 38 | container.setLayout(new FillLayout(SWT.VERTICAL)); 39 | container.setLayoutData(new GridData(GridData.FILL_BOTH)); 40 | 41 | Composite composite = new Composite(container, SWT.BORDER); 42 | composite.setLayout(new GridLayout(1, false)); 43 | 44 | txtSdfdSdfs = new Text(composite, SWT.BORDER | SWT.READ_ONLY | SWT.MULTI); 45 | txtSdfdSdfs.setEditable(false); 46 | txtSdfdSdfs.setBackground(SWTResourceManager.getColor(240,240,240)); 47 | txtSdfdSdfs.setText("代码生成器,希望能节约大家重复编码的时间\r\n\r\n本代码生成器生成的代码基于jeesite基础开发框架,jeesite开发框架是快速、安全、高效的开发框架。\r\n\r\n本代码生成器只是简单的代码生成功能,更复杂的功能,请您使用过程中提出,以便完善\r\n\r\n如果您有好的建议:请EMAIL: someday_122@qq.com"); 48 | GridData gd_txtSdfdSdfs = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); 49 | gd_txtSdfdSdfs.heightHint = 139; 50 | txtSdfdSdfs.setLayoutData(gd_txtSdfdSdfs); 51 | 52 | Composite composite_1 = new Composite(container, SWT.BORDER); 53 | composite_1.setLayout(new GridLayout(3, false)); 54 | new Label(composite_1, SWT.NONE); 55 | 56 | Label label = new Label(composite_1, SWT.NONE); 57 | label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); 58 | label.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.BOLD)); 59 | label.setText("设计:"); 60 | 61 | Label lblgitlikewindmanemailsomedayqqcom = new Label(composite_1, SWT.NONE); 62 | lblgitlikewindmanemailsomedayqqcom.setText("git account: likewindman EMAIL: someday_122@qq.com"); 63 | new Label(composite_1, SWT.NONE); 64 | 65 | Label lblEmail = new Label(composite_1, SWT.NONE); 66 | lblEmail.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); 67 | lblEmail.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.BOLD)); 68 | lblEmail.setText("编码:"); 69 | 70 | Label lblNewLabel = new Label(composite_1, SWT.NONE); 71 | lblNewLabel.setText("风一样的男子"); 72 | new Label(composite_1, SWT.NONE); 73 | 74 | Label label_2 = new Label(composite_1, SWT.NONE); 75 | label_2.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.BOLD)); 76 | label_2.setText("模板编制:"); 77 | 78 | Label lblJeesite = new Label(composite_1, SWT.NONE); 79 | new Label(composite_1, SWT.NONE); 80 | 81 | Label label_3 = new Label(composite_1, SWT.NONE); 82 | new Label(composite_1, SWT.NONE); 83 | 84 | return area; 85 | } 86 | 87 | /** 88 | * Create contents of the button bar. 89 | * @param parent 90 | */ 91 | @Override 92 | protected void createButtonsForButtonBar(Composite parent) { 93 | createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, 94 | true); 95 | createButton(parent, IDialogConstants.CANCEL_ID, 96 | IDialogConstants.CANCEL_LABEL, false); 97 | } 98 | 99 | /** 100 | * Return the initial size of the dialog. 101 | */ 102 | @Override 103 | protected Point getInitialSize() { 104 | return new Point(578, 450); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/actions/AboutAction.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.actions; 2 | 3 | import org.eclipse.jface.action.IAction; 4 | import org.eclipse.jface.viewers.ISelection; 5 | import org.eclipse.ui.IWorkbenchWindow; 6 | import org.eclipse.ui.IWorkbenchWindowActionDelegate; 7 | 8 | import com.thinkgem.jeesite.autocode.about.AboutDialog; 9 | 10 | /** 11 | * 弹出帮助ACTION 12 | * 13 | */ 14 | public class AboutAction implements IWorkbenchWindowActionDelegate { 15 | private IWorkbenchWindow window; 16 | 17 | public void run(IAction action) { 18 | AboutDialog dialog = new AboutDialog(window.getShell()); 19 | dialog.create(); 20 | dialog.open(); 21 | } 22 | 23 | public void selectionChanged(IAction action, ISelection selection) { 24 | 25 | } 26 | 27 | public void dispose() { 28 | 29 | } 30 | 31 | /** 32 | * We will cache window object in order to 33 | * be able to provide parent shell for the message dialog. 34 | * @see IWorkbenchWindowActionDelegate#init 35 | */ 36 | public void init(IWorkbenchWindow window) { 37 | this.window = window; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/actions/CrudModAction.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.actions; 2 | 3 | import org.eclipse.jface.action.IAction; 4 | import org.eclipse.jface.viewers.ISelection; 5 | import org.eclipse.jface.wizard.WizardDialog; 6 | import org.eclipse.ui.IWorkbenchWindow; 7 | import org.eclipse.ui.IWorkbenchWindowActionDelegate; 8 | 9 | import com.thinkgem.jeesite.autocode.crud.StartCurdWizard; 10 | 11 | /** 12 | * Our sample action implements workbench action delegate. 13 | * The action proxy will be created by the workbench and 14 | * shown in the UI. When the user tries to use the action, 15 | * this delegate will be created and execution will be 16 | * delegated to it. 17 | * @see IWorkbenchWindowActionDelegate 18 | */ 19 | public class CrudModAction implements IWorkbenchWindowActionDelegate { 20 | private IWorkbenchWindow window; 21 | 22 | /** 23 | * The constructor. 24 | */ 25 | public CrudModAction() { 26 | 27 | } 28 | 29 | /** 30 | * The action has been activated. The argument of the 31 | * method represents the 'real' action sitting 32 | * in the workbench UI. 33 | * @see IWorkbenchWindowActionDelegate#run 34 | */ 35 | public void run(IAction action) { 36 | StartCurdWizard wizard = new StartCurdWizard(); 37 | WizardDialog dialog = new WizardDialog(window.getShell(), wizard); 38 | dialog.create(); 39 | dialog.open(); 40 | } 41 | 42 | /** 43 | * Selection in the workbench has been changed. We 44 | * can change the state of the 'real' action here 45 | * if we want, but this can only happen after 46 | * the delegate has been created. 47 | * @see IWorkbenchWindowActionDelegate#selectionChanged 48 | */ 49 | public void selectionChanged(IAction action, ISelection selection) { 50 | } 51 | 52 | /** 53 | * We can use this method to dispose of any system 54 | * resources we previously allocated. 55 | * @see IWorkbenchWindowActionDelegate#dispose 56 | */ 57 | public void dispose() { 58 | } 59 | 60 | /** 61 | * We will cache window object in order to 62 | * be able to provide parent shell for the message dialog. 63 | * @see IWorkbenchWindowActionDelegate#init 64 | */ 65 | public void init(IWorkbenchWindow window) { 66 | this.window = window; 67 | } 68 | } -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/actions/DataSourceAction.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.actions; 2 | 3 | import org.eclipse.jface.action.IAction; 4 | import org.eclipse.jface.viewers.ISelection; 5 | import org.eclipse.ui.IWorkbenchWindow; 6 | import org.eclipse.ui.IWorkbenchWindowActionDelegate; 7 | 8 | import com.thinkgem.jeesite.autocode.datasource.DataSourceDailog; 9 | 10 | /** 11 | * 数据源管理 12 | * 13 | */ 14 | public class DataSourceAction implements IWorkbenchWindowActionDelegate { 15 | private IWorkbenchWindow window; 16 | 17 | /** 18 | * The constructor. 19 | */ 20 | public DataSourceAction() { 21 | 22 | } 23 | 24 | /** 25 | * The action has been activated. The argument of the 26 | * method represents the 'real' action sitting 27 | * in the workbench UI. 28 | * @see IWorkbenchWindowActionDelegate#run 29 | */ 30 | public void run(IAction action) { 31 | DataSourceDailog dialog = new DataSourceDailog(window.getShell()); 32 | dialog.create(); 33 | dialog.open(); 34 | } 35 | 36 | /** 37 | * Selection in the workbench has been changed. We 38 | * can change the state of the 'real' action here 39 | * if we want, but this can only happen after 40 | * the delegate has been created. 41 | * @see IWorkbenchWindowActionDelegate#selectionChanged 42 | */ 43 | public void selectionChanged(IAction action, ISelection selection) { 44 | } 45 | 46 | /** 47 | * We can use this method to dispose of any system 48 | * resources we previously allocated. 49 | * @see IWorkbenchWindowActionDelegate#dispose 50 | */ 51 | public void dispose() { 52 | } 53 | 54 | /** 55 | * We will cache window object in order to 56 | * be able to provide parent shell for the message dialog. 57 | * @see IWorkbenchWindowActionDelegate#init 58 | */ 59 | public void init(IWorkbenchWindow window) { 60 | this.window = window; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/actions/ReportModAction.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.actions; 2 | 3 | import org.eclipse.jface.action.IAction; 4 | import org.eclipse.jface.viewers.ISelection; 5 | import org.eclipse.jface.wizard.WizardDialog; 6 | import org.eclipse.ui.IWorkbenchWindow; 7 | import org.eclipse.ui.IWorkbenchWindowActionDelegate; 8 | 9 | import com.thinkgem.jeesite.autocode.report.StartReportWizard; 10 | 11 | /** 12 | * Our sample action implements workbench action delegate. 13 | * The action proxy will be created by the workbench and 14 | * shown in the UI. When the user tries to use the action, 15 | * this delegate will be created and execution will be 16 | * delegated to it. 17 | * @see IWorkbenchWindowActionDelegate 18 | */ 19 | public class ReportModAction implements IWorkbenchWindowActionDelegate { 20 | private IWorkbenchWindow window; 21 | 22 | /** 23 | * The constructor. 24 | */ 25 | public ReportModAction() { 26 | 27 | } 28 | 29 | /** 30 | * The action has been activated. The argument of the 31 | * method represents the 'real' action sitting 32 | * in the workbench UI. 33 | * @see IWorkbenchWindowActionDelegate#run 34 | */ 35 | public void run(IAction action) { 36 | StartReportWizard wizard = new StartReportWizard(); 37 | WizardDialog dialog = new WizardDialog(window.getShell(), wizard); 38 | dialog.create(); 39 | dialog.open(); 40 | } 41 | 42 | /** 43 | * Selection in the workbench has been changed. We 44 | * can change the state of the 'real' action here 45 | * if we want, but this can only happen after 46 | * the delegate has been created. 47 | * @see IWorkbenchWindowActionDelegate#selectionChanged 48 | */ 49 | public void selectionChanged(IAction action, ISelection selection) { 50 | } 51 | 52 | /** 53 | * We can use this method to dispose of any system 54 | * resources we previously allocated. 55 | * @see IWorkbenchWindowActionDelegate#dispose 56 | */ 57 | public void dispose() { 58 | } 59 | 60 | /** 61 | * We will cache window object in order to 62 | * be able to provide parent shell for the message dialog. 63 | * @see IWorkbenchWindowActionDelegate#init 64 | */ 65 | public void init(IWorkbenchWindow window) { 66 | this.window = window; 67 | } 68 | } -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/actions/TreeModAction.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.actions; 2 | 3 | import org.eclipse.jface.action.IAction; 4 | import org.eclipse.jface.viewers.ISelection; 5 | import org.eclipse.jface.wizard.WizardDialog; 6 | import org.eclipse.ui.IWorkbenchWindow; 7 | import org.eclipse.ui.IWorkbenchWindowActionDelegate; 8 | import com.thinkgem.jeesite.autocode.tree.StartTreeWizard; 9 | 10 | /** 11 | * Our sample action implements workbench action delegate. 12 | * The action proxy will be created by the workbench and 13 | * shown in the UI. When the user tries to use the action, 14 | * this delegate will be created and execution will be 15 | * delegated to it. 16 | * @see IWorkbenchWindowActionDelegate 17 | */ 18 | public class TreeModAction implements IWorkbenchWindowActionDelegate { 19 | private IWorkbenchWindow window; 20 | 21 | /** 22 | * The constructor. 23 | */ 24 | public TreeModAction() { 25 | 26 | } 27 | 28 | /** 29 | * The action has been activated. The argument of the 30 | * method represents the 'real' action sitting 31 | * in the workbench UI. 32 | * @see IWorkbenchWindowActionDelegate#run 33 | */ 34 | public void run(IAction action) { 35 | StartTreeWizard wizard = new StartTreeWizard(); 36 | WizardDialog dialog = new WizardDialog(window.getShell(), wizard); 37 | dialog.create(); 38 | dialog.open(); 39 | } 40 | 41 | /** 42 | * Selection in the workbench has been changed. We 43 | * can change the state of the 'real' action here 44 | * if we want, but this can only happen after 45 | * the delegate has been created. 46 | * @see IWorkbenchWindowActionDelegate#selectionChanged 47 | */ 48 | public void selectionChanged(IAction action, ISelection selection) { 49 | } 50 | 51 | /** 52 | * We can use this method to dispose of any system 53 | * resources we previously allocated. 54 | * @see IWorkbenchWindowActionDelegate#dispose 55 | */ 56 | public void dispose() { 57 | } 58 | 59 | /** 60 | * We will cache window object in order to 61 | * be able to provide parent shell for the message dialog. 62 | * @see IWorkbenchWindowActionDelegate#init 63 | */ 64 | public void init(IWorkbenchWindow window) { 65 | this.window = window; 66 | } 67 | } -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/crud/PageOne.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.crud; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.eclipse.core.databinding.DataBindingContext; 6 | import org.eclipse.core.databinding.beans.BeansObservables; 7 | import org.eclipse.core.databinding.observable.list.WritableList; 8 | import org.eclipse.core.databinding.observable.map.IObservableMap; 9 | import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; 10 | import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; 11 | import org.eclipse.jface.viewers.IStructuredSelection; 12 | import org.eclipse.jface.viewers.TableViewer; 13 | import org.eclipse.jface.wizard.IWizardPage; 14 | import org.eclipse.jface.wizard.WizardPage; 15 | import org.eclipse.swt.SWT; 16 | import org.eclipse.swt.custom.SashForm; 17 | import org.eclipse.swt.events.SelectionAdapter; 18 | import org.eclipse.swt.events.SelectionEvent; 19 | import org.eclipse.swt.layout.FillLayout; 20 | import org.eclipse.swt.layout.GridData; 21 | import org.eclipse.swt.layout.GridLayout; 22 | import org.eclipse.swt.widgets.Composite; 23 | import org.eclipse.swt.widgets.Label; 24 | import org.eclipse.swt.widgets.List; 25 | import org.eclipse.swt.widgets.Table; 26 | import org.eclipse.swt.widgets.TableColumn; 27 | import org.eclipse.wb.swt.SWTResourceManager; 28 | 29 | import com.thinkgem.jeesite.autocode.model.DataSource; 30 | import com.thinkgem.jeesite.autocode.model.TableModel; 31 | import com.thinkgem.jeesite.autocode.util.AutoCodeDbUtils; 32 | import com.thinkgem.jeesite.autocode.util.XmlObjectCrud; 33 | import com.thinkgem.jeesite.autocode.util.XmlObjectUtils; 34 | 35 | public class PageOne extends WizardPage { 36 | private DataBindingContext m_bindingContext; 37 | private Table table; 38 | 39 | private java.util.List dataSourceList = new ArrayList(); 40 | 41 | /* 42 | * 表LIST 43 | */ 44 | private java.util.List tableList = new ArrayList(); 45 | 46 | private List connList = null; 47 | 48 | private TableViewer tableViewer; 49 | 50 | private DataSource ds; 51 | 52 | private void updateButtons(){ 53 | getWizard().getContainer().updateButtons(); 54 | } 55 | 56 | /** 57 | * Create the wizard. 58 | */ 59 | public PageOne() { 60 | super("PageOne"); 61 | setTitle("选择数据连接"); 62 | setDescription("请选择数据库连接,模板文件位于:"+XmlObjectCrud.getFtlPath()); 63 | } 64 | 65 | /** 66 | * Create contents of the wizard. 67 | * @param parent 68 | */ 69 | public void createControl(Composite parent) { 70 | Composite container = new Composite(parent, SWT.NULL); 71 | 72 | setControl(container); 73 | container.setLayout(new FillLayout(SWT.HORIZONTAL)); 74 | 75 | SashForm sashForm = new SashForm(container, SWT.NONE); 76 | 77 | Composite composite = new Composite(sashForm, SWT.BORDER); 78 | composite.setLayout(new GridLayout(1, false)); 79 | 80 | Label lblNewLabel = new Label(composite, SWT.SHADOW_NONE | SWT.CENTER); 81 | lblNewLabel.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.BOLD)); 82 | lblNewLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 83 | lblNewLabel.setText("选择数据源"); 84 | 85 | connList = new List(composite, SWT.BORDER); 86 | connList.addSelectionListener(new SelectionAdapter() { 87 | @Override 88 | public void widgetSelected(SelectionEvent e) { 89 | //更新表列表 90 | ds = (DataSource)dataSourceList.get(connList.getSelectionIndex()); 91 | tableList.clear(); 92 | java.util.List tmList = AutoCodeDbUtils.getTableList(ds); 93 | for(TableModel tm:tmList){ 94 | tableList.add(tm); 95 | } 96 | tableViewer.refresh(); 97 | m_bindingContext.updateModels(); 98 | updateButtons(); 99 | } 100 | }); 101 | GridData gd_connList = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); 102 | gd_connList.heightHint = 400; 103 | connList.setLayoutData(gd_connList); 104 | 105 | Composite composite_1 = new Composite(sashForm, SWT.BORDER); 106 | composite_1.setLayout(new GridLayout(1, false)); 107 | 108 | Label lblNewLabel_1 = new Label(composite_1, SWT.HORIZONTAL); 109 | lblNewLabel_1.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1)); 110 | lblNewLabel_1.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.BOLD)); 111 | lblNewLabel_1.setText("选择表名"); 112 | 113 | tableViewer = new TableViewer(composite_1, SWT.BORDER | SWT.FULL_SELECTION); 114 | table = tableViewer.getTable(); 115 | table.addSelectionListener(new SelectionAdapter() { 116 | @Override 117 | public void widgetSelected(SelectionEvent e) { 118 | IStructuredSelection select = (IStructuredSelection)tableViewer.getSelection(); 119 | TableModel tm = (TableModel)select.getFirstElement(); 120 | setWizardTm(tm); 121 | updateButtons(); 122 | } 123 | }); 124 | table.setLinesVisible(true); 125 | table.setHeaderVisible(true); 126 | table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); 127 | 128 | TableColumn tblclmnNewColumn = new TableColumn(table, SWT.NONE); 129 | tblclmnNewColumn.setWidth(190); 130 | tblclmnNewColumn.setText("表名"); 131 | 132 | TableColumn tblclmnNewColumn_1 = new TableColumn(table, SWT.NONE); 133 | tblclmnNewColumn_1.setWidth(168); 134 | tblclmnNewColumn_1.setText("中文名称"); 135 | 136 | 137 | java.util.List tmp = (java.util.List)XmlObjectUtils.objectXmlDecoder(XmlObjectUtils.getDataSourceFileName()); 138 | if(tmp != null){ 139 | dataSourceList = tmp; 140 | } 141 | 142 | String[] connItems = new String[dataSourceList.size()]; 143 | for (int i = 0; i < dataSourceList.size(); i++) { 144 | DataSource ds = (DataSource) dataSourceList.get(i); 145 | connItems[i] = ds.getName(); 146 | } 147 | connList.setItems(connItems); 148 | sashForm.setWeights(new int[] {206, 427}); 149 | 150 | m_bindingContext = initDataBindings(); 151 | 152 | TableModel m = new TableModel(); 153 | m.setName("table"); 154 | m.setComment("comment"); 155 | tableList.add(m); 156 | 157 | } 158 | 159 | private void setWizardTm(TableModel tm){ 160 | StartCurdWizard wizard = (StartCurdWizard)super.getWizard(); 161 | wizard.setTableModel(tm.getName(), tm.getComment()); 162 | 163 | //设置表信息 164 | PageTwo pageTwo = (PageTwo)wizard.getPage("PageTwo"); 165 | pageTwo.onEnterPage(tm.getName(), tm.getComment()); 166 | 167 | //设置列信息 168 | PageThree pageThree = (PageThree)wizard.getPage("PageThree"); 169 | pageThree.onEnterPage(); 170 | } 171 | 172 | protected DataBindingContext initDataBindings() { 173 | DataBindingContext bindingContext = new DataBindingContext(); 174 | 175 | // 176 | ObservableListContentProvider listContentProvider = new ObservableListContentProvider(); 177 | IObservableMap[] observeMaps = BeansObservables.observeMaps(listContentProvider.getKnownElements(), TableModel.class, new String[]{"name", "comment"}); 178 | tableViewer.setLabelProvider(new ObservableMapLabelProvider(observeMaps)); 179 | tableViewer.setContentProvider(listContentProvider); 180 | // 181 | WritableList writableList = new WritableList(tableList, TableModel.class); 182 | tableViewer.setInput(writableList); 183 | // 184 | return bindingContext; 185 | } 186 | 187 | @Override 188 | public IWizardPage getNextPage() { 189 | return super.getNextPage(); 190 | } 191 | 192 | @Override 193 | public boolean canFlipToNextPage() { 194 | if (getErrorMessage() != null) return false; 195 | if(!tableViewer.getSelection().isEmpty()) { 196 | return true; 197 | } 198 | return false; 199 | } 200 | 201 | public DataSource getDs() { 202 | return ds; 203 | } 204 | 205 | } 206 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/crud/PageThree.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.crud; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | import org.eclipse.jface.resource.ImageRegistry; 8 | import org.eclipse.jface.viewers.CellEditor; 9 | import org.eclipse.jface.viewers.CheckboxCellEditor; 10 | import org.eclipse.jface.viewers.ICellModifier; 11 | import org.eclipse.jface.viewers.IStructuredContentProvider; 12 | import org.eclipse.jface.viewers.ITableLabelProvider; 13 | import org.eclipse.jface.viewers.LabelProvider; 14 | import org.eclipse.jface.viewers.TableViewer; 15 | import org.eclipse.jface.viewers.TextCellEditor; 16 | import org.eclipse.jface.viewers.Viewer; 17 | import org.eclipse.jface.wizard.WizardPage; 18 | import org.eclipse.swt.SWT; 19 | import org.eclipse.swt.graphics.Image; 20 | import org.eclipse.swt.layout.GridData; 21 | import org.eclipse.swt.layout.GridLayout; 22 | import org.eclipse.swt.widgets.Composite; 23 | import org.eclipse.swt.widgets.Table; 24 | import org.eclipse.swt.widgets.TableColumn; 25 | import org.eclipse.swt.widgets.TableItem; 26 | import org.eclipse.swt.widgets.ToolBar; 27 | import org.eclipse.swt.widgets.ToolItem; 28 | import org.eclipse.wb.swt.ResourceManager; 29 | 30 | import swing2swt.layout.BorderLayout; 31 | 32 | import com.thinkgem.jeesite.autocode.model.ColumnModel; 33 | import com.thinkgem.jeesite.autocode.model.TableModel; 34 | import com.thinkgem.jeesite.autocode.util.AutoCodeDbUtils; 35 | import com.thinkgem.jeesite.autocode.util.StringUtils; 36 | 37 | public class PageThree extends WizardPage { 38 | private Table columnsTable; 39 | 40 | /** 41 | * 列信息 42 | */ 43 | List columnList = new ArrayList(); 44 | 45 | private TableViewer tableViewer; 46 | 47 | private String[] columnNames = new String[] {"columnName", "javaName", "javaType", "isNull", "isQuery", "isList", "isEdit", "comment", "dictKey"}; 48 | 49 | /** 50 | * Create the wizard. 51 | */ 52 | public PageThree() { 53 | super("PageThree"); 54 | setTitle("设置字段信息"); 55 | setDescription("设置字段信息"); 56 | } 57 | 58 | public TableViewer getTableViewer() { 59 | return tableViewer; 60 | } 61 | 62 | public List getColumnList() { 63 | return columnList; 64 | } 65 | 66 | /** 67 | * Create contents of the wizard. 68 | * 69 | * @param parent 70 | */ 71 | public void createControl(Composite parent) { 72 | Composite container = new Composite(parent, SWT.NULL); 73 | 74 | setControl(container); 75 | container.setLayout(new BorderLayout(3, 0)); 76 | 77 | Composite composite = new Composite(container, SWT.BORDER); 78 | composite.setLayoutData(BorderLayout.EAST); 79 | composite.setLayout(new GridLayout(1, false)); 80 | 81 | ToolBar toolBar = new ToolBar(composite, SWT.FLAT | SWT.RIGHT 82 | | SWT.VERTICAL); 83 | 84 | ToolItem tbiUp = new ToolItem(toolBar, SWT.NONE); 85 | tbiUp.setImage(ResourceManager.getPluginImage( 86 | "com.thinkgem.jeesite.autocode", "icons/up.png")); 87 | 88 | ToolItem tbiDown = new ToolItem(toolBar, SWT.NONE); 89 | tbiDown.setImage(ResourceManager.getPluginImage( 90 | "com.thinkgem.jeesite.autocode", "icons/down.png")); 91 | 92 | Composite composite_1 = new Composite(container, SWT.BORDER); 93 | composite_1.setLayoutData(BorderLayout.CENTER); 94 | composite_1.setLayout(new GridLayout(1, false)); 95 | 96 | tableViewer = new TableViewer(composite_1, SWT.BORDER 97 | | SWT.FULL_SELECTION); 98 | tableViewer.setColumnProperties(columnNames); 99 | columnsTable = tableViewer.getTable(); 100 | columnsTable.setHeaderVisible(true); 101 | columnsTable.setLinesVisible(true); 102 | columnsTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 103 | 1, 1)); 104 | 105 | TableColumn tc1 = new TableColumn(columnsTable, SWT.CENTER, 0); 106 | tc1.setText("列名"); //$NON-NLS-1$ 107 | TableColumn tc2 = new TableColumn(columnsTable, SWT.CENTER, 1); 108 | tc2.setText("属性名"); //$NON-NLS-1$ 109 | TableColumn tc3 = new TableColumn(columnsTable, SWT.LEFT, 2); 110 | tc3.setText("说明"); //$NON-NLS-1$ 111 | TableColumn tc4 = new TableColumn(columnsTable, SWT.CENTER, 3); 112 | tc4.setText("主键"); //$NON-NLS-1$ 113 | TableColumn tc5 = new TableColumn(columnsTable, SWT.CENTER, 4); 114 | tc5.setText("列表"); //$NON-NLS-1$ 115 | TableColumn tc6 = new TableColumn(columnsTable, SWT.CENTER, 5); 116 | tc6.setText("查询"); //$NON-NLS-1$ 117 | TableColumn tc7 = new TableColumn(columnsTable, SWT.CENTER, 6); 118 | tc7.setText("修改"); //$NON-NLS-1$ 119 | TableColumn tc8 = new TableColumn(columnsTable, SWT.CENTER, 7); 120 | tc8.setText("参数"); //$NON-NLS-1$ 121 | 122 | tc1.setWidth(140); 123 | tc2.setWidth(90); 124 | tc3.setWidth(200); 125 | tc4.setWidth(70); 126 | tc5.setWidth(70); 127 | tc6.setWidth(70); 128 | tc7.setWidth(70); 129 | tc8.setWidth(70); 130 | 131 | CellEditor[] editors = new CellEditor[columnNames.length]; 132 | editors[0] = new TextCellEditor(columnsTable, SWT.READ_ONLY); 133 | editors[1] = new TextCellEditor(columnsTable); 134 | editors[2] = new TextCellEditor(columnsTable); 135 | editors[3] = new CheckboxCellEditor(columnsTable); 136 | editors[4] = new CheckboxCellEditor(columnsTable); 137 | editors[5] = new CheckboxCellEditor(columnsTable); 138 | editors[6] = new CheckboxCellEditor(columnsTable); 139 | editors[7] = new TextCellEditor(columnsTable); 140 | tableViewer.setCellEditors(editors); 141 | 142 | tableViewer.setLabelProvider(new ColumnLabelProvider()); 143 | tableViewer.setContentProvider(new ColumnContentProvider()); 144 | tableViewer.setCellModifier(new ColumnCellModifier(this,this.columnNames)); 145 | tableViewer.setInput(columnList); 146 | } 147 | 148 | public void onEnterPage() { 149 | StartCurdWizard wizard = (StartCurdWizard) super.getWizard(); 150 | PageOne pageOne = (PageOne) wizard.getPage("PageOne"); 151 | PageTwo pageTwo = (PageTwo) wizard.getPage("PageTwo"); 152 | TableModel table = wizard.getTableModel(); 153 | columnList = AutoCodeDbUtils.getColumnList(pageOne.getDs(),table.getName()); 154 | tableViewer.refresh(); 155 | } 156 | 157 | 158 | class ColumnContentProvider implements IStructuredContentProvider { 159 | 160 | public void dispose() { 161 | } 162 | 163 | public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 164 | 165 | } 166 | 167 | public Object[] getElements(Object inputElement) { 168 | return columnList.toArray(); 169 | } 170 | } 171 | } 172 | 173 | /** 174 | * LABEL 提供者 175 | * 176 | */ 177 | class ColumnLabelProvider extends LabelProvider implements ITableLabelProvider { 178 | 179 | // Names of images used to represent checkboxes 180 | public static final String CHECKED_IMAGE = "checked"; 181 | public static final String UNCHECKED_IMAGE = "unchecked"; 182 | 183 | private static ImageRegistry imageRegistry = new ImageRegistry(); 184 | 185 | static { 186 | String iconPath = "icons/"; 187 | imageRegistry.put(CHECKED_IMAGE, ResourceManager.getPluginImage("com.thinkgem.jeesite.autocode", "icons/checked.png")); 188 | imageRegistry.put(UNCHECKED_IMAGE, ResourceManager.getPluginImage("com.thinkgem.jeesite.autocode", "icons/unchecked.png")); 189 | } 190 | 191 | /** 192 | * Returns the image with the given key, or null if not found. 193 | */ 194 | private Image getImage(boolean isSelected) { 195 | String key = isSelected ? CHECKED_IMAGE : UNCHECKED_IMAGE; 196 | return imageRegistry.get(key); 197 | } 198 | 199 | /* 200 | * (non-Javadoc) 201 | * 202 | * @see 203 | * org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang 204 | * .Object, int) 205 | */ 206 | public Image getColumnImage(Object element, int columnIndex) { 207 | ColumnModel col = (ColumnModel) element; 208 | 209 | Image result = null; 210 | 211 | switch (columnIndex) { 212 | case 3: 213 | result = getImage("Y".equalsIgnoreCase(col.getIsParamKey())); 214 | break; 215 | case 4: 216 | result = getImage("Y".equalsIgnoreCase(col.getIsList())); 217 | break; 218 | case 5: 219 | result = getImage("Y".equalsIgnoreCase(col.getIsQuery())); 220 | break; 221 | case 6: 222 | result = getImage("Y".equalsIgnoreCase(col.getIsEdit())); 223 | break; 224 | default: 225 | break; 226 | } 227 | return result; 228 | } 229 | 230 | public String getColumnText(Object element, int columnIndex) { 231 | String result = ""; 232 | ColumnModel col = (ColumnModel) element; 233 | switch (columnIndex) { 234 | case 0: 235 | result = col.getColumnName(); 236 | break; 237 | case 1: 238 | result = col.getJavaName(); 239 | break; 240 | case 2: 241 | result = col.getComment() == null ? "" : col.getComment(); 242 | break; 243 | case 7: 244 | result = col.getDictKey(); 245 | break; 246 | default: 247 | break; 248 | } 249 | return result; 250 | } 251 | 252 | } 253 | 254 | class ColumnCellModifier implements ICellModifier { 255 | PageThree pageThree; 256 | List columnNames; 257 | 258 | public ColumnCellModifier(PageThree pageThree, String[] columnNames) { 259 | this.pageThree = pageThree; 260 | this.columnNames = Arrays.asList(columnNames); 261 | } 262 | 263 | public boolean canModify(Object element, String property) { 264 | return true; 265 | } 266 | 267 | public Object getValue(Object element, String property) { 268 | int columnIndex = columnNames.indexOf(property); 269 | 270 | Object result = null; 271 | 272 | ColumnModel col = (ColumnModel) element; 273 | switch (columnIndex) { 274 | case 0: 275 | result = col.getColumnName(); 276 | break; 277 | case 1: 278 | result = col.getJavaName(); 279 | break; 280 | case 2: 281 | result = col.getComment(); 282 | break; 283 | case 3: 284 | result = new Boolean(!"Y".equals(col.getIsParamKey())); 285 | break; 286 | case 4: 287 | result = new Boolean(!"Y".equals(col.getIsList())); 288 | break; 289 | case 5: 290 | result = new Boolean(!"Y".equals(col.getIsQuery())); 291 | break; 292 | case 6: 293 | result = new Boolean(!"Y".equals(col.getIsEdit())); 294 | break; 295 | case 7: 296 | result = col.getDictKey(); 297 | break; 298 | default: 299 | result = ""; 300 | } 301 | return result; 302 | } 303 | 304 | public void modify(Object element, String property, Object value) { 305 | int columnIndex = columnNames.indexOf(property); 306 | TableItem item = (TableItem) element; 307 | ColumnModel col = (ColumnModel)item.getData(); 308 | switch (columnIndex) { 309 | case 0: 310 | col.setColumnName(StringUtils.trim((String)value)); 311 | break; 312 | case 1: 313 | col.setJavaName(StringUtils.trim((String)value)); 314 | break; 315 | case 2: 316 | col.setComment(StringUtils.trim((String)value)); 317 | break; 318 | case 3: 319 | col.setIsParamKey(((Boolean) value).booleanValue()?"N":"Y"); 320 | break; 321 | case 4: 322 | col.setIsList(((Boolean) value).booleanValue()?"N":"Y"); 323 | break; 324 | case 5: 325 | col.setIsQuery(((Boolean) value).booleanValue()?"N":"Y"); 326 | break; 327 | case 6: 328 | col.setIsEdit(((Boolean) value).booleanValue()?"N":"Y"); 329 | break; 330 | case 7: 331 | col.setDictKey(StringUtils.trim((String)value)); 332 | break; 333 | default: 334 | //result = ""; 335 | } 336 | 337 | this.pageThree.getTableViewer().update(col, null); 338 | } 339 | 340 | } -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/crud/StartCurdWizard.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.crud; 2 | 3 | import java.io.File; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.eclipse.jface.wizard.Wizard; 8 | 9 | import com.thinkgem.jeesite.autocode.model.ColumnModel; 10 | import com.thinkgem.jeesite.autocode.model.TableConfigModel; 11 | import com.thinkgem.jeesite.autocode.model.TableModel; 12 | import com.thinkgem.jeesite.autocode.util.FreeMakerUtils; 13 | import com.thinkgem.jeesite.autocode.util.StringUtils; 14 | import com.thinkgem.jeesite.autocode.util.XmlObjectCrud; 15 | import com.thinkgem.jeesite.autocode.util.XmlObjectUtils; 16 | 17 | import freemarker.template.Configuration; 18 | 19 | public class StartCurdWizard extends Wizard { 20 | //所有全局变量防止在这里 21 | 22 | TableModel tableModel = new TableModel(); 23 | 24 | public StartCurdWizard() { 25 | setWindowTitle("树状机构生成"); 26 | setHelpAvailable(false); 27 | setNeedsProgressMonitor(false); 28 | } 29 | 30 | @Override 31 | public void addPages() { 32 | addPage(new PageOne()); 33 | addPage(new PageTwo()); 34 | addPage(new PageThree()); 35 | 36 | //设置上一次操作的路径 37 | TableConfigModel fileconfig = (TableConfigModel)XmlObjectUtils.objectXmlDecoder(XmlObjectCrud.getLeastTable()); 38 | if(fileconfig!=null){ 39 | PageTwo pageTwo = (PageTwo)super.getPage("PageTwo"); 40 | TableConfigModel pttable = pageTwo.getTableConfig(); 41 | pttable.setAuthor(fileconfig.getAuthor()); 42 | pttable.setVersion(fileconfig.getVersion()); 43 | pttable.setTopPackage(fileconfig.getTopPackage()); 44 | pttable.setFilePath(fileconfig.getFilePath()); 45 | pttable.setJspLocation(fileconfig.getJspLocation()); 46 | pttable.setFunctionNameCn(fileconfig.getFunctionNameCn()); 47 | pttable.setFunctionNameEn(fileconfig.getFunctionNameEn()); 48 | pttable.setUrlPrefix(fileconfig.getUrlPrefix()); 49 | pttable.setPermissionPrefix(fileconfig.getPermissionPrefix()); 50 | } 51 | } 52 | 53 | @Override 54 | public boolean performFinish() { 55 | PageTwo pageTwo = (PageTwo)super.getPage("PageTwo"); 56 | pageTwo.checkInput(); 57 | 58 | TableConfigModel tableconfig = pageTwo.getTableConfig(); 59 | PageThree pageThree = (PageThree)super.getPage("PageThree"); 60 | XmlObjectUtils.objectXmlEncoder(pageThree.getColumnList(), XmlObjectCrud.getLeastColumns()); 61 | XmlObjectUtils.objectXmlEncoder(tableconfig,XmlObjectCrud.getLeastTable()); 62 | //设置主键字段 63 | for(ColumnModel column:pageThree.getColumnList()){ 64 | if(column.isKey()){ 65 | tableconfig.setKey(column); 66 | break; 67 | } 68 | } 69 | Map data = new HashMap(); 70 | data.put("columnList", pageThree.getColumnList()); 71 | data.put("table", tableconfig); 72 | 73 | 74 | String separator = File.separator; 75 | String basePath = pageTwo.getTableConfig().getFilePath(); 76 | 77 | //生成文件 78 | Configuration freemakerCfg = FreeMakerUtils.getFreeMarkerCfg(this.getClass(), "template"); 79 | //Configuration freemakerCfg = FreeMakerUtils.getFreeMarkerCfg(XmlObjectCrud.getFtlPath()); 80 | FreeMakerUtils.generateFile(freemakerCfg, "entity.ftl", data, "src\\"+StringUtils.replace(tableconfig.getTopPackage(), ".", "\\") + "\\entity\\", StringUtils.capitalize(tableconfig.getTableJavaName()) +".java", basePath); 81 | FreeMakerUtils.generateFile(freemakerCfg,"hbm.ftl",data,"src\\config\\hibernate\\",StringUtils.capitalize(tableconfig.getTableJavaName())+".hbm.xml",basePath); 82 | FreeMakerUtils.generateFile(freemakerCfg,"struts.ftl",data,"src\\config\\struts\\warehouse\\","tmp.xml",basePath); 83 | FreeMakerUtils.generateFile(freemakerCfg, "action.ftl", data, "src\\"+StringUtils.replace(tableconfig.getTopPackage(), ".", "\\") + "\\web\\", StringUtils.capitalize(tableconfig.getFunctionNameEn()) +"Action.java", basePath); 84 | FreeMakerUtils.generateFile(freemakerCfg, "service.ftl", data, "src\\"+StringUtils.replace(tableconfig.getTopPackage(), ".", "\\") + "\\services\\", StringUtils.capitalize(tableconfig.getFunctionNameEn()) +"Service.java", basePath); 85 | FreeMakerUtils.generateFile(freemakerCfg, "serviceImpl.ftl", data, "src\\"+StringUtils.replace(tableconfig.getTopPackage(), ".", "\\") + "\\services\\impl\\", StringUtils.capitalize(tableconfig.getFunctionNameEn()) +"ServiceImpl.java", basePath); 86 | FreeMakerUtils.generateFile(freemakerCfg, "qry.ftl", data, "src\\"+StringUtils.replace(tableconfig.getTopPackage(), ".", "\\") + "\\qry\\", StringUtils.capitalize(tableconfig.getFunctionNameEn()) +"Qry.java", basePath); 87 | 88 | FreeMakerUtils.generateFile(freemakerCfg, "list.ftl", data, "WebRoot\\"+StringUtils.replace(tableconfig.getJspLocation(), "/", "\\"), "list.jsp", basePath); 89 | FreeMakerUtils.generateFile(freemakerCfg, "edit.ftl", data, "WebRoot\\"+StringUtils.replace(tableconfig.getJspLocation(), "/", "\\"), "edit.jsp", basePath); 90 | FreeMakerUtils.generateFile(freemakerCfg, "view.ftl", data, "WebRoot\\"+StringUtils.replace(tableconfig.getJspLocation(), "/", "\\"), "view.jsp", basePath); 91 | 92 | 93 | //MessageDialog.openInformation(super.getShell(), "代码生成成功", "代码生成成功,生成代码存放路径:"+tableconfig.getFilePath()); 94 | return false; 95 | } 96 | 97 | 98 | 99 | public void setTableModel(String name,String comment){ 100 | tableModel.setName(name); 101 | tableModel.setComment(comment); 102 | } 103 | 104 | public TableModel getTableModel() { 105 | return tableModel; 106 | } 107 | 108 | @Override 109 | public boolean canFinish() { 110 | if("PageThree".equals(super.getContainer().getCurrentPage().getName())){ 111 | return true; 112 | }else{ 113 | return false; 114 | } 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/crud/template/action.ftl: -------------------------------------------------------------------------------- 1 | package ${table.topPackage}.web; 2 | 3 | import java.util.Date; 4 | 5 | import org.apache.commons.lang.StringUtils; 6 | 7 | import com.calf.framework.util.Constants; 8 | import com.calf.framework.util.ObjectUtils; 9 | import com.calf.framework.vo.AdminUserInfo; 10 | import com.calf.framework.vo.Page; 11 | import ${table.topPackage}.entity.${table.tableJavaName?cap_first}; 12 | import ${table.topPackage}.qry.${table.functionNameEn?cap_first}Qry; 13 | import ${table.topPackage}.services.${table.functionNameEn?cap_first}Service; 14 | import com.calf.framework.web.BaseAction; 15 | import com.calf.framework.web.util.RequiresPermissions; 16 | 17 | 18 | public class ${table.functionNameEn?cap_first}Action extends BaseAction { 19 | 20 | ${table.functionNameEn?cap_first}Service ${table.functionNameEn}Service; 21 | 22 | ${table.functionNameEn?cap_first}Qry qry; 23 | 24 | Page page; 25 | 26 | ${table.tableJavaName?cap_first} entity; 27 | 28 | /** 29 | * 列表 30 | */ 31 | @RequiresPermissions(value = "${table.permissionPrefix}:view",requiresUser=true) 32 | public String list() throws Exception{ 33 | AdminUserInfo userInfo = super.getUserInfo(); 34 | if(StringUtils.isNotBlank(super.qryHex)){ 35 | qry = (${table.functionNameEn?cap_first}Qry)ObjectUtils.getObjectFromHex(qryHex); 36 | } 37 | if(qry==null){ 38 | qry = new ${table.functionNameEn?cap_first}Qry(); 39 | qry.setOrderCol("createDate"); 40 | qry.setOrderType(Constants.DESC); 41 | } 42 | 43 | //设置默认排序号 44 | if(StringUtils.isBlank(qry.getOrderCol())){ 45 | qry.setOrderCol("createDate"); 46 | qry.setOrderType(Constants.DESC); 47 | } 48 | 49 | qry.setUserInfo(userInfo); 50 | page = ${table.functionNameEn}Service.find${table.functionNameEn?cap_first}Page(qry); 51 | return "list"; 52 | } 53 | /** 54 | * 新增 55 | **/ 56 | @RequiresPermissions(value = "${table.permissionPrefix}:edit",requiresUser=true) 57 | public String toAdd() throws Exception{ 58 | AdminUserInfo userInfo = super.getUserInfo(); 59 | entity = new ${table.tableJavaName?cap_first}(); 60 | super.event="ADD"; 61 | super.title="新增"; 62 | return "edit"; 63 | } 64 | /** 65 | * 修改 66 | **/ 67 | @RequiresPermissions(value = "${table.permissionPrefix}:edit",requiresUser=true) 68 | public String toEdit() throws Exception{ 69 | AdminUserInfo userInfo = super.getUserInfo(); 70 | entity = ${table.functionNameEn}Service.get(${table.tableJavaName?cap_first}.class,entity.get${table.key.javaName?cap_first}()); 71 | super.event="EDIT"; 72 | super.title="修改"; 73 | return "edit"; 74 | } 75 | /** 76 | * 修改动作 77 | **/ 78 | @RequiresPermissions(value = "${table.permissionPrefix}:edit",requiresUser=true) 79 | public String edit() throws Exception{ 80 | AdminUserInfo userInfo = super.getUserInfo(); 81 | if("ADD".equals(super.event)){ 82 | //新增操作 83 | entity.set${table.key.javaName?cap_first}(null); 84 | entity.setDataStatus(Constants.YES); 85 | entity.setCreateUser(userInfo.getUserId()); 86 | entity.setCreateDate(new Date()); 87 | ${table.functionNameEn}Service.save${table.functionNameEn?cap_first}(entity); 88 | super.addAttribute("qry.orderCol", "createDate"); 89 | super.addAttribute("qry.orderType", "0"); 90 | super.saveMessage("${table.functionNameCn}新增成功"); 91 | }else if("EDIT".equals(super.event)){ 92 | //修改操作 93 | ${table.tableJavaName?cap_first} db = ${table.functionNameEn}Service.get(${table.tableJavaName?cap_first}.class,entity.get${table.key.javaName?cap_first}()); 94 | 95 | <#list columnList as x> 96 | <#if x.isEdit=="Y"> 97 | db.set${x.javaName?cap_first}(entity.get${x.javaName?cap_first}()); 98 | 99 | 100 | 101 | db.setUpdateUser(userInfo.getUserId()); 102 | db.setUpdateDate(new Date()); 103 | 104 | ${table.functionNameEn}Service.save${table.functionNameEn?cap_first}(db); 105 | super.saveMessage("${table.functionNameCn}修改保存成功"); 106 | super.addAttribute("qryHex", super.qryHex); 107 | } 108 | super.redirectUrl = "${table.urlPrefix}_list.action"; 109 | return super.GLOBAL_SUCCESS; 110 | } 111 | /** 112 | * 删除 113 | **/ 114 | @RequiresPermissions(value = "${table.permissionPrefix}:edit",requiresUser=true) 115 | public String delete() throws Exception{ 116 | AdminUserInfo userInfo = super.getUserInfo(); 117 | entity = ${table.functionNameEn}Service.get(${table.tableJavaName?cap_first}.class,entity.get${table.key.javaName?cap_first}()); 118 | if(entity.isCanDelete()){ 119 | this.${table.functionNameEn}Service.delete${table.functionNameEn?cap_first}(entity); 120 | super.renderJsonSuccess("删除成功!"); 121 | }else{ 122 | super.renderJsonError("该记录已被删除!"); 123 | } 124 | return null; 125 | } 126 | 127 | /** 128 | * 修改 129 | **/ 130 | @RequiresPermissions(value = "${table.permissionPrefix}:view",requiresUser=true) 131 | public String toView() throws Exception{ 132 | AdminUserInfo userInfo = super.getUserInfo(); 133 | entity = ${table.functionNameEn}Service.get(${table.tableJavaName?cap_first}.class,entity.get${table.key.javaName?cap_first}()); 134 | super.title="${table.functionNameCn}详细信息"; 135 | return "view"; 136 | } 137 | 138 | /** 139 | * 判断是否唯一 140 | * @return 141 | */ 142 | public String checkUnique()throws Exception{ 143 | AdminUserInfo userInfo = super.getUserInfo(); 144 | boolean isCorrect = ${table.functionNameEn}Service.isUnique(entity.get${table.key.javaName?cap_first}()); 145 | super.rendText(String.valueOf(isCorrect)); 146 | return null; 147 | } 148 | 149 | public ${table.functionNameEn?cap_first}Qry getQry(){ 150 | return this.qry; 151 | } 152 | public void setQry(${table.functionNameEn?cap_first}Qry qry){ 153 | this.qry = qry; 154 | } 155 | 156 | public ${table.functionNameEn?cap_first}Service get${table.functionNameEn?cap_first}Service(){ 157 | return this.${table.functionNameEn}Service; 158 | } 159 | public void set${table.functionNameEn?cap_first}Service(${table.functionNameEn?cap_first}Service ${table.functionNameEn}Service){ 160 | this.${table.functionNameEn}Service = ${table.functionNameEn}Service; 161 | } 162 | public Page getPage() { 163 | return this.page; 164 | } 165 | public void setPage(Page page) { 166 | this.page = page; 167 | } 168 | public ${table.tableJavaName?cap_first} getEntity(){ 169 | return entity; 170 | } 171 | public void setEntity(${table.tableJavaName?cap_first} entity){ 172 | this.entity = entity; 173 | } 174 | } -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/crud/template/edit.ftl: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=utf-8"%> 2 | <%@page import="com.calf.framework.util.CodeNameUtils"%> 3 | <%@ include file="/jsp/include/head.jsp"%> 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%@ include file="/jsp/include/basejs.jsp" %> 13 | 22 | 23 | 24 |
25 |
26 |
27 |
28 |
29 | 33 |
34 |
35 | 36 |
37 |
38 | 39 |
40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 54 | 55 | 56 | 57 | 58 | <#list columnList as x> 59 | <#if x.isEdit=="Y"> 60 | 61 | 62 | 71 | 72 | 73 | 74 | 75 | 76 | 77 |
<#if table.key.comment??>${table.key.comment} 51 | ${r"${entity."}${table.key.javaName}${r"}"} 52 | 53 |
<#if x.isNull!="Y"> 63 | <#if x.isParamKey!="Y"> 64 | {byteRangeLength:[0,${x.datasize}]}<#if x.isNull!="Y"> {required: true,byteRangeLength:[0,${x.datasize}],messages: {required:'请输入<#if x.comment??>${x.comment}'}}" id="${x.javaName}" value="${r"${entity."}${x.javaName}<#if x.javaType=='Double'>Str<#if x.javaType=='Date'>Str<#if x.isParamKey=="Y">Str${r"}"}"/> 65 | 66 | 67 | <#if x.dictKey!=""> 68 | <%=CodeNameUtils.getInstance().generateSelect("
78 |
79 | 80 |
81 |
82 |
83 | 84 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/crud/template/entity.ftl: -------------------------------------------------------------------------------- 1 | package ${table.topPackage}.entity; 2 | 3 | import java.util.Date; 4 | 5 | import com.calf.framework.util.DateUtil; 6 | import com.calf.framework.util.FormateUtil; 7 | 8 | public class ${table.tableJavaName?cap_first} implements java.io.Serializable { 9 | /** 10 | * 11 | */ 12 | private static final long serialVersionUID = 7210248768007789556L; 13 | 14 | <#list columnList as x> 15 | <#if x.key> 16 | /** 17 | * 主键 18 | * <#if x.comment??>${x.comment} 19 | **/ 20 | ${x.javaType} ${x.javaName}; 21 | <#else> 22 | /** 23 | * <#if x.comment??>${x.comment} 24 | **/ 25 | ${x.javaType} ${x.javaName}; 26 | 27 | 28 | 29 | public ${table.tableJavaName?cap_first}(){ 30 | } 31 | 32 | <#list columnList as x> 33 | public ${x.javaType} get${x.javaName?cap_first}(){ 34 | return this.${x.javaName}; 35 | } 36 | public void set${x.javaName?cap_first}(${x.javaType} ${x.javaName}){ 37 | this.${x.javaName} = ${x.javaName}; 38 | } 39 | 40 | 41 | <#list columnList as x> 42 | <#if x.javaType=='Double'> 43 | public String get${x.javaName?cap_first}Str(){ 44 | return FormateUtil.getInstance().formateDouble(this.${x.javaName}); 45 | } 46 | 47 | <#if x.javaType=='Date'> 48 | public String get${x.javaName?cap_first}Str(){ 49 | return DateUtil.getInstance().dateToString(this.${x.javaName},DateUtil.patternA); 50 | } 51 | 52 | 53 | 54 | <#list columnList as x> 55 | <#if x.dictKey!=""> 56 | public String get${x.javaName?cap_first}Str(){ 57 | return FormateUtil.getInstance().getNameByCode("${x.dictKey}", ${x.javaName}); 58 | } 59 | 60 | 61 | 62 | public boolean isCanDelete(){ 63 | return "1".equals(this.dataStatus); 64 | } 65 | } -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/crud/template/hbm.ftl: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | <#list columnList as x> 8 | <#if x.key> 9 | <#if x.javaType=='Long'> 10 | 11 | not-null="true"/> 12 | 13 | <#if x.javaType=='String'> 14 | 15 | not-null="true"/> 16 | 17 | 18 | SEQ_${table.seqName} 19 | 20 | 21 | <#else> 22 | 23 | 24 | <#if x.javaType=='Long'> 25 | 26 | not-null="true"/> 27 | 28 | <#if x.javaType=='String'> 29 | 30 | not-null="true"/> 31 | 32 | <#if x.javaType=='Date'> 33 | 34 | not-null="true"/> 35 | 36 | <#if x.javaType=='Double'> 37 | 38 | not-null="true"/> 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/crud/template/list.ftl: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=utf-8"%> 2 | <%@page import="com.calf.framework.util.CodeNameUtils"%> 3 | <%@page import="com.calf.framework.util.Constants"%> 4 | 5 | <%@ include file="/jsp/include/head.jsp"%> 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | <%@ include file="/jsp/include/basejs.jsp" %> 15 | 48 | 49 | 50 |
loading....
51 | 52 |
53 | 54 | 55 |
56 | 57 |
58 |
59 |
60 |
61 |
62 | 66 |
67 |
68 | 69 |
70 |
71 |
72 | 73 | 74 | 82 | 83 |
75 | <#list columnList as x> 76 | <#if x.isQuery=="Y"> 77 | 78 | 79 | 80 | 81 |
84 | 85 | 86 | 87 | 88 |
89 | 没有查询到符合条件的${table.functionNameCn} 90 |
91 |
92 | 93 | 94 | 95 | <#list columnList as x> 96 | <#if x.isList=="Y"> 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | <#list columnList as x> 105 | <#if x.isList=="Y"> 106 | 107 | 108 | 109 | 118 | 119 | 120 |
<#if x.comment??>${x.comment}操作
${r"${b."}${x.javaName}<#if x.javaType=='Double'>Str<#if x.javaType=='Date'>Str<#if x.dictKey!="">Str${r"}"} 110 | 111 | 修改  112 | 113 | 删除 114 | 115 | 116 | 查看 117 |
121 | 122 | 123 | 124 | 125 | 126 | 127 |
128 |
129 |
130 |
131 |
132 |
133 | 134 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/crud/template/qry.ftl: -------------------------------------------------------------------------------- 1 | package ${table.topPackage}.qry; 2 | 3 | import java.io.Serializable; 4 | 5 | import com.calf.framework.util.BaseAdminQuery; 6 | 7 | public class ${table.functionNameEn?cap_first}Qry extends BaseAdminQuery implements Serializable { 8 | /** 9 | * 10 | */ 11 | private static final long serialVersionUID = 1937084884877261956L; 12 | 13 | <#list columnList as x> 14 | <#if x.isQuery=="Y"> 15 | /** 16 | * <#if x.comment??>${x.comment} 17 | **/ 18 | ${x.javaType} ${x.javaName}; 19 | 20 | 21 | 22 | <#list columnList as x> 23 | <#if x.isQuery=="Y"> 24 | public ${x.javaType} get${x.javaName?cap_first}(){ 25 | return this.${x.javaName}; 26 | } 27 | public void set${x.javaName?cap_first}(${x.javaType} ${x.javaName}){ 28 | this.${x.javaName} = ${x.javaName}; 29 | } 30 | 31 | 32 | 33 | <#list columnList as x> 34 | <#if x.isQuery=="Y"> 35 | <#if x.javaType=='Double'> 36 | public String get${x.javaName?cap_first}Str(){ 37 | return FormateUtil.getInstance().formateDouble(this.${x.javaName}); 38 | } 39 | 40 | <#if x.javaType=='Date'> 41 | public String get${x.javaName?cap_first}Str(){ 42 | return DateUtil.getInstance().dateToString(this.${x.javaName},DateUtil.patternA); 43 | } 44 | 45 | 46 | 47 | } -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/crud/template/service.ftl: -------------------------------------------------------------------------------- 1 | package ${table.topPackage}.services; 2 | 3 | import java.util.List; 4 | 5 | import com.calf.framework.services.BaseService; 6 | import ${table.topPackage}.entity.${table.tableJavaName?cap_first}; 7 | import ${table.topPackage}.qry.${table.functionNameEn?cap_first}Qry; 8 | import com.calf.framework.vo.Page; 9 | 10 | public interface ${table.functionNameEn?cap_first}Service extends BaseService{ 11 | /** 12 | * 保存 13 | **/ 14 | public String save${table.functionNameEn?cap_first}(${table.tableJavaName?cap_first} entity); 15 | /** 16 | * 删除 17 | */ 18 | public String delete${table.functionNameEn?cap_first}(${table.tableJavaName?cap_first} entity); 19 | /** 20 | * 查找分页信息 21 | */ 22 | public Page find${table.functionNameEn?cap_first}Page(${table.functionNameEn?cap_first}Qry qry); 23 | 24 | /** 25 | * 判断编码是否唯一 26 | * @return 27 | */ 28 | public boolean isUnique(${table.key.javaType} ${table.key.javaName}); 29 | } -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/crud/template/serviceImpl.ftl: -------------------------------------------------------------------------------- 1 | package ${table.topPackage}.services.impl; 2 | 3 | import org.hibernate.Criteria; 4 | import org.hibernate.criterion.Restrictions; 5 | import org.springframework.stereotype.Service; 6 | 7 | import com.calf.framework.dao.CriteriaUtils; 8 | import com.calf.framework.services.impl.BaseServiceImpl; 9 | import com.calf.framework.util.Constants; 10 | import ${table.topPackage}.entity.${table.tableJavaName?cap_first}; 11 | import ${table.topPackage}.qry.${table.functionNameEn?cap_first}Qry; 12 | import com.calf.framework.vo.Page; 13 | import ${table.topPackage}.services.${table.functionNameEn?cap_first}Service; 14 | 15 | @Service("${table.functionNameEn}Service") 16 | public class ${table.functionNameEn?cap_first}ServiceImpl extends BaseServiceImpl implements ${table.functionNameEn?cap_first}Service{ 17 | /** 18 | * 查找分页信息 19 | */ 20 | public Page find${table.functionNameEn?cap_first}Page(${table.functionNameEn?cap_first}Qry qry){ 21 | Criteria criteria = hibernateDao.createCriteria(${table.tableJavaName?cap_first}.class); 22 | <#list columnList as x> 23 | <#if x.isQuery=="Y"> 24 | CriteriaUtils.addEq(criteria, "${x.javaName}", qry.get${x.javaName?cap_first}()); 25 | 26 | 27 | criteria.add(Restrictions.eq("dataStatus", Constants.YES)); 28 | CriteriaUtils.addOrder(criteria,qry.getOrderCol(),qry.getOrderType()); 29 | return super.hibernateDao.pagedQuery(criteria, qry.getPageNo(), qry.getPageSize()); 30 | } 31 | 32 | /** 33 | * 保存 34 | **/ 35 | public String save${table.functionNameEn?cap_first}(${table.tableJavaName?cap_first} entity){ 36 | super.save(entity); 37 | return null; 38 | } 39 | /** 40 | * 删除 41 | */ 42 | public String delete${table.functionNameEn?cap_first}(${table.tableJavaName?cap_first} entity){ 43 | entity.setDataStatus(Constants.NO); 44 | super.save(entity); 45 | return null; 46 | } 47 | 48 | /** 49 | * 判断编码是否唯一 50 | * @return 51 | */ 52 | public boolean isUnique(${table.key.javaType} ${table.key.javaName}){ 53 | ${table.tableJavaName?cap_first} entity = super.hibernateDao.get(${table.tableJavaName?cap_first}.class, ${table.key.javaName}); 54 | return entity==null; 55 | } 56 | } -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/crud/template/struts.ftl: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | ${table.jspLocation}/edit.jsp 13 | ${table.jspLocation}/list.jsp 14 | ${table.jspLocation}/view.jsp 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/crud/template/view.ftl: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=utf-8"%> 2 | <%@page import="com.calf.framework.util.CodeNameUtils"%> 3 | <%@ include file="/jsp/include/head.jsp"%> 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%@ include file="/jsp/include/basejs.jsp" %> 13 | 14 | 15 | 16 | <#list columnList as x> 17 | <#if x.isEdit=="Y"> 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
<#if x.comment??>${x.comment}${r"${entity."}${x.javaName}<#if x.javaType=='Double'>Str<#if x.javaType=='Date'>Str<#if x.dictKey!="">Str${r"}"}
28 | 29 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/datasource/SelectionUpdateValueStrategy.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.datasource; 2 | 3 | import org.eclipse.core.databinding.UpdateValueStrategy; 4 | import org.eclipse.core.databinding.observable.value.IObservableValue; 5 | import org.eclipse.core.runtime.IStatus; 6 | 7 | public class SelectionUpdateValueStrategy extends UpdateValueStrategy { 8 | 9 | public SelectionUpdateValueStrategy() { 10 | } 11 | 12 | protected IStatus doSet(IObservableValue observableValue, Object value) { 13 | Integer selection = (Integer) value; 14 | return super.doSet(observableValue, 15 | selection.intValue() == -1 ? Boolean.FALSE : Boolean.TRUE); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/model/AbstractModelObject.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.model; 2 | 3 | import java.beans.PropertyChangeListener; 4 | import java.beans.PropertyChangeSupport; 5 | 6 | public abstract class AbstractModelObject { 7 | private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( 8 | this); 9 | 10 | public void addPropertyChangeListener(PropertyChangeListener listener) { 11 | propertyChangeSupport.addPropertyChangeListener(listener); 12 | } 13 | 14 | public void addPropertyChangeListener(String propertyName, 15 | PropertyChangeListener listener) { 16 | propertyChangeSupport.addPropertyChangeListener(propertyName, listener); 17 | } 18 | 19 | public void removePropertyChangeListener(PropertyChangeListener listener) { 20 | propertyChangeSupport.removePropertyChangeListener(listener); 21 | } 22 | 23 | public void removePropertyChangeListener(String propertyName, 24 | PropertyChangeListener listener) { 25 | propertyChangeSupport.removePropertyChangeListener(propertyName, 26 | listener); 27 | } 28 | 29 | protected void firePropertyChange(String propertyName, Object oldValue, 30 | Object newValue) { 31 | propertyChangeSupport.firePropertyChange(propertyName, oldValue, 32 | newValue); 33 | } 34 | } -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/model/ColumnModel.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.model; 2 | 3 | import com.thinkgem.jeesite.autocode.util.StringUtils; 4 | 5 | public class ColumnModel extends AbstractModelObject { 6 | String columnName; 7 | String javaName; 8 | String javaType; 9 | String dbType;//数据库声明的类型 10 | int datasize;//数据大小 11 | int digits;//小数点位数 12 | String isNull; 13 | String isQuery; 14 | String isList; 15 | String isEdit; 16 | String comment; 17 | String isParamKey; 18 | String dictKey;//数据字典ID 19 | 20 | /** 21 | * 做部分字段初始化操作 22 | */ 23 | public void init(){ 24 | //设置JAVA属性名 25 | javaName = StringUtils.getJavaName(columnName); 26 | 27 | //设置是否为主键 28 | if("PRI".equalsIgnoreCase(isParamKey)){ 29 | this.isParamKey = "Y"; 30 | } 31 | 32 | 33 | this.isQuery = "N"; 34 | this.dictKey = ""; 35 | 36 | this.isList = "Y"; 37 | this.isEdit = "Y"; 38 | 39 | String dbType = StringUtils.substringBefore(javaType, "(").toUpperCase(); 40 | if("VARCHAR".equals(dbType) || "CHAR".equals(dbType) ||"VARCHAR2".equals(dbType)){ 41 | this.javaType = "String"; 42 | }else if("DATETIME".equals(dbType)){ 43 | this.javaType = "Date"; 44 | }else if("BIGINT".equals(dbType)){ 45 | this.javaType = "Long"; 46 | } 47 | } 48 | 49 | /** 50 | * 做部分字段初始化操作,处理ORACLE数据库 51 | */ 52 | public void initOra(){ 53 | //设置JAVA属性名 54 | javaName = StringUtils.getJavaName(columnName); 55 | 56 | //设置是否为主键 57 | if("PRI".equalsIgnoreCase(isParamKey)){ 58 | this.isParamKey = "Y"; 59 | } 60 | 61 | //忽略掉部分字段DATA_STATUS,CREATE_USER,CREATE_DATE,UPDATE_USER,UPDATE_DATE 62 | if("DATA_STATUS".equalsIgnoreCase(columnName)||"CREATE_USER".equalsIgnoreCase(columnName)||"CREATE_DATE".equalsIgnoreCase(columnName)||"UPDATE_USER".equalsIgnoreCase(columnName)||"UPDATE_DATE".equalsIgnoreCase(columnName)){ 63 | this.isList = "N"; 64 | this.isEdit = "N"; 65 | }else{ 66 | this.isList = "Y"; 67 | this.isEdit = "Y"; 68 | } 69 | 70 | this.isQuery = "N"; 71 | this.dictKey = ""; 72 | 73 | //转换为大写比较 74 | this.dbType = this.dbType.toUpperCase(); 75 | if("VARCHAR".equals(dbType) || "CHAR".equals(dbType) ||"VARCHAR2".equals(dbType)){ 76 | this.javaType = "String"; 77 | }else if("DATETIME".equals(dbType)||"DATE".equals(dbType)){ 78 | this.javaType = "Date"; 79 | }else if("BIGINT".equals(dbType)){ 80 | this.javaType = "Long"; 81 | }else if("NUMBER".equals(dbType)&&digits==0){ 82 | this.javaType = "Long"; 83 | }else if("NUMBER".equals(dbType)&&digits>0){ 84 | this.javaType = "Double"; 85 | } 86 | 87 | } 88 | 89 | public String getColumnName() { 90 | return columnName; 91 | } 92 | public void setColumnName(String columnName) { 93 | this.columnName = columnName; 94 | } 95 | public String getJavaName() { 96 | return javaName; 97 | } 98 | public void setJavaName(String javaName) { 99 | this.javaName = javaName; 100 | } 101 | public String getJavaType() { 102 | return javaType; 103 | } 104 | public void setJavaType(String javaType) { 105 | this.javaType = javaType; 106 | } 107 | public String getIsNull() { 108 | return isNull; 109 | } 110 | public void setIsNull(String isNull) { 111 | this.isNull = isNull; 112 | } 113 | public String getIsQuery() { 114 | return isQuery; 115 | } 116 | public void setIsQuery(String isQuery) { 117 | this.isQuery = isQuery; 118 | } 119 | public String getIsList() { 120 | return isList; 121 | } 122 | public void setIsList(String isList) { 123 | this.isList = isList; 124 | } 125 | public String getIsEdit() { 126 | return isEdit; 127 | } 128 | public void setIsEdit(String isEdit) { 129 | this.isEdit = isEdit; 130 | } 131 | public String getComment() { 132 | return comment; 133 | } 134 | public void setComment(String comment) { 135 | this.comment = comment; 136 | } 137 | public String getIsParamKey() { 138 | return isParamKey; 139 | } 140 | public void setIsParamKey(String isParamKey) { 141 | this.isParamKey = isParamKey; 142 | } 143 | public String getDictKey() { 144 | return dictKey; 145 | } 146 | public void setDictKey(String dictKey) { 147 | this.dictKey = dictKey; 148 | } 149 | public int getDatasize() { 150 | return datasize; 151 | } 152 | public void setDatasize(int datasize) { 153 | this.datasize = datasize; 154 | } 155 | public int getDigits() { 156 | return digits; 157 | } 158 | public void setDigits(int digits) { 159 | this.digits = digits; 160 | } 161 | 162 | public String getDbType() { 163 | return dbType; 164 | } 165 | 166 | public void setDbType(String dbType) { 167 | this.dbType = dbType; 168 | } 169 | 170 | public boolean isKey(){ 171 | return "Y".equals(this.isParamKey); 172 | } 173 | 174 | public boolean isNullAble(){ 175 | return "Y".equals(this.isNull); 176 | } 177 | 178 | @Override 179 | public String toString() { 180 | StringBuffer str = new StringBuffer(); 181 | str.append("columnName=").append(columnName); 182 | str.append(",javaName=").append(javaName); 183 | str.append(",javaType=").append(javaType); 184 | str.append(",dbType=").append(dbType); 185 | str.append(",isNull=").append(isNull); 186 | str.append(",isQuery=").append(isQuery); 187 | str.append(",isList=").append(isList); 188 | str.append(",isEdit=").append(isEdit); 189 | str.append(",comment=").append(comment); 190 | str.append(",isParamKey=").append(isParamKey); 191 | str.append(",dictKey=").append(dictKey); 192 | return str.toString(); 193 | } 194 | 195 | 196 | } 197 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/model/DataSource.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.model; 2 | 3 | public class DataSource extends AbstractModelObject { 4 | private String name; 5 | private String driver; 6 | private String url; 7 | private String user; 8 | private String password; 9 | private String dbName; 10 | 11 | public String getName() { 12 | return name; 13 | } 14 | 15 | public void setName(String name) { 16 | String oldValue = this.name; 17 | this.name = name; 18 | firePropertyChange("name", oldValue, name); 19 | } 20 | 21 | public String getDriver() { 22 | return driver; 23 | } 24 | 25 | public void setDriver(String driver) { 26 | String oldValue = this.driver; 27 | this.driver = driver; 28 | firePropertyChange("driver", oldValue, driver); 29 | } 30 | 31 | public String getUrl() { 32 | return url; 33 | } 34 | 35 | public void setUrl(String url) { 36 | String oldValue = this.url; 37 | this.url = url; 38 | firePropertyChange("url", oldValue, url); 39 | } 40 | 41 | public String getUser() { 42 | return user; 43 | } 44 | 45 | public void setUser(String user) { 46 | String oldValue = this.user; 47 | this.user = user; 48 | firePropertyChange("user", oldValue, user); 49 | } 50 | 51 | public String getPassword() { 52 | return password; 53 | } 54 | 55 | public void setPassword(String password) { 56 | String oldValue = this.password; 57 | this.password = password; 58 | firePropertyChange("password", oldValue, password); 59 | } 60 | 61 | /** 62 | * 获取数据库类型 63 | * @return 64 | */ 65 | public String getDataBaseType(){ 66 | if("oracle.jdbc.driver.OracleDriver".equals(this.driver)){ 67 | return "ORACLE"; 68 | }else if("com.mysql.jdbc.Driver".equals(this.driver)){ 69 | return "MYSQL"; 70 | }else{ 71 | return ""; 72 | } 73 | } 74 | 75 | public String getDbName() { 76 | return dbName; 77 | } 78 | 79 | public void setDbName(String dbName) { 80 | String oldValue = this.dbName; 81 | this.dbName = dbName; 82 | firePropertyChange("dbName", oldValue, dbName); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/model/TableConfigModel.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.model; 2 | 3 | import com.thinkgem.jeesite.autocode.util.StringUtils; 4 | 5 | public class TableConfigModel { 6 | String tableName; 7 | String tableComment; 8 | String topPackage; 9 | String functionNameEn; 10 | String functionNameCn; 11 | String urlPrefix; 12 | String permissionPrefix; 13 | String jspLocation; 14 | String author; 15 | String version; 16 | String filePath; 17 | String sql;//执行的SQL语句 18 | ColumnModel key;//主键字段 19 | 20 | public String getTableName() { 21 | return tableName; 22 | } 23 | public void setTableName(String tableName) { 24 | this.tableName = tableName; 25 | } 26 | 27 | public String getTableJavaName(){ 28 | return StringUtils.getJavaName(this.tableName); 29 | } 30 | 31 | public String getTableComment() { 32 | return tableComment; 33 | } 34 | public void setTableComment(String tableComment) { 35 | this.tableComment = tableComment; 36 | } 37 | public String getTopPackage() { 38 | return topPackage; 39 | } 40 | public void setTopPackage(String topPackage) { 41 | this.topPackage = topPackage; 42 | } 43 | public String getFunctionNameEn() { 44 | return functionNameEn; 45 | } 46 | public void setFunctionNameEn(String functionNameEn) { 47 | this.functionNameEn = functionNameEn; 48 | } 49 | public String getFunctionNameCn() { 50 | return functionNameCn; 51 | } 52 | public void setFunctionNameCn(String functionNameCn) { 53 | this.functionNameCn = functionNameCn; 54 | } 55 | public String getUrlPrefix() { 56 | return urlPrefix; 57 | } 58 | public void setUrlPrefix(String urlPrefix) { 59 | this.urlPrefix = urlPrefix; 60 | } 61 | public String getJspLocation() { 62 | return jspLocation; 63 | } 64 | public void setJspLocation(String jspLocation) { 65 | this.jspLocation = jspLocation; 66 | } 67 | public String getAuthor() { 68 | return author; 69 | } 70 | public void setAuthor(String author) { 71 | this.author = author; 72 | } 73 | public String getVersion() { 74 | return version; 75 | } 76 | public void setVersion(String version) { 77 | this.version = version; 78 | } 79 | public String getFilePath() { 80 | return filePath; 81 | } 82 | public void setFilePath(String filePath) { 83 | this.filePath = filePath; 84 | } 85 | 86 | public String getSql() { 87 | return sql; 88 | } 89 | public void setSql(String sql) { 90 | this.sql = sql; 91 | } 92 | public String getSeqName(){ 93 | int idx = this.tableName.indexOf("_"); 94 | return this.tableName.substring(++idx).toUpperCase(); 95 | } 96 | public ColumnModel getKey() { 97 | return key; 98 | } 99 | public void setKey(ColumnModel key) { 100 | this.key = key; 101 | } 102 | 103 | public String getPermissionPrefix() { 104 | return permissionPrefix; 105 | } 106 | public void setPermissionPrefix(String permissionPrefix) { 107 | this.permissionPrefix = permissionPrefix; 108 | } 109 | @Override 110 | public String toString() { 111 | StringBuffer str = new StringBuffer(); 112 | str.append("tableName=").append(tableName).append("\r\n"); 113 | str.append("sql=").append(sql).append("\r\n"); 114 | str.append("tableComment=").append(tableComment).append("\r\n"); 115 | str.append("topPackage=").append(topPackage).append("\r\n"); 116 | str.append("functionNameEn=").append(functionNameEn).append("\r\n"); 117 | str.append("functionNameCn=").append(functionNameCn).append("\r\n"); 118 | str.append("urlPrefix=").append(urlPrefix).append("\r\n"); 119 | str.append("jspLocation=").append(jspLocation).append("\r\n"); 120 | str.append("author=").append(author).append("\r\n"); 121 | str.append("version=").append(version).append("\r\n"); 122 | str.append("filePath=").append(filePath).append("\r\n"); 123 | return str.toString(); 124 | } 125 | 126 | 127 | 128 | } 129 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/model/TableModel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.thinkgem.jeesite.autocode.model; 5 | 6 | /** 7 | * 表名和表备注 8 | */ 9 | public class TableModel extends AbstractModelObject { 10 | String name; 11 | String comment; 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | 17 | public void setName(String name) { 18 | String oldValue = this.name; 19 | this.name = name; 20 | firePropertyChange("name", oldValue, name); 21 | } 22 | 23 | public String getComment() { 24 | return comment; 25 | } 26 | 27 | public void setComment(String comment) { 28 | String oldValue = this.comment; 29 | this.comment = comment; 30 | firePropertyChange("comment", oldValue, comment); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/ms/PageOne.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.ms; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.eclipse.core.databinding.DataBindingContext; 6 | import org.eclipse.core.databinding.beans.BeansObservables; 7 | import org.eclipse.core.databinding.observable.list.WritableList; 8 | import org.eclipse.core.databinding.observable.map.IObservableMap; 9 | import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; 10 | import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; 11 | import org.eclipse.jface.viewers.IStructuredSelection; 12 | import org.eclipse.jface.viewers.TableViewer; 13 | import org.eclipse.jface.wizard.IWizardPage; 14 | import org.eclipse.jface.wizard.WizardPage; 15 | import org.eclipse.swt.SWT; 16 | import org.eclipse.swt.custom.SashForm; 17 | import org.eclipse.swt.events.SelectionAdapter; 18 | import org.eclipse.swt.events.SelectionEvent; 19 | import org.eclipse.swt.layout.FillLayout; 20 | import org.eclipse.swt.layout.GridData; 21 | import org.eclipse.swt.layout.GridLayout; 22 | import org.eclipse.swt.widgets.Composite; 23 | import org.eclipse.swt.widgets.Label; 24 | import org.eclipse.swt.widgets.List; 25 | import org.eclipse.swt.widgets.Table; 26 | import org.eclipse.swt.widgets.TableColumn; 27 | import org.eclipse.wb.swt.SWTResourceManager; 28 | 29 | import com.thinkgem.jeesite.autocode.model.DataSource; 30 | import com.thinkgem.jeesite.autocode.model.TableModel; 31 | import com.thinkgem.jeesite.autocode.util.AutoCodeDbUtils; 32 | import com.thinkgem.jeesite.autocode.util.XmlObjectCrud; 33 | import com.thinkgem.jeesite.autocode.util.XmlObjectUtils; 34 | 35 | public class PageOne extends WizardPage { 36 | private DataBindingContext m_bindingContext; 37 | private Table table; 38 | 39 | private java.util.List dataSourceList = new ArrayList(); 40 | 41 | /* 42 | * 表LIST 43 | */ 44 | private java.util.List tableList = new ArrayList(); 45 | 46 | private List connList = null; 47 | 48 | private TableViewer tableViewer; 49 | 50 | private DataSource ds; 51 | 52 | private void updateButtons(){ 53 | getWizard().getContainer().updateButtons(); 54 | } 55 | 56 | /** 57 | * Create the wizard. 58 | */ 59 | public PageOne() { 60 | super("PageOne"); 61 | setTitle("选择数据连接"); 62 | setDescription("请选择数据库连接,模板文件位于:"+XmlObjectCrud.getFtlPath()); 63 | } 64 | 65 | /** 66 | * Create contents of the wizard. 67 | * @param parent 68 | */ 69 | public void createControl(Composite parent) { 70 | Composite container = new Composite(parent, SWT.NULL); 71 | 72 | setControl(container); 73 | container.setLayout(new FillLayout(SWT.HORIZONTAL)); 74 | 75 | SashForm sashForm = new SashForm(container, SWT.NONE); 76 | 77 | Composite composite = new Composite(sashForm, SWT.BORDER); 78 | composite.setLayout(new GridLayout(1, false)); 79 | 80 | Label lblNewLabel = new Label(composite, SWT.SHADOW_NONE | SWT.CENTER); 81 | lblNewLabel.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.BOLD)); 82 | lblNewLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 83 | lblNewLabel.setText("选择数据源"); 84 | 85 | connList = new List(composite, SWT.BORDER); 86 | connList.addSelectionListener(new SelectionAdapter() { 87 | @Override 88 | public void widgetSelected(SelectionEvent e) { 89 | //更新表列表 90 | ds = (DataSource)dataSourceList.get(connList.getSelectionIndex()); 91 | tableList.clear(); 92 | java.util.List tmList = AutoCodeDbUtils.getTableList(ds); 93 | for(TableModel tm:tmList){ 94 | tableList.add(tm); 95 | } 96 | tableViewer.refresh(); 97 | m_bindingContext.updateModels(); 98 | updateButtons(); 99 | } 100 | }); 101 | GridData gd_connList = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); 102 | gd_connList.heightHint = 400; 103 | connList.setLayoutData(gd_connList); 104 | 105 | Composite composite_1 = new Composite(sashForm, SWT.BORDER); 106 | composite_1.setLayout(new GridLayout(1, false)); 107 | 108 | Label lblNewLabel_1 = new Label(composite_1, SWT.HORIZONTAL); 109 | lblNewLabel_1.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1)); 110 | lblNewLabel_1.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.BOLD)); 111 | lblNewLabel_1.setText("选择表名"); 112 | 113 | tableViewer = new TableViewer(composite_1, SWT.BORDER | SWT.FULL_SELECTION); 114 | table = tableViewer.getTable(); 115 | table.addSelectionListener(new SelectionAdapter() { 116 | @Override 117 | public void widgetSelected(SelectionEvent e) { 118 | IStructuredSelection select = (IStructuredSelection)tableViewer.getSelection(); 119 | TableModel tm = (TableModel)select.getFirstElement(); 120 | setWizardTm(tm); 121 | updateButtons(); 122 | } 123 | }); 124 | table.setLinesVisible(true); 125 | table.setHeaderVisible(true); 126 | table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); 127 | 128 | TableColumn tblclmnNewColumn = new TableColumn(table, SWT.NONE); 129 | tblclmnNewColumn.setWidth(190); 130 | tblclmnNewColumn.setText("表名"); 131 | 132 | TableColumn tblclmnNewColumn_1 = new TableColumn(table, SWT.NONE); 133 | tblclmnNewColumn_1.setWidth(168); 134 | tblclmnNewColumn_1.setText("中文名称"); 135 | 136 | 137 | java.util.List tmp = (java.util.List)XmlObjectUtils.objectXmlDecoder(XmlObjectUtils.getDataSourceFileName()); 138 | if(tmp != null){ 139 | dataSourceList = tmp; 140 | } 141 | 142 | String[] connItems = new String[dataSourceList.size()]; 143 | for (int i = 0; i < dataSourceList.size(); i++) { 144 | DataSource ds = (DataSource) dataSourceList.get(i); 145 | connItems[i] = ds.getName(); 146 | } 147 | connList.setItems(connItems); 148 | sashForm.setWeights(new int[] {206, 427}); 149 | 150 | m_bindingContext = initDataBindings(); 151 | 152 | TableModel m = new TableModel(); 153 | m.setName("table"); 154 | m.setComment("comment"); 155 | tableList.add(m); 156 | 157 | } 158 | 159 | private void setWizardTm(TableModel tm){ 160 | StartMsWizard wizard = (StartMsWizard)super.getWizard(); 161 | wizard.setTableModel(tm.getName(), tm.getComment()); 162 | 163 | //设置表信息 164 | PageTwo pageTwo = (PageTwo)wizard.getPage("PageTwo"); 165 | pageTwo.onEnterPage(tm.getName(), tm.getComment()); 166 | 167 | //设置列信息 168 | PageThree pageThree = (PageThree)wizard.getPage("PageThree"); 169 | pageThree.onEnterPage(); 170 | } 171 | 172 | protected DataBindingContext initDataBindings() { 173 | DataBindingContext bindingContext = new DataBindingContext(); 174 | 175 | // 176 | ObservableListContentProvider listContentProvider = new ObservableListContentProvider(); 177 | IObservableMap[] observeMaps = BeansObservables.observeMaps(listContentProvider.getKnownElements(), TableModel.class, new String[]{"name", "comment"}); 178 | tableViewer.setLabelProvider(new ObservableMapLabelProvider(observeMaps)); 179 | tableViewer.setContentProvider(listContentProvider); 180 | // 181 | WritableList writableList = new WritableList(tableList, TableModel.class); 182 | tableViewer.setInput(writableList); 183 | // 184 | return bindingContext; 185 | } 186 | 187 | @Override 188 | public IWizardPage getNextPage() { 189 | return super.getNextPage(); 190 | } 191 | 192 | @Override 193 | public boolean canFlipToNextPage() { 194 | if (getErrorMessage() != null) return false; 195 | if(!tableViewer.getSelection().isEmpty()) { 196 | return true; 197 | } 198 | return false; 199 | } 200 | 201 | public DataSource getDs() { 202 | return ds; 203 | } 204 | 205 | } 206 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/ms/PageThree.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.ms; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | import org.eclipse.jface.resource.ImageRegistry; 8 | import org.eclipse.jface.viewers.CellEditor; 9 | import org.eclipse.jface.viewers.CheckboxCellEditor; 10 | import org.eclipse.jface.viewers.ICellModifier; 11 | import org.eclipse.jface.viewers.IStructuredContentProvider; 12 | import org.eclipse.jface.viewers.ITableLabelProvider; 13 | import org.eclipse.jface.viewers.LabelProvider; 14 | import org.eclipse.jface.viewers.TableViewer; 15 | import org.eclipse.jface.viewers.TextCellEditor; 16 | import org.eclipse.jface.viewers.Viewer; 17 | import org.eclipse.jface.wizard.WizardPage; 18 | import org.eclipse.swt.SWT; 19 | import org.eclipse.swt.graphics.Image; 20 | import org.eclipse.swt.layout.GridData; 21 | import org.eclipse.swt.layout.GridLayout; 22 | import org.eclipse.swt.widgets.Composite; 23 | import org.eclipse.swt.widgets.Table; 24 | import org.eclipse.swt.widgets.TableColumn; 25 | import org.eclipse.swt.widgets.TableItem; 26 | import org.eclipse.swt.widgets.ToolBar; 27 | import org.eclipse.swt.widgets.ToolItem; 28 | import org.eclipse.wb.swt.ResourceManager; 29 | 30 | import swing2swt.layout.BorderLayout; 31 | 32 | import com.thinkgem.jeesite.autocode.model.ColumnModel; 33 | import com.thinkgem.jeesite.autocode.model.TableModel; 34 | import com.thinkgem.jeesite.autocode.util.AutoCodeDbUtils; 35 | import com.thinkgem.jeesite.autocode.util.StringUtils; 36 | 37 | public class PageThree extends WizardPage { 38 | private Table columnsTable; 39 | 40 | /** 41 | * 列信息 42 | */ 43 | List columnList = new ArrayList(); 44 | 45 | private TableViewer tableViewer; 46 | 47 | private String[] columnNames = new String[] {"columnName", "javaName", "javaType", "isNull", "isQuery", "isList", "isEdit", "comment", "dictKey"}; 48 | 49 | /** 50 | * Create the wizard. 51 | */ 52 | public PageThree() { 53 | super("PageThree"); 54 | setTitle("设置字段信息"); 55 | setDescription("设置字段信息"); 56 | } 57 | 58 | public TableViewer getTableViewer() { 59 | return tableViewer; 60 | } 61 | 62 | public List getColumnList() { 63 | return columnList; 64 | } 65 | 66 | /** 67 | * Create contents of the wizard. 68 | * 69 | * @param parent 70 | */ 71 | public void createControl(Composite parent) { 72 | Composite container = new Composite(parent, SWT.NULL); 73 | 74 | setControl(container); 75 | container.setLayout(new BorderLayout(3, 0)); 76 | 77 | Composite composite = new Composite(container, SWT.BORDER); 78 | composite.setLayoutData(BorderLayout.EAST); 79 | composite.setLayout(new GridLayout(1, false)); 80 | 81 | ToolBar toolBar = new ToolBar(composite, SWT.FLAT | SWT.RIGHT 82 | | SWT.VERTICAL); 83 | 84 | ToolItem tbiUp = new ToolItem(toolBar, SWT.NONE); 85 | tbiUp.setImage(ResourceManager.getPluginImage( 86 | "com.thinkgem.jeesite.autocode", "icons/up.png")); 87 | 88 | ToolItem tbiDown = new ToolItem(toolBar, SWT.NONE); 89 | tbiDown.setImage(ResourceManager.getPluginImage( 90 | "com.thinkgem.jeesite.autocode", "icons/down.png")); 91 | 92 | Composite composite_1 = new Composite(container, SWT.BORDER); 93 | composite_1.setLayoutData(BorderLayout.CENTER); 94 | composite_1.setLayout(new GridLayout(1, false)); 95 | 96 | tableViewer = new TableViewer(composite_1, SWT.BORDER 97 | | SWT.FULL_SELECTION); 98 | tableViewer.setColumnProperties(columnNames); 99 | columnsTable = tableViewer.getTable(); 100 | columnsTable.setHeaderVisible(true); 101 | columnsTable.setLinesVisible(true); 102 | columnsTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 103 | 1, 1)); 104 | 105 | TableColumn tc1 = new TableColumn(columnsTable, SWT.CENTER, 0); 106 | tc1.setText("列名"); //$NON-NLS-1$ 107 | TableColumn tc2 = new TableColumn(columnsTable, SWT.CENTER, 1); 108 | tc2.setText("属性名"); //$NON-NLS-1$ 109 | TableColumn tc3 = new TableColumn(columnsTable, SWT.LEFT, 2); 110 | tc3.setText("说明"); //$NON-NLS-1$ 111 | TableColumn tc4 = new TableColumn(columnsTable, SWT.CENTER, 3); 112 | tc4.setText("主键"); //$NON-NLS-1$ 113 | TableColumn tc5 = new TableColumn(columnsTable, SWT.CENTER, 4); 114 | tc5.setText("列表"); //$NON-NLS-1$ 115 | TableColumn tc6 = new TableColumn(columnsTable, SWT.CENTER, 5); 116 | tc6.setText("查询"); //$NON-NLS-1$ 117 | TableColumn tc7 = new TableColumn(columnsTable, SWT.CENTER, 6); 118 | tc7.setText("修改"); //$NON-NLS-1$ 119 | TableColumn tc8 = new TableColumn(columnsTable, SWT.CENTER, 7); 120 | tc8.setText("参数"); //$NON-NLS-1$ 121 | 122 | tc1.setWidth(140); 123 | tc2.setWidth(90); 124 | tc3.setWidth(200); 125 | tc4.setWidth(70); 126 | tc5.setWidth(70); 127 | tc6.setWidth(70); 128 | tc7.setWidth(70); 129 | tc8.setWidth(70); 130 | 131 | CellEditor[] editors = new CellEditor[columnNames.length]; 132 | editors[0] = new TextCellEditor(columnsTable, SWT.READ_ONLY); 133 | editors[1] = new TextCellEditor(columnsTable); 134 | editors[2] = new TextCellEditor(columnsTable); 135 | editors[3] = new CheckboxCellEditor(columnsTable); 136 | editors[4] = new CheckboxCellEditor(columnsTable); 137 | editors[5] = new CheckboxCellEditor(columnsTable); 138 | editors[6] = new CheckboxCellEditor(columnsTable); 139 | editors[7] = new TextCellEditor(columnsTable); 140 | tableViewer.setCellEditors(editors); 141 | 142 | tableViewer.setLabelProvider(new ColumnLabelProvider()); 143 | tableViewer.setContentProvider(new ColumnContentProvider()); 144 | tableViewer.setCellModifier(new ColumnCellModifier(this,this.columnNames)); 145 | tableViewer.setInput(columnList); 146 | } 147 | 148 | public void onEnterPage() { 149 | StartMsWizard wizard = (StartMsWizard) super.getWizard(); 150 | PageOne pageOne = (PageOne) wizard.getPage("PageOne"); 151 | PageTwo pageTwo = (PageTwo) wizard.getPage("PageTwo"); 152 | TableModel table = wizard.getTableModel(); 153 | columnList = AutoCodeDbUtils.getColumnList(pageOne.getDs(),table.getName()); 154 | tableViewer.refresh(); 155 | } 156 | 157 | 158 | class ColumnContentProvider implements IStructuredContentProvider { 159 | 160 | public void dispose() { 161 | } 162 | 163 | public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 164 | 165 | } 166 | 167 | public Object[] getElements(Object inputElement) { 168 | return columnList.toArray(); 169 | } 170 | } 171 | } 172 | 173 | /** 174 | * LABEL 提供者 175 | * 176 | */ 177 | class ColumnLabelProvider extends LabelProvider implements ITableLabelProvider { 178 | 179 | // Names of images used to represent checkboxes 180 | public static final String CHECKED_IMAGE = "checked"; 181 | public static final String UNCHECKED_IMAGE = "unchecked"; 182 | 183 | private static ImageRegistry imageRegistry = new ImageRegistry(); 184 | 185 | static { 186 | String iconPath = "icons/"; 187 | imageRegistry.put(CHECKED_IMAGE, ResourceManager.getPluginImage("com.thinkgem.jeesite.autocode", "icons/checked.png")); 188 | imageRegistry.put(UNCHECKED_IMAGE, ResourceManager.getPluginImage("com.thinkgem.jeesite.autocode", "icons/unchecked.png")); 189 | } 190 | 191 | /** 192 | * Returns the image with the given key, or null if not found. 193 | */ 194 | private Image getImage(boolean isSelected) { 195 | String key = isSelected ? CHECKED_IMAGE : UNCHECKED_IMAGE; 196 | return imageRegistry.get(key); 197 | } 198 | 199 | /* 200 | * (non-Javadoc) 201 | * 202 | * @see 203 | * org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang 204 | * .Object, int) 205 | */ 206 | public Image getColumnImage(Object element, int columnIndex) { 207 | ColumnModel col = (ColumnModel) element; 208 | 209 | Image result = null; 210 | 211 | switch (columnIndex) { 212 | case 3: 213 | result = getImage("Y".equalsIgnoreCase(col.getIsParamKey())); 214 | break; 215 | case 4: 216 | result = getImage("Y".equalsIgnoreCase(col.getIsList())); 217 | break; 218 | case 5: 219 | result = getImage("Y".equalsIgnoreCase(col.getIsQuery())); 220 | break; 221 | case 6: 222 | result = getImage("Y".equalsIgnoreCase(col.getIsEdit())); 223 | break; 224 | default: 225 | break; 226 | } 227 | return result; 228 | } 229 | 230 | public String getColumnText(Object element, int columnIndex) { 231 | String result = ""; 232 | ColumnModel col = (ColumnModel) element; 233 | switch (columnIndex) { 234 | case 0: 235 | result = col.getColumnName(); 236 | break; 237 | case 1: 238 | result = col.getJavaName(); 239 | break; 240 | case 2: 241 | result = col.getComment() == null ? "" : col.getComment(); 242 | break; 243 | case 7: 244 | result = col.getDictKey(); 245 | break; 246 | default: 247 | break; 248 | } 249 | return result; 250 | } 251 | 252 | } 253 | 254 | class ColumnCellModifier implements ICellModifier { 255 | PageThree pageThree; 256 | List columnNames; 257 | 258 | public ColumnCellModifier(PageThree pageThree, String[] columnNames) { 259 | this.pageThree = pageThree; 260 | this.columnNames = Arrays.asList(columnNames); 261 | } 262 | 263 | public boolean canModify(Object element, String property) { 264 | return true; 265 | } 266 | 267 | public Object getValue(Object element, String property) { 268 | int columnIndex = columnNames.indexOf(property); 269 | 270 | Object result = null; 271 | 272 | ColumnModel col = (ColumnModel) element; 273 | switch (columnIndex) { 274 | case 0: 275 | result = col.getColumnName(); 276 | break; 277 | case 1: 278 | result = col.getJavaName(); 279 | break; 280 | case 2: 281 | result = col.getComment(); 282 | break; 283 | case 3: 284 | result = new Boolean(!"Y".equals(col.getIsParamKey())); 285 | break; 286 | case 4: 287 | result = new Boolean(!"Y".equals(col.getIsList())); 288 | break; 289 | case 5: 290 | result = new Boolean(!"Y".equals(col.getIsQuery())); 291 | break; 292 | case 6: 293 | result = new Boolean(!"Y".equals(col.getIsEdit())); 294 | break; 295 | case 7: 296 | result = col.getDictKey(); 297 | break; 298 | default: 299 | result = ""; 300 | } 301 | return result; 302 | } 303 | 304 | public void modify(Object element, String property, Object value) { 305 | int columnIndex = columnNames.indexOf(property); 306 | TableItem item = (TableItem) element; 307 | ColumnModel col = (ColumnModel)item.getData(); 308 | switch (columnIndex) { 309 | case 0: 310 | col.setColumnName(StringUtils.trim((String)value)); 311 | break; 312 | case 1: 313 | col.setJavaName(StringUtils.trim((String)value)); 314 | break; 315 | case 2: 316 | col.setComment(StringUtils.trim((String)value)); 317 | break; 318 | case 3: 319 | col.setIsParamKey(((Boolean) value).booleanValue()?"N":"Y"); 320 | break; 321 | case 4: 322 | col.setIsList(((Boolean) value).booleanValue()?"N":"Y"); 323 | break; 324 | case 5: 325 | col.setIsQuery(((Boolean) value).booleanValue()?"N":"Y"); 326 | break; 327 | case 6: 328 | col.setIsEdit(((Boolean) value).booleanValue()?"N":"Y"); 329 | break; 330 | case 7: 331 | col.setDictKey(StringUtils.trim((String)value)); 332 | break; 333 | default: 334 | //result = ""; 335 | } 336 | 337 | this.pageThree.getTableViewer().update(col, null); 338 | } 339 | 340 | } -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/ms/StartMsWizard.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.ms; 2 | 3 | import java.io.File; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.eclipse.jface.dialogs.MessageDialog; 8 | import org.eclipse.jface.wizard.Wizard; 9 | 10 | import com.thinkgem.jeesite.autocode.model.TableConfigModel; 11 | import com.thinkgem.jeesite.autocode.model.TableModel; 12 | import com.thinkgem.jeesite.autocode.util.FreeMakerUtils; 13 | import com.thinkgem.jeesite.autocode.util.StringUtils; 14 | import com.thinkgem.jeesite.autocode.util.XmlObjectCrud; 15 | import com.thinkgem.jeesite.autocode.util.XmlObjectUtils; 16 | 17 | import freemarker.template.Configuration; 18 | 19 | /** 20 | * 主从表代码生成 21 | */ 22 | public class StartMsWizard extends Wizard { 23 | //所有全局变量防止在这里 24 | 25 | TableModel tableModel = new TableModel(); 26 | 27 | public StartMsWizard() { 28 | setWindowTitle("树状机构生成"); 29 | setHelpAvailable(false); 30 | setNeedsProgressMonitor(false); 31 | } 32 | 33 | @Override 34 | public void addPages() { 35 | addPage(new PageOne()); 36 | addPage(new PageTwo()); 37 | addPage(new PageThree()); 38 | 39 | //设置上一次操作的路径 40 | TableConfigModel fileconfig = (TableConfigModel)XmlObjectUtils.objectXmlDecoder(XmlObjectCrud.getLeastTable()); 41 | if(fileconfig!=null){ 42 | PageTwo pageTwo = (PageTwo)super.getPage("PageTwo"); 43 | TableConfigModel pttable = pageTwo.getTableConfig(); 44 | pttable.setAuthor(fileconfig.getAuthor()); 45 | pttable.setVersion(fileconfig.getVersion()); 46 | pttable.setTopPackage(fileconfig.getTopPackage()); 47 | pttable.setFilePath(fileconfig.getFilePath()); 48 | pttable.setJspLocation(fileconfig.getJspLocation()); 49 | pttable.setFunctionNameCn(fileconfig.getFunctionNameCn()); 50 | pttable.setFunctionNameEn(fileconfig.getFunctionNameEn()); 51 | pttable.setUrlPrefix(fileconfig.getUrlPrefix()); 52 | } 53 | } 54 | 55 | @Override 56 | public boolean performFinish() { 57 | PageTwo pageTwo = (PageTwo)super.getPage("PageTwo"); 58 | pageTwo.checkInput(); 59 | 60 | TableConfigModel tableconfig = pageTwo.getTableConfig(); 61 | 62 | PageThree pageThree = (PageThree)super.getPage("PageThree"); 63 | XmlObjectUtils.objectXmlEncoder(pageThree.getColumnList(), XmlObjectCrud.getLeastColumns()); 64 | XmlObjectUtils.objectXmlEncoder(tableconfig,XmlObjectCrud.getLeastTable()); 65 | 66 | Map data = new HashMap(); 67 | data.put("columnList", pageThree.getColumnList()); 68 | data.put("table", tableconfig); 69 | 70 | 71 | String separator = File.separator; 72 | String basePath = pageTwo.getTableConfig().getFilePath(); 73 | 74 | //生成文件 75 | //Configuration freemakerCfg = FreeMakerUtils.getFreeMarkerCfg(this.getClass(), "template"); 76 | 77 | Configuration freemakerCfg = FreeMakerUtils.getFreeMarkerCfg(XmlObjectCrud.getFtlPath()); 78 | FreeMakerUtils.generateFile(freemakerCfg, "entity.ftl", data, "src\\main\\java\\"+StringUtils.replace(tableconfig.getTopPackage(), ".", "\\") + "\\entity\\", StringUtils.capitalize(tableconfig.getTableJavaName()) +".java", basePath); 79 | 80 | MessageDialog.openInformation(super.getShell(), "代码生成成功", "代码生成成功,生成代码存放路径:"+tableconfig.getFilePath()); 81 | return true; 82 | } 83 | 84 | 85 | 86 | public void setTableModel(String name,String comment){ 87 | tableModel.setName(name); 88 | tableModel.setComment(comment); 89 | } 90 | 91 | public TableModel getTableModel() { 92 | return tableModel; 93 | } 94 | 95 | @Override 96 | public boolean canFinish() { 97 | if("PageThree".equals(super.getContainer().getCurrentPage().getName())){ 98 | return true; 99 | }else{ 100 | return false; 101 | } 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/ms/template/controller.ftl: -------------------------------------------------------------------------------- 1 | /** 2 | * There are JeeSite code generation 3 | */ 4 | package ${packageName}.${moduleName}.web${subModuleName}; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | import javax.servlet.http.HttpServletResponse; 8 | 9 | import org.apache.shiro.authz.annotation.RequiresPermissions; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Controller; 12 | import org.springframework.ui.Model; 13 | import org.springframework.web.bind.annotation.ModelAttribute; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | import org.springframework.web.bind.annotation.RequestParam; 16 | import org.springframework.web.servlet.mvc.support.RedirectAttributes; 17 | 18 | import com.thinkgem.jeesite.common.config.Global; 19 | import com.thinkgem.jeesite.common.persistence.Page; 20 | import com.thinkgem.jeesite.common.web.BaseController; 21 | import com.thinkgem.jeesite.modules.sys.entity.User; 22 | import com.thinkgem.jeesite.modules.sys.utils.UserUtils; 23 | import ${packageName}.${moduleName}.entity${subModuleName}.${ClassName}; 24 | import ${packageName}.${moduleName}.service${subModuleName}.${ClassName}Service; 25 | 26 | /** 27 | * ${functionName}Controller 28 | * @author ${classAuthor} 29 | * @version ${classVersion} 30 | */ 31 | @Controller 32 | @RequestMapping(value = Global.ADMIN_PATH+"/${urlPrefix}") 33 | public class ${ClassName}Controller extends BaseController { 34 | 35 | @Autowired 36 | private ${ClassName}Service ${className}Service; 37 | 38 | @ModelAttribute 39 | public ${ClassName} get(@RequestParam(required=false) Long id) { 40 | if (id != null){ 41 | return ${className}Service.get(id); 42 | }else{ 43 | return new ${ClassName}(); 44 | } 45 | } 46 | 47 | @RequiresPermissions("${permissionPrefix}:view") 48 | @RequestMapping(value = {"list", ""}) 49 | public String list(${ClassName} ${className}, HttpServletRequest request, HttpServletResponse response, Model model) { 50 | User user = UserUtils.getUser(); 51 | if (!user.isAdmin()){ 52 | ${className}.setUser(user); 53 | } 54 | Page<${ClassName}> page = ${className}Service.find(new Page<${ClassName}>(request, response), ${className}); 55 | model.addAttribute("page", page); 56 | return "${viewPrefix}List"; 57 | } 58 | 59 | @RequiresPermissions("${permissionPrefix}:view") 60 | @RequestMapping(value = "form") 61 | public String form(${ClassName} ${className}, Model model) { 62 | model.addAttribute("${className}", ${className}); 63 | return "${viewPrefix}Form"; 64 | } 65 | 66 | @RequiresPermissions("${permissionPrefix}:edit") 67 | @RequestMapping(value = "save") 68 | public String save(${ClassName} ${className}, Model model, RedirectAttributes redirectAttributes) { 69 | if (!beanValidator(model, ${className})){ 70 | return form(${className}, model); 71 | } 72 | ${className}Service.save(${className}); 73 | addMessage(redirectAttributes, "保存${functionName}'" + ${className}.getName() + "'成功"); 74 | return "redirect:"+Global.ADMIN_PATH+"/${viewPrefix}/?repage"; 75 | } 76 | 77 | @RequiresPermissions("${permissionPrefix}:edit") 78 | @RequestMapping(value = "delete") 79 | public String delete(Long id, RedirectAttributes redirectAttributes) { 80 | ${className}Service.delete(id); 81 | addMessage(redirectAttributes, "删除${functionName}成功"); 82 | return "redirect:"+Global.ADMIN_PATH+"/${viewPrefix}/?repage"; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/ms/template/dao.ftl: -------------------------------------------------------------------------------- 1 | /** 2 | * There are JeeSite code generation 3 | */ 4 | package ${packageName}.${moduleName}.dao${subModuleName}; 5 | 6 | import org.springframework.data.jpa.repository.Modifying; 7 | import org.springframework.data.jpa.repository.Query; 8 | import org.springframework.data.repository.CrudRepository; 9 | import org.springframework.stereotype.Component; 10 | 11 | import com.thinkgem.jeesite.common.persistence.BaseDao; 12 | import com.thinkgem.jeesite.common.persistence.BaseDaoImpl; 13 | import ${packageName}.${moduleName}.entity${subModuleName}.${ClassName}; 14 | 15 | /** 16 | * ${functionName}DAO接口 17 | * @author ${classAuthor} 18 | * @version ${classVersion} 19 | */ 20 | public interface ${ClassName}Dao extends ${ClassName}DaoCustom, CrudRepository<${ClassName}, Long> { 21 | 22 | @Modifying 23 | @Query("update ${ClassName} set delFlag='" + ${ClassName}.DEL_FLAG_DELETE + "' where id = ?1") 24 | public int deleteById(Long id); 25 | 26 | } 27 | 28 | /** 29 | * DAO自定义接口 30 | * @author ${classAuthor} 31 | */ 32 | interface ${ClassName}DaoCustom extends BaseDao<${ClassName}> { 33 | 34 | } 35 | 36 | /** 37 | * DAO自定义接口实现 38 | * @author ${classAuthor} 39 | */ 40 | @Component 41 | class ${ClassName}DaoImpl extends BaseDaoImpl<${ClassName}> implements ${ClassName}DaoCustom { 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/ms/template/entity.ftl: -------------------------------------------------------------------------------- 1 | table属性 2 | ${table} 3 | 4 | table所有列属性 5 | <#list columnList as x> 6 | ${x} 7 | 8 | 9 | /** 10 | * There are JeeSite code generation 11 | */ 12 | package ${table.topPackage}.entity.${table.tableJavaName} 13 | 14 | import java.util.Date; 15 | 16 | import javax.persistence.Entity; 17 | import javax.persistence.GeneratedValue; 18 | import javax.persistence.GenerationType; 19 | import javax.persistence.Id; 20 | import javax.persistence.JoinColumn; 21 | import javax.persistence.ManyToOne; 22 | import javax.persistence.Table; 23 | import javax.validation.constraints.NotNull; 24 | 25 | import org.hibernate.annotations.Cache; 26 | import org.hibernate.annotations.CacheConcurrencyStrategy; 27 | import org.hibernate.annotations.NotFound; 28 | import org.hibernate.annotations.NotFoundAction; 29 | import org.hibernate.validator.constraints.Length; 30 | 31 | import com.thinkgem.jeesite.common.persistence.BaseEntity; 32 | import com.thinkgem.jeesite.modules.sys.entity.User; 33 | 34 | 35 | /** 36 | * ${table.tableComment}Entity 37 | * @author ${table.author} 38 | * @version ${table.version} 39 | */ 40 | @Entity 41 | @Table(name = "${table.tableName}") 42 | @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) 43 | public class ${table.tableJavaName} extends BaseEntity { 44 | 45 | <#list columnList as x> 46 | /** 47 | * <#if x.comment??>${x.comment} 48 | **/ 49 | private ${x.javaType} ${x.javaName}; 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/ms/template/service.ftl: -------------------------------------------------------------------------------- 1 | /** 2 | * There are JeeSite code generation 3 | */ 4 | package ${packageName}.${moduleName}.service${subModuleName}; 5 | 6 | import org.apache.commons.lang3.StringUtils; 7 | import org.hibernate.criterion.DetachedCriteria; 8 | import org.hibernate.criterion.Order; 9 | import org.hibernate.criterion.Restrictions; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.stereotype.Component; 14 | import org.springframework.transaction.annotation.Transactional; 15 | 16 | import com.thinkgem.jeesite.common.persistence.Page; 17 | import com.thinkgem.jeesite.common.service.BaseService; 18 | import ${packageName}.${moduleName}.entity${subModuleName}.${ClassName}; 19 | import ${packageName}.${moduleName}.dao${subModuleName}.${ClassName}Dao; 20 | 21 | /** 22 | * ${functionName}Service 23 | * @author ${classAuthor} 24 | * @version ${classVersion} 25 | */ 26 | @Component 27 | @Transactional(readOnly = true) 28 | public class ${ClassName}Service extends BaseService { 29 | 30 | @SuppressWarnings("unused") 31 | private static Logger logger = LoggerFactory.getLogger(${ClassName}Service.class); 32 | 33 | @Autowired 34 | private ${ClassName}Dao ${className}Dao; 35 | 36 | public ${ClassName} get(Long id) { 37 | return ${className}Dao.findOne(id); 38 | } 39 | 40 | public Page<${ClassName}> find(Page<${ClassName}> page, ${ClassName} ${className}) { 41 | DetachedCriteria dc = ${className}Dao.createDetachedCriteria(); 42 | if (${className}.getUser()!=null && ${className}.getUser().getId()>0){ 43 | dc.add(Restrictions.eq("user.id", ${className}.getUser().getId())); 44 | } 45 | if (StringUtils.isNotEmpty(${className}.getName())){ 46 | dc.add(Restrictions.like("name", "%"+${className}.getName()+"%")); 47 | } 48 | if (StringUtils.isNotEmpty(${className}.getRemarks())){ 49 | dc.add(Restrictions.like("remarks", "%"+${className}.getRemarks()+"%")); 50 | } 51 | dc.add(Restrictions.eq("delFlag", ${ClassName}.DEL_FLAG_NORMAL)); 52 | dc.addOrder(Order.desc("id")); 53 | return ${className}Dao.find(page, dc); 54 | } 55 | 56 | @Transactional(readOnly = false) 57 | public void save(${ClassName} ${className}) { 58 | ${className}Dao.save(${className}); 59 | } 60 | 61 | @Transactional(readOnly = false) 62 | public void delete(Long id) { 63 | ${className}Dao.deleteById(id); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/ms/template/viewForm.ftl: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" %> 2 | <%@ include file="/WEB-INF/views/include/taglib.jsp"%> 3 | 4 | 5 | ${functionName}管理 6 | 7 | 27 | 28 | 29 |
33 | 34 | 35 | 36 |
37 | 38 |
39 | 40 |
41 |
42 |
43 | 44 |
45 | 46 |
47 |
48 |
49 |   50 | 51 |
52 |
53 | 54 | 55 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/ms/template/viewList.ftl: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" %> 2 | <%@ include file="/WEB-INF/views/include/taglib.jsp"%> 3 | 4 | 5 | ${functionName}管理 6 | 7 | 18 | 19 | 20 | 24 | 25 | 26 | 27 | 28 |   29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 42 | 43 | 44 | 45 |
名称备注操作
${"${"+className+".name}"}${"${"+className+".remarks}"} 39 | 修改 40 | 删除 41 |
46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/report/PageOne.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.report; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.eclipse.core.databinding.DataBindingContext; 6 | import org.eclipse.core.databinding.beans.BeansObservables; 7 | import org.eclipse.core.databinding.observable.list.WritableList; 8 | import org.eclipse.core.databinding.observable.map.IObservableMap; 9 | import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; 10 | import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; 11 | import org.eclipse.jface.viewers.IStructuredSelection; 12 | import org.eclipse.jface.viewers.TableViewer; 13 | import org.eclipse.jface.wizard.IWizardPage; 14 | import org.eclipse.jface.wizard.WizardPage; 15 | import org.eclipse.swt.SWT; 16 | import org.eclipse.swt.custom.SashForm; 17 | import org.eclipse.swt.events.SelectionAdapter; 18 | import org.eclipse.swt.events.SelectionEvent; 19 | import org.eclipse.swt.layout.FillLayout; 20 | import org.eclipse.swt.layout.GridData; 21 | import org.eclipse.swt.layout.GridLayout; 22 | import org.eclipse.swt.widgets.Composite; 23 | import org.eclipse.swt.widgets.Label; 24 | import org.eclipse.swt.widgets.List; 25 | import org.eclipse.swt.widgets.Table; 26 | import org.eclipse.swt.widgets.TableColumn; 27 | import org.eclipse.wb.swt.SWTResourceManager; 28 | 29 | import com.thinkgem.jeesite.autocode.model.DataSource; 30 | import com.thinkgem.jeesite.autocode.model.TableModel; 31 | import com.thinkgem.jeesite.autocode.util.AutoCodeDbUtils; 32 | import com.thinkgem.jeesite.autocode.util.SQLFormatter; 33 | import com.thinkgem.jeesite.autocode.util.StringUtils; 34 | import com.thinkgem.jeesite.autocode.util.XmlObjectUtils; 35 | import org.eclipse.wb.swt.ResourceManager; 36 | import org.eclipse.swt.widgets.Text; 37 | import org.eclipse.swt.widgets.Button; 38 | import org.eclipse.swt.events.KeyAdapter; 39 | import org.eclipse.swt.events.KeyEvent; 40 | import org.eclipse.swt.events.ModifyListener; 41 | import org.eclipse.swt.events.ModifyEvent; 42 | import org.eclipse.core.databinding.observable.value.IObservableValue; 43 | import org.eclipse.jface.databinding.swt.SWTObservables; 44 | import org.eclipse.core.databinding.beans.PojoObservables; 45 | 46 | public class PageOne extends WizardPage { 47 | private DataBindingContext m_bindingContext; 48 | 49 | private java.util.List dataSourceList = new ArrayList(); 50 | 51 | private List connList = null; 52 | 53 | private DataSource ds; 54 | 55 | private String sql = ""; 56 | 57 | private Text txtSql; 58 | 59 | private void updateButtons(){ 60 | getWizard().getContainer().updateButtons(); 61 | } 62 | 63 | /** 64 | * Create the wizard. 65 | */ 66 | public PageOne() { 67 | super("PageOne"); 68 | setTitle("根据SQL生成报表"); 69 | setDescription("选择数据源,输入可以运行的SQL语句"); 70 | } 71 | 72 | /** 73 | * Create contents of the wizard. 74 | * @param parent 75 | */ 76 | public void createControl(Composite parent) { 77 | Composite container = new Composite(parent, SWT.NULL); 78 | 79 | setControl(container); 80 | container.setLayout(new FillLayout(SWT.HORIZONTAL)); 81 | 82 | SashForm sashForm = new SashForm(container, SWT.NONE); 83 | 84 | Composite composite = new Composite(sashForm, SWT.BORDER); 85 | composite.setLayout(new GridLayout(1, false)); 86 | 87 | Label lblNewLabel = new Label(composite, SWT.SHADOW_NONE | SWT.CENTER); 88 | lblNewLabel.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.BOLD)); 89 | lblNewLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 90 | lblNewLabel.setText("选择数据源"); 91 | 92 | connList = new List(composite, SWT.BORDER); 93 | connList.addSelectionListener(new SelectionAdapter() { 94 | @Override 95 | public void widgetSelected(SelectionEvent e) { 96 | //更新表列表 97 | ds = (DataSource)dataSourceList.get(connList.getSelectionIndex()); 98 | updateButtons(); 99 | } 100 | }); 101 | GridData gd_connList = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); 102 | gd_connList.heightHint = 400; 103 | connList.setLayoutData(gd_connList); 104 | 105 | Composite composite_1 = new Composite(sashForm, SWT.BORDER); 106 | composite_1.setLayout(new GridLayout(1, false)); 107 | 108 | Label lblNewLabel_1 = new Label(composite_1, SWT.HORIZONTAL); 109 | lblNewLabel_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 110 | lblNewLabel_1.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.BOLD)); 111 | lblNewLabel_1.setText("输入SQL语句"); 112 | 113 | txtSql = new Text(composite_1, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI); 114 | txtSql.addModifyListener(new ModifyListener() { 115 | public void modifyText(ModifyEvent e) { 116 | updateButtons(); 117 | } 118 | }); 119 | 120 | txtSql.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); 121 | 122 | Button btnsql = new Button(composite_1, SWT.NONE); 123 | btnsql.addSelectionListener(new SelectionAdapter() { 124 | @Override 125 | public void widgetSelected(SelectionEvent e) { 126 | //格式化SQL 127 | String newsql = SQLFormatter.formatSql(txtSql.getText()); 128 | txtSql.setText(newsql); 129 | } 130 | }); 131 | btnsql.setText("格式化SQL"); 132 | 133 | java.util.List tmp = (java.util.List)XmlObjectUtils.objectXmlDecoder(XmlObjectUtils.getDataSourceFileName()); 134 | if(tmp != null){ 135 | dataSourceList = tmp; 136 | } 137 | 138 | String[] connItems = new String[dataSourceList.size()]; 139 | for (int i = 0; i < dataSourceList.size(); i++) { 140 | DataSource ds = (DataSource) dataSourceList.get(i); 141 | connItems[i] = ds.getName(); 142 | } 143 | connList.setItems(connItems); 144 | sashForm.setWeights(new int[] {206, 427}); 145 | 146 | m_bindingContext = initDataBindings(); 147 | } 148 | 149 | @Override 150 | public IWizardPage getNextPage() { 151 | //设置表信息 152 | StartReportWizard wizard = (StartReportWizard)super.getWizard(); 153 | 154 | //设置列信息 155 | PageThree pageThree = (PageThree)wizard.getPage("PageThree"); 156 | pageThree.onEnterPage(); 157 | 158 | return super.getNextPage(); 159 | } 160 | 161 | @Override 162 | public boolean canFlipToNextPage() { 163 | if(ds!=null&&StringUtils.isNotBlank(txtSql.getText())){ 164 | return true; 165 | } 166 | return false; 167 | } 168 | 169 | public DataSource getDs() { 170 | return ds; 171 | } 172 | 173 | public String getSql() { 174 | return sql; 175 | } 176 | 177 | public void setSql(String sql) { 178 | this.sql = sql; 179 | } 180 | protected DataBindingContext initDataBindings() { 181 | DataBindingContext bindingContext = new DataBindingContext(); 182 | // 183 | IObservableValue txtSqlObserveTextObserveWidget = SWTObservables.observeText(txtSql, SWT.Modify); 184 | IObservableValue sqlEmptyObserveValue = PojoObservables.observeValue(this, "sql"); 185 | bindingContext.bindValue(txtSqlObserveTextObserveWidget, sqlEmptyObserveValue, null, null); 186 | // 187 | return bindingContext; 188 | } 189 | } 190 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/report/StartReportWizard.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.report; 2 | 3 | import java.io.File; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.eclipse.jface.dialogs.MessageDialog; 8 | import org.eclipse.jface.wizard.Wizard; 9 | 10 | import com.thinkgem.jeesite.autocode.model.TableConfigModel; 11 | import com.thinkgem.jeesite.autocode.model.TableModel; 12 | import com.thinkgem.jeesite.autocode.util.FreeMakerUtils; 13 | import com.thinkgem.jeesite.autocode.util.StringUtils; 14 | import com.thinkgem.jeesite.autocode.util.XmlObjectReport; 15 | import com.thinkgem.jeesite.autocode.util.XmlObjectTree; 16 | import com.thinkgem.jeesite.autocode.util.XmlObjectUtils; 17 | 18 | import freemarker.template.Configuration; 19 | 20 | public class StartReportWizard extends Wizard { 21 | //所有全局变量防止在这里 22 | 23 | TableModel tableModel = new TableModel(); 24 | 25 | public StartReportWizard() { 26 | setWindowTitle("增删改查操作类"); 27 | setHelpAvailable(false); 28 | setNeedsProgressMonitor(false); 29 | } 30 | 31 | @Override 32 | public void addPages() { 33 | addPage(new PageOne()); 34 | addPage(new PageTwo()); 35 | addPage(new PageThree()); 36 | 37 | //设置上一次操作的路径 38 | TableConfigModel fileconfig = (TableConfigModel)XmlObjectUtils.objectXmlDecoder(XmlObjectTree.getLeastTable()); 39 | if(fileconfig!=null){ 40 | PageTwo pageTwo = (PageTwo)super.getPage("PageTwo"); 41 | TableConfigModel pttable = pageTwo.getTableConfig(); 42 | pttable.setAuthor(fileconfig.getAuthor()); 43 | pttable.setVersion(fileconfig.getVersion()); 44 | pttable.setTopPackage(fileconfig.getTopPackage()); 45 | pttable.setFilePath(fileconfig.getFilePath()); 46 | pttable.setJspLocation(fileconfig.getJspLocation()); 47 | pttable.setFunctionNameCn(fileconfig.getFunctionNameCn()); 48 | pttable.setFunctionNameEn(fileconfig.getFunctionNameEn()); 49 | pttable.setUrlPrefix(fileconfig.getUrlPrefix()); 50 | } 51 | } 52 | 53 | @Override 54 | public boolean performFinish() { 55 | PageTwo pageTwo = (PageTwo)super.getPage("PageTwo"); 56 | pageTwo.checkInput(); 57 | 58 | TableConfigModel tableconfig = pageTwo.getTableConfig(); 59 | 60 | PageThree pageThree = (PageThree)super.getPage("PageThree"); 61 | XmlObjectUtils.objectXmlEncoder(pageThree.getColumnList(), XmlObjectTree.getLeastColumns()); 62 | XmlObjectUtils.objectXmlEncoder(tableconfig,XmlObjectTree.getLeastTable()); 63 | 64 | Map data = new HashMap(); 65 | data.put("columnList", pageThree.getColumnList()); 66 | data.put("table", tableconfig); 67 | 68 | 69 | String separator = File.separator; 70 | String basePath = pageTwo.getTableConfig().getFilePath(); 71 | 72 | //生成文件 73 | //Configuration freemakerCfg = FreeMakerUtils.getFreeMarkerCfg(this.getClass(), "template"); 74 | 75 | Configuration freemakerCfg = FreeMakerUtils.getFreeMarkerCfg(XmlObjectReport.getFtlPath()); 76 | FreeMakerUtils.generateFile(freemakerCfg, "entity.ftl", data, "src\\main\\java\\"+StringUtils.replace(tableconfig.getTopPackage(), ".", "\\") + "\\entity\\", StringUtils.capitalize(tableconfig.getTableJavaName()) +".java", basePath); 77 | 78 | MessageDialog.openInformation(super.getShell(), "代码生成成功", "代码生成成功,生成代码存放路径:"+tableconfig.getFilePath()); 79 | return true; 80 | } 81 | 82 | 83 | 84 | public void setTableModel(String name,String comment){ 85 | tableModel.setName(name); 86 | tableModel.setComment(comment); 87 | } 88 | 89 | public TableModel getTableModel() { 90 | return tableModel; 91 | } 92 | 93 | @Override 94 | public boolean canFinish() { 95 | if("PageThree".equals(super.getContainer().getCurrentPage().getName())){ 96 | return true; 97 | }else{ 98 | return false; 99 | } 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/tree/PageOne.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.tree; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.eclipse.core.databinding.DataBindingContext; 6 | import org.eclipse.core.databinding.beans.BeansObservables; 7 | import org.eclipse.core.databinding.observable.list.WritableList; 8 | import org.eclipse.core.databinding.observable.map.IObservableMap; 9 | import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; 10 | import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; 11 | import org.eclipse.jface.viewers.IStructuredSelection; 12 | import org.eclipse.jface.viewers.TableViewer; 13 | import org.eclipse.jface.wizard.IWizardPage; 14 | import org.eclipse.jface.wizard.WizardPage; 15 | import org.eclipse.swt.SWT; 16 | import org.eclipse.swt.custom.SashForm; 17 | import org.eclipse.swt.events.SelectionAdapter; 18 | import org.eclipse.swt.events.SelectionEvent; 19 | import org.eclipse.swt.layout.FillLayout; 20 | import org.eclipse.swt.layout.GridData; 21 | import org.eclipse.swt.layout.GridLayout; 22 | import org.eclipse.swt.widgets.Composite; 23 | import org.eclipse.swt.widgets.Label; 24 | import org.eclipse.swt.widgets.List; 25 | import org.eclipse.swt.widgets.Table; 26 | import org.eclipse.swt.widgets.TableColumn; 27 | import org.eclipse.wb.swt.SWTResourceManager; 28 | 29 | import com.thinkgem.jeesite.autocode.model.DataSource; 30 | import com.thinkgem.jeesite.autocode.model.TableModel; 31 | import com.thinkgem.jeesite.autocode.util.AutoCodeDbUtils; 32 | import com.thinkgem.jeesite.autocode.util.XmlObjectUtils; 33 | import org.eclipse.wb.swt.ResourceManager; 34 | 35 | public class PageOne extends WizardPage { 36 | private DataBindingContext m_bindingContext; 37 | private Table table; 38 | 39 | private java.util.List dataSourceList = new ArrayList(); 40 | 41 | /* 42 | * 表LIST 43 | */ 44 | private java.util.List tableList = new ArrayList(); 45 | 46 | private List connList = null; 47 | 48 | private TableViewer tableViewer; 49 | 50 | private DataSource ds; 51 | 52 | private void updateButtons(){ 53 | getWizard().getContainer().updateButtons(); 54 | } 55 | 56 | /** 57 | * Create the wizard. 58 | */ 59 | public PageOne() { 60 | super("PageOne"); 61 | setTitle("树状结构数据生成"); 62 | setDescription("请选择数据库连接,模板文件位于:"); 63 | } 64 | 65 | /** 66 | * Create contents of the wizard. 67 | * @param parent 68 | */ 69 | public void createControl(Composite parent) { 70 | Composite container = new Composite(parent, SWT.NULL); 71 | 72 | setControl(container); 73 | container.setLayout(new FillLayout(SWT.HORIZONTAL)); 74 | 75 | SashForm sashForm = new SashForm(container, SWT.NONE); 76 | 77 | Composite composite = new Composite(sashForm, SWT.BORDER); 78 | composite.setLayout(new GridLayout(1, false)); 79 | 80 | Label lblNewLabel = new Label(composite, SWT.SHADOW_NONE | SWT.CENTER); 81 | lblNewLabel.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.BOLD)); 82 | lblNewLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 83 | lblNewLabel.setText("选择数据源"); 84 | 85 | connList = new List(composite, SWT.BORDER); 86 | connList.addSelectionListener(new SelectionAdapter() { 87 | @Override 88 | public void widgetSelected(SelectionEvent e) { 89 | //更新表列表 90 | ds = (DataSource)dataSourceList.get(connList.getSelectionIndex()); 91 | tableList.clear(); 92 | java.util.List tmList = AutoCodeDbUtils.getTableList(ds); 93 | for(TableModel tm:tmList){ 94 | tableList.add(tm); 95 | } 96 | tableViewer.refresh(); 97 | m_bindingContext.updateModels(); 98 | updateButtons(); 99 | } 100 | }); 101 | GridData gd_connList = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); 102 | gd_connList.heightHint = 400; 103 | connList.setLayoutData(gd_connList); 104 | 105 | Composite composite_1 = new Composite(sashForm, SWT.BORDER); 106 | composite_1.setLayout(new GridLayout(1, false)); 107 | 108 | Label lblNewLabel_1 = new Label(composite_1, SWT.HORIZONTAL); 109 | lblNewLabel_1.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1)); 110 | lblNewLabel_1.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.BOLD)); 111 | lblNewLabel_1.setText("选择表名"); 112 | 113 | tableViewer = new TableViewer(composite_1, SWT.BORDER | SWT.FULL_SELECTION); 114 | table = tableViewer.getTable(); 115 | table.addSelectionListener(new SelectionAdapter() { 116 | @Override 117 | public void widgetSelected(SelectionEvent e) { 118 | IStructuredSelection select = (IStructuredSelection)tableViewer.getSelection(); 119 | TableModel tm = (TableModel)select.getFirstElement(); 120 | setWizardTm(tm); 121 | updateButtons(); 122 | } 123 | }); 124 | table.setLinesVisible(true); 125 | table.setHeaderVisible(true); 126 | table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); 127 | 128 | TableColumn tblclmnNewColumn = new TableColumn(table, SWT.NONE); 129 | tblclmnNewColumn.setWidth(190); 130 | tblclmnNewColumn.setText("表名"); 131 | 132 | TableColumn tblclmnNewColumn_1 = new TableColumn(table, SWT.NONE); 133 | tblclmnNewColumn_1.setWidth(168); 134 | tblclmnNewColumn_1.setText("中文名称"); 135 | 136 | 137 | java.util.List tmp = (java.util.List)XmlObjectUtils.objectXmlDecoder(XmlObjectUtils.getDataSourceFileName()); 138 | if(tmp != null){ 139 | dataSourceList = tmp; 140 | } 141 | 142 | String[] connItems = new String[dataSourceList.size()]; 143 | for (int i = 0; i < dataSourceList.size(); i++) { 144 | DataSource ds = (DataSource) dataSourceList.get(i); 145 | connItems[i] = ds.getName(); 146 | } 147 | connList.setItems(connItems); 148 | sashForm.setWeights(new int[] {206, 427}); 149 | 150 | m_bindingContext = initDataBindings(); 151 | 152 | TableModel m = new TableModel(); 153 | m.setName("table"); 154 | m.setComment("comment"); 155 | tableList.add(m); 156 | 157 | } 158 | 159 | private void setWizardTm(TableModel tm){ 160 | StartTreeWizard wizard = (StartTreeWizard)super.getWizard(); 161 | wizard.setTableModel(tm.getName(), tm.getComment()); 162 | 163 | //设置表信息 164 | PageTwo pageTwo = (PageTwo)wizard.getPage("PageTwo"); 165 | pageTwo.onEnterPage(tm.getName(), tm.getComment()); 166 | 167 | //设置列信息 168 | PageThree pageThree = (PageThree)wizard.getPage("PageThree"); 169 | pageThree.onEnterPage(); 170 | } 171 | 172 | protected DataBindingContext initDataBindings() { 173 | DataBindingContext bindingContext = new DataBindingContext(); 174 | 175 | // 176 | ObservableListContentProvider listContentProvider = new ObservableListContentProvider(); 177 | IObservableMap[] observeMaps = BeansObservables.observeMaps(listContentProvider.getKnownElements(), TableModel.class, new String[]{"name", "comment"}); 178 | tableViewer.setLabelProvider(new ObservableMapLabelProvider(observeMaps)); 179 | tableViewer.setContentProvider(listContentProvider); 180 | // 181 | WritableList writableList = new WritableList(tableList, TableModel.class); 182 | tableViewer.setInput(writableList); 183 | // 184 | return bindingContext; 185 | } 186 | 187 | @Override 188 | public IWizardPage getNextPage() { 189 | return super.getNextPage(); 190 | } 191 | 192 | @Override 193 | public boolean canFlipToNextPage() { 194 | if (getErrorMessage() != null) return false; 195 | if(!tableViewer.getSelection().isEmpty()) { 196 | return true; 197 | } 198 | return false; 199 | } 200 | 201 | public DataSource getDs() { 202 | return ds; 203 | } 204 | 205 | } 206 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/tree/StartTreeWizard.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.tree; 2 | 3 | import java.io.File; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.eclipse.jface.dialogs.MessageDialog; 8 | import org.eclipse.jface.wizard.Wizard; 9 | 10 | import com.thinkgem.jeesite.autocode.model.TableConfigModel; 11 | import com.thinkgem.jeesite.autocode.model.TableModel; 12 | import com.thinkgem.jeesite.autocode.util.FreeMakerUtils; 13 | import com.thinkgem.jeesite.autocode.util.StringUtils; 14 | import com.thinkgem.jeesite.autocode.util.XmlObjectTree; 15 | import com.thinkgem.jeesite.autocode.util.XmlObjectUtils; 16 | 17 | import freemarker.template.Configuration; 18 | 19 | public class StartTreeWizard extends Wizard { 20 | //所有全局变量防止在这里 21 | 22 | TableModel tableModel = new TableModel(); 23 | 24 | public StartTreeWizard() { 25 | setWindowTitle("增删改查操作类"); 26 | setHelpAvailable(false); 27 | setNeedsProgressMonitor(false); 28 | } 29 | 30 | @Override 31 | public void addPages() { 32 | addPage(new PageOne()); 33 | addPage(new PageTwo()); 34 | addPage(new PageThree()); 35 | 36 | //设置上一次操作的路径 37 | TableConfigModel fileconfig = (TableConfigModel)XmlObjectUtils.objectXmlDecoder(XmlObjectTree.getLeastTable()); 38 | if(fileconfig!=null){ 39 | PageTwo pageTwo = (PageTwo)super.getPage("PageTwo"); 40 | TableConfigModel pttable = pageTwo.getTableConfig(); 41 | pttable.setAuthor(fileconfig.getAuthor()); 42 | pttable.setVersion(fileconfig.getVersion()); 43 | pttable.setTopPackage(fileconfig.getTopPackage()); 44 | pttable.setFilePath(fileconfig.getFilePath()); 45 | pttable.setJspLocation(fileconfig.getJspLocation()); 46 | pttable.setFunctionNameCn(fileconfig.getFunctionNameCn()); 47 | pttable.setFunctionNameEn(fileconfig.getFunctionNameEn()); 48 | pttable.setUrlPrefix(fileconfig.getUrlPrefix()); 49 | } 50 | } 51 | 52 | @Override 53 | public boolean performFinish() { 54 | PageTwo pageTwo = (PageTwo)super.getPage("PageTwo"); 55 | pageTwo.checkInput(); 56 | 57 | TableConfigModel tableconfig = pageTwo.getTableConfig(); 58 | 59 | PageThree pageThree = (PageThree)super.getPage("PageThree"); 60 | XmlObjectUtils.objectXmlEncoder(pageThree.getColumnList(), XmlObjectTree.getLeastColumns()); 61 | XmlObjectUtils.objectXmlEncoder(tableconfig,XmlObjectTree.getLeastTable()); 62 | 63 | Map data = new HashMap(); 64 | data.put("columnList", pageThree.getColumnList()); 65 | data.put("table", tableconfig); 66 | 67 | 68 | String separator = File.separator; 69 | String basePath = pageTwo.getTableConfig().getFilePath(); 70 | 71 | //生成文件 72 | //Configuration freemakerCfg = FreeMakerUtils.getFreeMarkerCfg(this.getClass(), "template"); 73 | 74 | Configuration freemakerCfg = FreeMakerUtils.getFreeMarkerCfg(XmlObjectTree.getFtlPath()); 75 | FreeMakerUtils.generateFile(freemakerCfg, "entity.ftl", data, "src\\main\\java\\"+StringUtils.replace(tableconfig.getTopPackage(), ".", "\\") + "\\entity\\", StringUtils.capitalize(tableconfig.getTableJavaName()) +".java", basePath); 76 | 77 | MessageDialog.openInformation(super.getShell(), "代码生成成功", "代码生成成功,生成代码存放路径:"+tableconfig.getFilePath()); 78 | return true; 79 | } 80 | 81 | 82 | 83 | public void setTableModel(String name,String comment){ 84 | tableModel.setName(name); 85 | tableModel.setComment(comment); 86 | } 87 | 88 | public TableModel getTableModel() { 89 | return tableModel; 90 | } 91 | 92 | @Override 93 | public boolean canFinish() { 94 | if("PageThree".equals(super.getContainer().getCurrentPage().getName())){ 95 | return true; 96 | }else{ 97 | return false; 98 | } 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/tree/template/action.ftl: -------------------------------------------------------------------------------- 1 | package ${table.topPackage}.web; 2 | 3 | import java.util.Date; 4 | 5 | import org.apache.commons.lang.StringUtils; 6 | 7 | import com.calf.framework.util.Constants; 8 | import com.calf.framework.util.ObjectUtils; 9 | import com.calf.framework.vo.AdminUserInfo; 10 | import com.calf.framework.vo.Page; 11 | import ${table.topPackage}.entity.${table.tableJavaName?cap_first}; 12 | import ${table.topPackage}.qry.${table.functionNameEn?cap_first}Qry; 13 | import ${table.topPackage}.services.${table.functionNameEn?cap_first}Service; 14 | import com.calf.framework.web.BaseAction; 15 | import com.calf.framework.web.util.RequiresPermissions; 16 | 17 | 18 | public class ${table.functionNameEn?cap_first}Action extends BaseAction { 19 | 20 | ${table.functionNameEn?cap_first}Service ${table.functionNameEn}Service; 21 | 22 | ${table.functionNameEn?cap_first}Qry qry; 23 | 24 | Page page; 25 | 26 | ${table.tableJavaName?cap_first} entity; 27 | 28 | /** 29 | * 列表 30 | */ 31 | @RequiresPermissions(value = "${table.permissionPrefix}:view",requiresUser=true) 32 | public String list() throws Exception{ 33 | AdminUserInfo userInfo = super.getUserInfo(); 34 | if(StringUtils.isNotBlank(super.qryHex)){ 35 | qry = (${table.functionNameEn?cap_first}Qry)ObjectUtils.getObjectFromHex(qryHex); 36 | } 37 | if(qry==null){ 38 | qry = new ${table.functionNameEn?cap_first}Qry(); 39 | qry.setOrderCol("createDate"); 40 | qry.setOrderType(Constants.DESC); 41 | } 42 | 43 | //设置默认排序号 44 | if(StringUtils.isBlank(qry.getOrderCol())){ 45 | qry.setOrderCol("createDate"); 46 | qry.setOrderType(Constants.DESC); 47 | } 48 | 49 | qry.setUserInfo(userInfo); 50 | page = ${table.functionNameEn}Service.find${table.functionNameEn?cap_first}Page(qry); 51 | return "list"; 52 | } 53 | /** 54 | * 新增 55 | **/ 56 | @RequiresPermissions(value = "${table.permissionPrefix}:edit",requiresUser=true) 57 | public String toAdd() throws Exception{ 58 | AdminUserInfo userInfo = super.getUserInfo(); 59 | entity = new ${table.tableJavaName?cap_first}(); 60 | super.event="ADD"; 61 | super.title="新增"; 62 | return "edit"; 63 | } 64 | /** 65 | * 修改 66 | **/ 67 | @RequiresPermissions(value = "${table.permissionPrefix}:edit",requiresUser=true) 68 | public String toEdit() throws Exception{ 69 | AdminUserInfo userInfo = super.getUserInfo(); 70 | entity = ${table.functionNameEn}Service.get(${table.tableJavaName?cap_first}.class,entity.get${table.key.javaName?cap_first}()); 71 | super.event="EDIT"; 72 | super.title="修改"; 73 | return "edit"; 74 | } 75 | /** 76 | * 修改动作 77 | **/ 78 | @RequiresPermissions(value = "${table.permissionPrefix}:edit",requiresUser=true) 79 | public String edit() throws Exception{ 80 | AdminUserInfo userInfo = super.getUserInfo(); 81 | if("ADD".equals(super.event)){ 82 | //新增操作 83 | entity.set${table.key.javaName?cap_first}(null); 84 | entity.setDataStatus(Constants.YES); 85 | entity.setCreateUser(userInfo.getUserId()); 86 | entity.setCreateDate(new Date()); 87 | ${table.functionNameEn}Service.save${table.functionNameEn?cap_first}(entity); 88 | super.addAttribute("qry.orderCol", "createDate"); 89 | super.addAttribute("qry.orderType", "0"); 90 | super.saveMessage("${table.functionNameCn}新增成功"); 91 | }else if("EDIT".equals(super.event)){ 92 | //修改操作 93 | ${table.tableJavaName?cap_first} db = ${table.functionNameEn}Service.get(${table.tableJavaName?cap_first}.class,entity.get${table.key.javaName?cap_first}()); 94 | 95 | <#list columnList as x> 96 | <#if x.isEdit=="Y"> 97 | db.set${x.javaName?cap_first}(entity.get${x.javaName?cap_first}()); 98 | 99 | 100 | 101 | db.setUpdateUser(userInfo.getUserId()); 102 | db.setUpdateDate(new Date()); 103 | 104 | ${table.functionNameEn}Service.save${table.functionNameEn?cap_first}(db); 105 | super.saveMessage("${table.functionNameCn}修改保存成功"); 106 | super.addAttribute("qryHex", super.qryHex); 107 | } 108 | super.redirectUrl = "${table.urlPrefix}_list.action"; 109 | return super.GLOBAL_SUCCESS; 110 | } 111 | /** 112 | * 删除 113 | **/ 114 | @RequiresPermissions(value = "${table.permissionPrefix}:edit",requiresUser=true) 115 | public String delete() throws Exception{ 116 | AdminUserInfo userInfo = super.getUserInfo(); 117 | entity = ${table.functionNameEn}Service.get(${table.tableJavaName?cap_first}.class,entity.get${table.key.javaName?cap_first}()); 118 | if(entity.isCanDelete()){ 119 | this.${table.functionNameEn}Service.delete${table.functionNameEn?cap_first}(entity); 120 | super.renderJsonSuccess("删除成功!"); 121 | }else{ 122 | super.renderJsonError("该记录已被删除!"); 123 | } 124 | return null; 125 | } 126 | 127 | /** 128 | * 修改 129 | **/ 130 | @RequiresPermissions(value = "${table.permissionPrefix}:view",requiresUser=true) 131 | public String toView() throws Exception{ 132 | AdminUserInfo userInfo = super.getUserInfo(); 133 | entity = ${table.functionNameEn}Service.get(${table.tableJavaName?cap_first}.class,entity.get${table.key.javaName?cap_first}()); 134 | super.title="${table.functionNameCn}详细信息"; 135 | return "view"; 136 | } 137 | 138 | /** 139 | * 判断是否唯一 140 | * @return 141 | */ 142 | public String checkUnique()throws Exception{ 143 | AdminUserInfo userInfo = super.getUserInfo(); 144 | boolean isCorrect = ${table.functionNameEn}Service.isUnique(entity.get${table.key.javaName?cap_first}()); 145 | super.rendText(String.valueOf(isCorrect)); 146 | return null; 147 | } 148 | 149 | public ${table.functionNameEn?cap_first}Qry getQry(){ 150 | return this.qry; 151 | } 152 | public void setQry(${table.functionNameEn?cap_first}Qry qry){ 153 | this.qry = qry; 154 | } 155 | 156 | public ${table.functionNameEn?cap_first}Service get${table.functionNameEn?cap_first}Service(){ 157 | return this.${table.functionNameEn}Service; 158 | } 159 | public void set${table.functionNameEn?cap_first}Service(${table.functionNameEn?cap_first}Service ${table.functionNameEn}Service){ 160 | this.${table.functionNameEn}Service = ${table.functionNameEn}Service; 161 | } 162 | public Page getPage() { 163 | return this.page; 164 | } 165 | public void setPage(Page page) { 166 | this.page = page; 167 | } 168 | public ${table.tableJavaName?cap_first} getEntity(){ 169 | return entity; 170 | } 171 | public void setEntity(${table.tableJavaName?cap_first} entity){ 172 | this.entity = entity; 173 | } 174 | } -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/tree/template/edit.ftl: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=utf-8"%> 2 | <%@page import="com.calf.framework.util.CodeNameUtils"%> 3 | <%@ include file="/jsp/include/head.jsp"%> 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%@ include file="/jsp/include/basejs.jsp" %> 13 | 22 | 23 | 24 |
25 |
26 |
27 |
28 |
29 | 33 |
34 |
35 | 36 |
37 |
38 | 39 |
40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 54 | 55 | 56 | 57 | 58 | <#list columnList as x> 59 | <#if x.isEdit=="Y"> 60 | 61 | 62 | 71 | 72 | 73 | 74 | 75 | 76 | 77 |
<#if table.key.comment??>${table.key.comment} 51 | ${r"${entity."}${table.key.javaName}${r"}"} 52 | 53 |
<#if x.isNull!="Y"> 63 | <#if x.isParamKey!="Y"> 64 | {byteRangeLength:[0,${x.datasize}]}<#if x.isNull!="Y"> {required: true,byteRangeLength:[0,${x.datasize}],messages: {required:'请输入<#if x.comment??>${x.comment}'}}" id="${x.javaName}" value="${r"${entity."}${x.javaName}<#if x.javaType=='Double'>Str<#if x.javaType=='Date'>Str<#if x.isParamKey=="Y">Str${r"}"}"/> 65 | 66 | 67 | <#if x.dictKey!=""> 68 | <%=CodeNameUtils.getInstance().generateSelect("
78 |
79 | 80 |
81 |
82 |
83 | 84 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/tree/template/entity.ftl: -------------------------------------------------------------------------------- 1 | package ${table.topPackage}.entity; 2 | 3 | import java.util.Date; 4 | 5 | import com.calf.framework.util.DateUtil; 6 | import com.calf.framework.util.FormateUtil; 7 | 8 | public class ${table.tableJavaName?cap_first} implements java.io.Serializable { 9 | /** 10 | * 11 | */ 12 | private static final long serialVersionUID = 7210248768007789556L; 13 | 14 | <#list columnList as x> 15 | <#if x.key> 16 | /** 17 | * 主键 18 | * <#if x.comment??>${x.comment} 19 | **/ 20 | ${x.javaType} ${x.javaName}; 21 | <#else> 22 | /** 23 | * <#if x.comment??>${x.comment} 24 | **/ 25 | ${x.javaType} ${x.javaName}; 26 | 27 | 28 | 29 | public ${table.tableJavaName?cap_first}(){ 30 | } 31 | 32 | <#list columnList as x> 33 | public ${x.javaType} get${x.javaName?cap_first}(){ 34 | return this.${x.javaName}; 35 | } 36 | public void set${x.javaName?cap_first}(${x.javaType} ${x.javaName}){ 37 | this.${x.javaName} = ${x.javaName}; 38 | } 39 | 40 | 41 | <#list columnList as x> 42 | <#if x.javaType=='Double'> 43 | public String get${x.javaName?cap_first}Str(){ 44 | return FormateUtil.getInstance().formateDouble(this.${x.javaName}); 45 | } 46 | 47 | <#if x.javaType=='Date'> 48 | public String get${x.javaName?cap_first}Str(){ 49 | return DateUtil.getInstance().dateToString(this.${x.javaName},DateUtil.patternA); 50 | } 51 | 52 | 53 | 54 | <#list columnList as x> 55 | <#if x.dictKey!=""> 56 | public String get${x.javaName?cap_first}Str(){ 57 | return FormateUtil.getInstance().getNameByCode("${x.dictKey}", ${x.javaName}); 58 | } 59 | 60 | 61 | 62 | public boolean isCanDelete(){ 63 | return "1".equals(this.dataStatus); 64 | } 65 | } -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/tree/template/hbm.ftl: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | <#list columnList as x> 8 | <#if x.key> 9 | <#if x.javaType=='Long'> 10 | 11 | not-null="true"/> 12 | 13 | <#if x.javaType=='String'> 14 | 15 | not-null="true"/> 16 | 17 | 18 | SEQ_${table.seqName} 19 | 20 | 21 | <#else> 22 | 23 | 24 | <#if x.javaType=='Long'> 25 | 26 | not-null="true"/> 27 | 28 | <#if x.javaType=='String'> 29 | 30 | not-null="true"/> 31 | 32 | <#if x.javaType=='Date'> 33 | 34 | not-null="true"/> 35 | 36 | <#if x.javaType=='Double'> 37 | 38 | not-null="true"/> 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/tree/template/list.ftl: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=utf-8"%> 2 | <%@page import="com.calf.framework.util.CodeNameUtils"%> 3 | <%@page import="com.calf.framework.util.Constants"%> 4 | 5 | <%@ include file="/jsp/include/head.jsp"%> 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | <%@ include file="/jsp/include/basejs.jsp" %> 15 | 48 | 49 | 50 |
loading....
51 | 52 |
53 | 54 | 55 |
56 | 57 |
58 |
59 |
60 |
61 |
62 | 66 |
67 |
68 | 69 |
70 |
71 |
72 | 73 | 74 | 82 | 83 |
75 | <#list columnList as x> 76 | <#if x.isQuery=="Y"> 77 | 78 | 79 | 80 | 81 |
84 | 85 | 86 | 87 | 88 |
89 | 没有查询到符合条件的${table.functionNameCn} 90 |
91 |
92 | 93 | 94 | 95 | <#list columnList as x> 96 | <#if x.isList=="Y"> 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | <#list columnList as x> 105 | <#if x.isList=="Y"> 106 | 107 | 108 | 109 | 118 | 119 | 120 |
<#if x.comment??>${x.comment}操作
${r"${b."}${x.javaName}<#if x.javaType=='Double'>Str<#if x.javaType=='Date'>Str<#if x.dictKey!="">Str${r"}"} 110 | 111 | 修改  112 | 113 | 删除 114 | 115 | 116 | 查看 117 |
121 | 122 | 123 | 124 | 125 | 126 | 127 |
128 |
129 |
130 |
131 |
132 |
133 | 134 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/tree/template/qry.ftl: -------------------------------------------------------------------------------- 1 | package ${table.topPackage}.qry; 2 | 3 | import java.io.Serializable; 4 | 5 | import com.calf.framework.util.BaseAdminQuery; 6 | 7 | public class ${table.functionNameEn?cap_first}Qry extends BaseAdminQuery implements Serializable { 8 | /** 9 | * 10 | */ 11 | private static final long serialVersionUID = 1937084884877261956L; 12 | 13 | <#list columnList as x> 14 | <#if x.isQuery=="Y"> 15 | /** 16 | * <#if x.comment??>${x.comment} 17 | **/ 18 | ${x.javaType} ${x.javaName}; 19 | 20 | 21 | 22 | <#list columnList as x> 23 | <#if x.isQuery=="Y"> 24 | public ${x.javaType} get${x.javaName?cap_first}(){ 25 | return this.${x.javaName}; 26 | } 27 | public void set${x.javaName?cap_first}(${x.javaType} ${x.javaName}){ 28 | this.${x.javaName} = ${x.javaName}; 29 | } 30 | 31 | 32 | 33 | <#list columnList as x> 34 | <#if x.isQuery=="Y"> 35 | <#if x.javaType=='Double'> 36 | public String get${x.javaName?cap_first}Str(){ 37 | return FormateUtil.getInstance().formateDouble(this.${x.javaName}); 38 | } 39 | 40 | <#if x.javaType=='Date'> 41 | public String get${x.javaName?cap_first}Str(){ 42 | return DateUtil.getInstance().dateToString(this.${x.javaName},DateUtil.patternA); 43 | } 44 | 45 | 46 | 47 | } -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/tree/template/service.ftl: -------------------------------------------------------------------------------- 1 | package ${table.topPackage}.services; 2 | 3 | import java.util.List; 4 | 5 | import com.calf.framework.services.BaseService; 6 | import ${table.topPackage}.entity.${table.tableJavaName?cap_first}; 7 | import ${table.topPackage}.qry.${table.functionNameEn?cap_first}Qry; 8 | import com.calf.framework.vo.Page; 9 | 10 | public interface ${table.functionNameEn?cap_first}Service extends BaseService{ 11 | /** 12 | * 保存 13 | **/ 14 | public String save${table.functionNameEn?cap_first}(${table.tableJavaName?cap_first} entity); 15 | /** 16 | * 删除 17 | */ 18 | public String delete${table.functionNameEn?cap_first}(${table.tableJavaName?cap_first} entity); 19 | /** 20 | * 查找分页信息 21 | */ 22 | public Page find${table.functionNameEn?cap_first}Page(${table.functionNameEn?cap_first}Qry qry); 23 | 24 | /** 25 | * 判断编码是否唯一 26 | * @return 27 | */ 28 | public boolean isUnique(${table.key.javaType} ${table.key.javaName}); 29 | } -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/tree/template/serviceImpl.ftl: -------------------------------------------------------------------------------- 1 | package ${table.topPackage}.services.impl; 2 | 3 | import org.hibernate.Criteria; 4 | import org.hibernate.criterion.Restrictions; 5 | import org.springframework.stereotype.Service; 6 | 7 | import com.calf.framework.dao.CriteriaUtils; 8 | import com.calf.framework.services.impl.BaseServiceImpl; 9 | import com.calf.framework.util.Constants; 10 | import ${table.topPackage}.entity.${table.tableJavaName?cap_first}; 11 | import ${table.topPackage}.qry.${table.functionNameEn?cap_first}Qry; 12 | import com.calf.framework.vo.Page; 13 | import ${table.topPackage}.services.${table.functionNameEn?cap_first}Service; 14 | 15 | @Service("${table.functionNameEn}Service") 16 | public class ${table.functionNameEn?cap_first}ServiceImpl extends BaseServiceImpl implements ${table.functionNameEn?cap_first}Service{ 17 | /** 18 | * 查找分页信息 19 | */ 20 | public Page find${table.functionNameEn?cap_first}Page(${table.functionNameEn?cap_first}Qry qry){ 21 | Criteria criteria = hibernateDao.createCriteria(${table.tableJavaName?cap_first}.class); 22 | <#list columnList as x> 23 | <#if x.isQuery=="Y"> 24 | CriteriaUtils.addEq(criteria, "${x.javaName}", qry.get${x.javaName?cap_first}()); 25 | 26 | 27 | criteria.add(Restrictions.eq("dataStatus", Constants.YES)); 28 | CriteriaUtils.addOrder(criteria,qry.getOrderCol(),qry.getOrderType()); 29 | return super.hibernateDao.pagedQuery(criteria, qry.getPageNo(), qry.getPageSize()); 30 | } 31 | 32 | /** 33 | * 保存 34 | **/ 35 | public String save${table.functionNameEn?cap_first}(${table.tableJavaName?cap_first} entity){ 36 | super.save(entity); 37 | return null; 38 | } 39 | /** 40 | * 删除 41 | */ 42 | public String delete${table.functionNameEn?cap_first}(${table.tableJavaName?cap_first} entity){ 43 | entity.setDataStatus(Constants.NO); 44 | super.save(entity); 45 | return null; 46 | } 47 | 48 | /** 49 | * 判断编码是否唯一 50 | * @return 51 | */ 52 | public boolean isUnique(${table.key.javaType} ${table.key.javaName}){ 53 | ${table.tableJavaName?cap_first} entity = super.hibernateDao.get(${table.tableJavaName?cap_first}.class, ${table.key.javaName}); 54 | return entity==null; 55 | } 56 | } -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/tree/template/struts.ftl: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | ${table.jspLocation}/edit.jsp 13 | ${table.jspLocation}/list.jsp 14 | ${table.jspLocation}/view.jsp 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/tree/template/view.ftl: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=utf-8"%> 2 | <%@page import="com.calf.framework.util.CodeNameUtils"%> 3 | <%@ include file="/jsp/include/head.jsp"%> 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%@ include file="/jsp/include/basejs.jsp" %> 13 | 14 | 15 | 16 | <#list columnList as x> 17 | <#if x.isEdit=="Y"> 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
<#if x.comment??>${x.comment}${r"${entity."}${x.javaName}<#if x.javaType=='Double'>Str<#if x.javaType=='Date'>Str<#if x.dictKey!="">Str${r"}"}
28 | 29 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/util/AutoCodeDbUtils.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.util; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | import java.sql.ResultSet; 6 | import java.sql.ResultSetMetaData; 7 | import java.sql.SQLException; 8 | import java.sql.Statement; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | import java.util.Properties; 12 | 13 | import com.thinkgem.jeesite.autocode.model.ColumnModel; 14 | import com.thinkgem.jeesite.autocode.model.DataSource; 15 | import com.thinkgem.jeesite.autocode.model.TableModel; 16 | 17 | public class AutoCodeDbUtils { 18 | /** 19 | * 数据库连接 MySql,SqlServer,Oracle driver-驱动名,url-连接地址及数据库,user-用户名,pwd-密码 20 | * */ 21 | public static Connection getConntion(DataSource ds) { 22 | try { 23 | Class.forName(ds.getDriver()).newInstance(); 24 | Properties prop = new Properties(); 25 | prop.put("user", ds.getUser()); 26 | prop.put("password", ds.getPassword()); 27 | if ("ORACLE".equals(ds.getDataBaseType())) { 28 | prop.put("remarksReporting", "true"); 29 | } 30 | Connection conn = DriverManager.getConnection(ds.getUrl(), prop); 31 | return conn; 32 | } catch (InstantiationException e) { 33 | // TODO Auto-generated catch block 34 | e.printStackTrace(); 35 | } catch (IllegalAccessException e) { 36 | // TODO Auto-generated catch block 37 | e.printStackTrace(); 38 | } catch (ClassNotFoundException e) { 39 | // TODO Auto-generated catch block 40 | e.printStackTrace(); 41 | } catch (SQLException e) { 42 | // TODO Auto-generated catch block 43 | e.printStackTrace(); 44 | } 45 | return null; 46 | } 47 | 48 | public static List getTableList(DataSource ds) { 49 | List list = new ArrayList(); 50 | String sql = ""; 51 | if ("ORACLE".equals(ds.getDataBaseType())) { 52 | sql = "select table_name as name,comments as comments from user_tab_comments"; 53 | }else if("MYSQL".equals(ds.getDataBaseType())){ 54 | sql = "SHOW TABLE STATUS FROM `"+ds.getDbName()+"`"; 55 | } 56 | 57 | Connection conn = null; 58 | try { 59 | conn = getConntion(ds); 60 | Statement stmt = conn.createStatement(); 61 | ResultSet rs = stmt.executeQuery(sql); 62 | 63 | while (rs.next()) { 64 | TableModel table = new TableModel(); 65 | table.setName(rs.getString("NAME").toLowerCase()); 66 | if ("ORACLE".equals(ds.getDataBaseType())) { 67 | table.setComment(rs.getString("comments")); 68 | }else if("MYSQL".equals(ds.getDataBaseType())){ 69 | table.setComment(rs.getString("comment")); 70 | } 71 | list.add(table); 72 | } 73 | } catch (Exception e) { 74 | e.printStackTrace(); 75 | } finally { 76 | DbUtils.closeQuietly(conn); 77 | } 78 | return list; 79 | } 80 | 81 | 82 | public static List getColumnList(DataSource ds,String tableName){ 83 | Connection conn = null; 84 | 85 | List list = new ArrayList(); 86 | 87 | String sql = ""; 88 | if ("ORACLE".equals(ds.getDataBaseType())) { 89 | StringBuffer buf = new StringBuffer(); 90 | buf.append("select a.COLUMN_NAME as FIELD, c.COMMENTS as COMMENTS,A.DATA_LENGTH,A.DATA_PRECISION,A.DATA_SCALE,a.DATA_TYPE,a.NULLABLE "); 91 | buf.append(" from user_tab_columns a, user_col_comments c "); 92 | buf.append(" where a.TABLE_NAME = c.TABLE_NAME(+) "); 93 | buf.append(" and a.COLUMN_NAME = c.COLUMN_NAME(+) "); 94 | buf.append(" and a.TABLE_NAME = '").append(tableName.toUpperCase()).append("' ORDER BY COLUMN_ID ASC"); 95 | sql = buf.toString(); 96 | }else if("MYSQL".equals(ds.getDataBaseType())){ 97 | sql = "show full fields from `"+tableName+"`"; 98 | } 99 | 100 | try { 101 | conn = getConntion(ds); 102 | Statement stmt = conn.createStatement(); 103 | ResultSet rs = stmt.executeQuery(sql); 104 | 105 | while (rs.next()) { 106 | ColumnModel column = new ColumnModel(); 107 | column.setColumnName(rs.getString("FIELD").toLowerCase()); 108 | 109 | if("MYSQL".equals(ds.getDataBaseType())){ 110 | column.setIsParamKey(rs.getString("KEY")); 111 | column.setComment(rs.getString("COMMENT")); 112 | column.setJavaType(rs.getString("TYPE")); 113 | }else if ("ORACLE".equals(ds.getDataBaseType())) { 114 | column.setDbType(rs.getString("DATA_TYPE")); 115 | 116 | if(rs.getInt("DATA_PRECISION")>0){ 117 | //如果是数字,此值会大于0 118 | column.setDatasize(rs.getInt("DATA_PRECISION")); 119 | column.setDigits(rs.getInt("DATA_SCALE")); 120 | }else{ 121 | //如果是字符串,需要取DATA_LENGTH值 122 | column.setDatasize(rs.getInt(("DATA_LENGTH"))); 123 | } 124 | 125 | column.setComment(rs.getString("COMMENTS")); 126 | column.setIsNull(rs.getString("NULLABLE")); 127 | column.setIsParamKey("N"); 128 | } 129 | 130 | list.add(column); 131 | } 132 | rs.close(); 133 | 134 | if ("ORACLE".equals(ds.getDataBaseType())) { 135 | //获取主键 136 | StringBuffer buf = new StringBuffer(); 137 | buf.append("select cu.COLUMN_NAME "); 138 | buf.append(" from user_cons_columns cu, user_constraints au "); 139 | buf.append(" where cu.constraint_name = au.constraint_name "); 140 | buf.append(" and au.constraint_type = 'P' "); 141 | buf.append(" and au.table_name = '").append(tableName.toUpperCase()).append("'"); 142 | 143 | ResultSet rspk = stmt.executeQuery(buf.toString()); 144 | while (rspk.next()) { 145 | String columnName = rspk.getString("COLUMN_NAME"); 146 | for(ColumnModel column:list){ 147 | if(columnName.equalsIgnoreCase(column.getColumnName())){ 148 | column.setIsParamKey("PRI"); 149 | break; 150 | } 151 | } 152 | } 153 | rspk.close(); 154 | } 155 | 156 | for(ColumnModel column:list){ 157 | if("MYSQL".equals(ds.getDataBaseType())){ 158 | column.init(); 159 | }else if ("ORACLE".equals(ds.getDataBaseType())) { 160 | column.initOra();//针对ORACLE进行初始化 161 | } 162 | } 163 | return list; 164 | } catch (Exception e) { 165 | e.printStackTrace(); 166 | } finally { 167 | DbUtils.closeQuietly(conn); 168 | } 169 | return null; 170 | } 171 | 172 | 173 | public static List getColumnListBySql(DataSource ds,final String sql){ 174 | //SQL增加条件过滤,只选择一条记录 175 | Connection conn = null; 176 | 177 | List list = new ArrayList(); 178 | 179 | String newsql = sql; 180 | 181 | if ("ORACLE".equals(ds.getDataBaseType())) { 182 | 183 | }else if("MYSQL".equals(ds.getDataBaseType())){ 184 | newsql += " limit 0,1"; 185 | } 186 | 187 | try { 188 | conn = getConntion(ds); 189 | Statement stmt = conn.createStatement(); 190 | ResultSet rs = stmt.executeQuery(sql); 191 | ResultSetMetaData rsmd = rs.getMetaData(); 192 | 193 | //spring dao 里面有具体的实现,回头翻阅下spring jdbc 代码 194 | List colList = new ArrayList(); 195 | int columnCount = rsmd.getColumnCount(); 196 | for (int i = 1; i <= columnCount; i++) { 197 | ColumnModel column = new ColumnModel(); 198 | column.setColumnName(rsmd.getColumnLabel(i)); 199 | column.setComment(""); 200 | column.setDigits(rsmd.getScale(i)); 201 | column.setJavaType(rsmd.getColumnTypeName(i)); 202 | column.init(); 203 | list.add(column); 204 | } 205 | return list; 206 | 207 | } catch (Exception e) { 208 | e.printStackTrace(); 209 | } finally { 210 | DbUtils.closeQuietly(conn); 211 | } 212 | return null; 213 | } 214 | } 215 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/util/CharSequenceUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.thinkgem.jeesite.autocode.util; 18 | 19 | /** 20 | *

Operations on {@link java.lang.CharSequence} that are 21 | * {@code null} safe.

22 | * 23 | * @see java.lang.CharSequence 24 | * @since 3.0 25 | * @version $Id: CharSequenceUtils.java 1199894 2011-11-09 17:53:59Z ggregory $ 26 | */ 27 | public class CharSequenceUtils { 28 | 29 | /** 30 | *

{@code CharSequenceUtils} instances should NOT be constructed in 31 | * standard programming.

32 | * 33 | *

This constructor is public to permit tools that require a JavaBean 34 | * instance to operate.

35 | */ 36 | public CharSequenceUtils() { 37 | super(); 38 | } 39 | 40 | //----------------------------------------------------------------------- 41 | /** 42 | *

Returns a new {@code CharSequence} that is a subsequence of this 43 | * sequence starting with the {@code char} value at the specified index.

44 | * 45 | *

This provides the {@code CharSequence} equivalent to {@link String#substring(int)}. 46 | * The length (in {@code char}) of the returned sequence is {@code length() - start}, 47 | * so if {@code start == end} then an empty sequence is returned.

48 | * 49 | * @param cs the specified subsequence, null returns null 50 | * @param start the start index, inclusive, valid 51 | * @return a new subsequence, may be null 52 | * @throws IndexOutOfBoundsException if {@code start} is negative or if 53 | * {@code start} is greater than {@code length()} 54 | */ 55 | public static CharSequence subSequence(CharSequence cs, int start) { 56 | return cs == null ? null : cs.subSequence(start, cs.length()); 57 | } 58 | 59 | //----------------------------------------------------------------------- 60 | /** 61 | *

Finds the first index in the {@code CharSequence} that matches the 62 | * specified character.

63 | * 64 | * @param cs the {@code CharSequence} to be processed, not null 65 | * @param searchChar the char to be searched for 66 | * @param start the start index, negative starts at the string start 67 | * @return the index where the search char was found, -1 if not found 68 | */ 69 | static int indexOf(CharSequence cs, int searchChar, int start) { 70 | if (cs instanceof String) { 71 | return ((String) cs).indexOf(searchChar, start); 72 | } else { 73 | int sz = cs.length(); 74 | if (start < 0) { 75 | start = 0; 76 | } 77 | for (int i = start; i < sz; i++) { 78 | if (cs.charAt(i) == searchChar) { 79 | return i; 80 | } 81 | } 82 | return -1; 83 | } 84 | } 85 | 86 | /** 87 | * Used by the indexOf(CharSequence methods) as a green implementation of indexOf. 88 | * 89 | * @param cs the {@code CharSequence} to be processed 90 | * @param searchChar the {@code CharSequence} to be searched for 91 | * @param start the start index 92 | * @return the index where the search sequence was found 93 | */ 94 | static int indexOf(CharSequence cs, CharSequence searchChar, int start) { 95 | return cs.toString().indexOf(searchChar.toString(), start); 96 | // if (cs instanceof String && searchChar instanceof String) { 97 | // // TODO: Do we assume searchChar is usually relatively small; 98 | // // If so then calling toString() on it is better than reverting to 99 | // // the green implementation in the else block 100 | // return ((String) cs).indexOf((String) searchChar, start); 101 | // } else { 102 | // // TODO: Implement rather than convert to String 103 | // return cs.toString().indexOf(searchChar.toString(), start); 104 | // } 105 | } 106 | 107 | /** 108 | *

Finds the last index in the {@code CharSequence} that matches the 109 | * specified character.

110 | * 111 | * @param cs the {@code CharSequence} to be processed 112 | * @param searchChar the char to be searched for 113 | * @param start the start index, negative returns -1, beyond length starts at end 114 | * @return the index where the search char was found, -1 if not found 115 | */ 116 | static int lastIndexOf(CharSequence cs, int searchChar, int start) { 117 | if (cs instanceof String) { 118 | return ((String) cs).lastIndexOf(searchChar, start); 119 | } else { 120 | int sz = cs.length(); 121 | if (start < 0) { 122 | return -1; 123 | } 124 | if (start >= sz) { 125 | start = sz - 1; 126 | } 127 | for (int i = start; i >= 0; --i) { 128 | if (cs.charAt(i) == searchChar) { 129 | return i; 130 | } 131 | } 132 | return -1; 133 | } 134 | } 135 | 136 | /** 137 | * Used by the lastIndexOf(CharSequence methods) as a green implementation of lastIndexOf 138 | * 139 | * @param cs the {@code CharSequence} to be processed 140 | * @param searchChar the {@code CharSequence} to be searched for 141 | * @param start the start index 142 | * @return the index where the search sequence was found 143 | */ 144 | static int lastIndexOf(CharSequence cs, CharSequence searchChar, int start) { 145 | return cs.toString().lastIndexOf(searchChar.toString(), start); 146 | // if (cs instanceof String && searchChar instanceof String) { 147 | // // TODO: Do we assume searchChar is usually relatively small; 148 | // // If so then calling toString() on it is better than reverting to 149 | // // the green implementation in the else block 150 | // return ((String) cs).lastIndexOf((String) searchChar, start); 151 | // } else { 152 | // // TODO: Implement rather than convert to String 153 | // return cs.toString().lastIndexOf(searchChar.toString(), start); 154 | // } 155 | } 156 | 157 | /** 158 | * Green implementation of toCharArray. 159 | * 160 | * @param cs the {@code CharSequence} to be processed 161 | * @return the resulting char array 162 | */ 163 | static char[] toCharArray(CharSequence cs) { 164 | if (cs instanceof String) { 165 | return ((String) cs).toCharArray(); 166 | } else { 167 | int sz = cs.length(); 168 | char[] array = new char[cs.length()]; 169 | for (int i = 0; i < sz; i++) { 170 | array[i] = cs.charAt(i); 171 | } 172 | return array; 173 | } 174 | } 175 | 176 | /** 177 | * Green implementation of regionMatches. 178 | * 179 | * @param cs the {@code CharSequence} to be processed 180 | * @param ignoreCase whether or not to be case insensitive 181 | * @param thisStart the index to start on the {@code cs} CharSequence 182 | * @param substring the {@code CharSequence} to be looked for 183 | * @param start the index to start on the {@code substring} CharSequence 184 | * @param length character length of the region 185 | * @return whether the region matched 186 | */ 187 | static boolean regionMatches(CharSequence cs, boolean ignoreCase, int thisStart, 188 | CharSequence substring, int start, int length) { 189 | if (cs instanceof String && substring instanceof String) { 190 | return ((String) cs).regionMatches(ignoreCase, thisStart, (String) substring, start, length); 191 | } else { 192 | // TODO: Implement rather than convert to String 193 | return cs.toString().regionMatches(ignoreCase, thisStart, substring.toString(), start, length); 194 | } 195 | } 196 | 197 | } 198 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/util/DbUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.thinkgem.jeesite.autocode.util; 18 | 19 | import java.io.PrintWriter; 20 | import java.sql.Connection; 21 | import java.sql.ResultSet; 22 | import java.sql.SQLException; 23 | import java.sql.Statement; 24 | 25 | /** 26 | * A collection of JDBC helper methods. This class is thread safe. 27 | */ 28 | public final class DbUtils { 29 | 30 | /** 31 | * Default constructor. 32 | * 33 | * Utility classes should not have a public or default constructor, but this 34 | * one preserves retro-compatibility. 35 | * 36 | * @since 1.4 37 | */ 38 | public DbUtils() { 39 | // do nothing 40 | } 41 | 42 | /** 43 | * Close a Connection, avoid closing if null. 44 | * 45 | * @param conn 46 | * Connection to close. 47 | * @throws SQLException 48 | * if a database access error occurs 49 | */ 50 | public static void close(Connection conn) throws SQLException { 51 | if (conn != null) { 52 | conn.close(); 53 | } 54 | } 55 | 56 | /** 57 | * Close a ResultSet, avoid closing if null. 58 | * 59 | * @param rs 60 | * ResultSet to close. 61 | * @throws SQLException 62 | * if a database access error occurs 63 | */ 64 | public static void close(ResultSet rs) throws SQLException { 65 | if (rs != null) { 66 | rs.close(); 67 | } 68 | } 69 | 70 | /** 71 | * Close a Statement, avoid closing if null. 72 | * 73 | * @param stmt 74 | * Statement to close. 75 | * @throws SQLException 76 | * if a database access error occurs 77 | */ 78 | public static void close(Statement stmt) throws SQLException { 79 | if (stmt != null) { 80 | stmt.close(); 81 | } 82 | } 83 | 84 | /** 85 | * Close a Connection, avoid closing if null and hide any 86 | * SQLExceptions that occur. 87 | * 88 | * @param conn 89 | * Connection to close. 90 | */ 91 | public static void closeQuietly(Connection conn) { 92 | try { 93 | close(conn); 94 | } catch (SQLException e) { // NOPMD 95 | // quiet 96 | } 97 | } 98 | 99 | /** 100 | * Close a Connection, Statement and 101 | * ResultSet. Avoid closing if null and hide any SQLExceptions 102 | * that occur. 103 | * 104 | * @param conn 105 | * Connection to close. 106 | * @param stmt 107 | * Statement to close. 108 | * @param rs 109 | * ResultSet to close. 110 | */ 111 | public static void closeQuietly(Connection conn, Statement stmt, 112 | ResultSet rs) { 113 | 114 | try { 115 | closeQuietly(rs); 116 | } finally { 117 | try { 118 | closeQuietly(stmt); 119 | } finally { 120 | closeQuietly(conn); 121 | } 122 | } 123 | 124 | } 125 | 126 | /** 127 | * Close a ResultSet, avoid closing if null and hide any 128 | * SQLExceptions that occur. 129 | * 130 | * @param rs 131 | * ResultSet to close. 132 | */ 133 | public static void closeQuietly(ResultSet rs) { 134 | try { 135 | close(rs); 136 | } catch (SQLException e) { // NOPMD 137 | // quiet 138 | } 139 | } 140 | 141 | /** 142 | * Close a Statement, avoid closing if null and hide any 143 | * SQLExceptions that occur. 144 | * 145 | * @param stmt 146 | * Statement to close. 147 | */ 148 | public static void closeQuietly(Statement stmt) { 149 | try { 150 | close(stmt); 151 | } catch (SQLException e) { // NOPMD 152 | // quiet 153 | } 154 | } 155 | 156 | /** 157 | * Commits a Connection then closes it, avoid closing if null. 158 | * 159 | * @param conn 160 | * Connection to close. 161 | * @throws SQLException 162 | * if a database access error occurs 163 | */ 164 | public static void commitAndClose(Connection conn) throws SQLException { 165 | if (conn != null) { 166 | try { 167 | conn.commit(); 168 | } finally { 169 | conn.close(); 170 | } 171 | } 172 | } 173 | 174 | /** 175 | * Commits a Connection then closes it, avoid closing if null 176 | * and hide any SQLExceptions that occur. 177 | * 178 | * @param conn 179 | * Connection to close. 180 | */ 181 | public static void commitAndCloseQuietly(Connection conn) { 182 | try { 183 | commitAndClose(conn); 184 | } catch (SQLException e) { // NOPMD 185 | // quiet 186 | } 187 | } 188 | 189 | /** 190 | * Loads and registers a database driver class. If this succeeds, it returns 191 | * true, else it returns false. 192 | * 193 | * @param driverClassName 194 | * of driver to load 195 | * @return boolean true if the driver was found, otherwise 196 | * false 197 | */ 198 | public static boolean loadDriver(String driverClassName) { 199 | return loadDriver(DbUtils.class.getClassLoader(), driverClassName); 200 | } 201 | 202 | /** 203 | * Loads and registers a database driver class. If this succeeds, it returns 204 | * true, else it returns false. 205 | * 206 | * @param classLoader 207 | * the class loader used to load the driver class 208 | * @param driverClassName 209 | * of driver to load 210 | * @return boolean true if the driver was found, otherwise 211 | * false 212 | * @since 1.4 213 | */ 214 | public static boolean loadDriver(ClassLoader classLoader, 215 | String driverClassName) { 216 | try { 217 | classLoader.loadClass(driverClassName).newInstance(); 218 | return true; 219 | 220 | } catch (IllegalAccessException e) { 221 | // Constructor is private, OK for DriverManager contract 222 | return true; 223 | 224 | } catch (Exception e) { 225 | return false; 226 | 227 | } 228 | } 229 | 230 | /** 231 | * Print the stack trace for a SQLException to STDERR. 232 | * 233 | * @param e 234 | * SQLException to print stack trace of 235 | */ 236 | public static void printStackTrace(SQLException e) { 237 | printStackTrace(e, new PrintWriter(System.err)); 238 | } 239 | 240 | /** 241 | * Print the stack trace for a SQLException to a specified PrintWriter. 242 | * 243 | * @param e 244 | * SQLException to print stack trace of 245 | * @param pw 246 | * PrintWriter to print to 247 | */ 248 | public static void printStackTrace(SQLException e, PrintWriter pw) { 249 | 250 | SQLException next = e; 251 | while (next != null) { 252 | next.printStackTrace(pw); 253 | next = next.getNextException(); 254 | if (next != null) { 255 | pw.println("Next SQLException:"); 256 | } 257 | } 258 | } 259 | 260 | /** 261 | * Print warnings on a Connection to STDERR. 262 | * 263 | * @param conn 264 | * Connection to print warnings from 265 | */ 266 | public static void printWarnings(Connection conn) { 267 | printWarnings(conn, new PrintWriter(System.err)); 268 | } 269 | 270 | /** 271 | * Print warnings on a Connection to a specified PrintWriter. 272 | * 273 | * @param conn 274 | * Connection to print warnings from 275 | * @param pw 276 | * PrintWriter to print to 277 | */ 278 | public static void printWarnings(Connection conn, PrintWriter pw) { 279 | if (conn != null) { 280 | try { 281 | printStackTrace(conn.getWarnings(), pw); 282 | } catch (SQLException e) { 283 | printStackTrace(e, pw); 284 | } 285 | } 286 | } 287 | 288 | /** 289 | * Rollback any changes made on the given connection. 290 | * 291 | * @param conn 292 | * Connection to rollback. A null value is legal. 293 | * @throws SQLException 294 | * if a database access error occurs 295 | */ 296 | public static void rollback(Connection conn) throws SQLException { 297 | if (conn != null) { 298 | conn.rollback(); 299 | } 300 | } 301 | 302 | /** 303 | * Performs a rollback on the Connection then closes it, avoid 304 | * closing if null. 305 | * 306 | * @param conn 307 | * Connection to rollback. A null value is legal. 308 | * @throws SQLException 309 | * if a database access error occurs 310 | * @since DbUtils 1.1 311 | */ 312 | public static void rollbackAndClose(Connection conn) throws SQLException { 313 | if (conn != null) { 314 | try { 315 | conn.rollback(); 316 | } finally { 317 | conn.close(); 318 | } 319 | } 320 | } 321 | 322 | /** 323 | * Performs a rollback on the Connection then closes it, avoid 324 | * closing if null and hide any SQLExceptions that occur. 325 | * 326 | * @param conn 327 | * Connection to rollback. A null value is legal. 328 | * @since DbUtils 1.1 329 | */ 330 | public static void rollbackAndCloseQuietly(Connection conn) { 331 | try { 332 | rollbackAndClose(conn); 333 | } catch (SQLException e) { // NOPMD 334 | // quiet 335 | } 336 | } 337 | 338 | } 339 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/util/FileUtils.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.util; 2 | 3 | import java.io.File; 4 | import java.io.FileOutputStream; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.io.OutputStream; 8 | import java.net.URL; 9 | 10 | public class FileUtils { 11 | public static void copyURLToFile(URL source, File destination) 12 | throws IOException { 13 | java.io.InputStream input = source.openStream(); 14 | try { 15 | FileOutputStream output = openOutputStream(destination); 16 | try { 17 | copy(input, output); 18 | } finally { 19 | closeQuietly(output); 20 | } 21 | } finally { 22 | closeQuietly(input); 23 | } 24 | } 25 | 26 | public static FileOutputStream openOutputStream(File file) 27 | throws IOException { 28 | if (file.exists()) { 29 | if (file.isDirectory()) 30 | throw new IOException("File '" + file 31 | + "' exists but is a directory"); 32 | if (!file.canWrite()) 33 | throw new IOException("File '" + file 34 | + "' cannot be written to"); 35 | } else { 36 | File parent = file.getParentFile(); 37 | if (parent != null && !parent.exists() && !parent.mkdirs()) 38 | throw new IOException("File '" + file 39 | + "' could not be created"); 40 | } 41 | return new FileOutputStream(file); 42 | } 43 | 44 | public static int copy(InputStream input, OutputStream output) 45 | throws IOException { 46 | long count = copyLarge(input, output); 47 | if (count > 2147483647L) 48 | return -1; 49 | else 50 | return (int) count; 51 | } 52 | 53 | public static long copyLarge(InputStream input, OutputStream output) 54 | throws IOException { 55 | byte buffer[] = new byte[4096]; 56 | long count = 0L; 57 | for (int n = 0; -1 != (n = input.read(buffer));) { 58 | output.write(buffer, 0, n); 59 | count += n; 60 | } 61 | 62 | return count; 63 | } 64 | 65 | public static void closeQuietly(OutputStream output) { 66 | try { 67 | if (output != null) 68 | output.close(); 69 | } catch (IOException ioe) { 70 | } 71 | } 72 | 73 | public static void closeQuietly(InputStream input) { 74 | try { 75 | if (input != null) 76 | input.close(); 77 | } catch (IOException ioe) { 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/util/FreeMakerUtils.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.util; 2 | 3 | import java.io.BufferedWriter; 4 | import java.io.File; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.io.OutputStreamWriter; 8 | import java.io.Writer; 9 | import java.util.Map; 10 | 11 | import freemarker.template.Configuration; 12 | import freemarker.template.Template; 13 | import freemarker.template.TemplateException; 14 | 15 | 16 | public class FreeMakerUtils { 17 | 18 | public static Configuration getFreeMarkerCfg(String ftlPath) { 19 | Configuration freemarkerCfg = new Configuration(); 20 | freemarkerCfg.setBooleanFormat("true,false"); 21 | freemarkerCfg.setNumberFormat("#"); 22 | freemarkerCfg.setDefaultEncoding("UTF-8"); 23 | try { 24 | freemarkerCfg.setDirectoryForTemplateLoading(new File(ftlPath)); 25 | } catch (IOException e) { 26 | e.printStackTrace(); 27 | } 28 | return freemarkerCfg; 29 | } 30 | 31 | public static Configuration getFreeMarkerCfg(Class cls, String templatePath) { 32 | Configuration freemarkerCfg = new Configuration(); 33 | freemarkerCfg.setBooleanFormat("true,false"); 34 | freemarkerCfg.setDefaultEncoding("UTF-8"); 35 | freemarkerCfg.setClassForTemplateLoading(cls, templatePath); 36 | return freemarkerCfg; 37 | } 38 | 39 | public static boolean generateFile(Configuration cfg, 40 | String templateFileName, Map propMap, String relPath, 41 | String fileName, String rootDir) { 42 | try { 43 | Template t = cfg.getTemplate(templateFileName); 44 | 45 | creatDirs(rootDir, relPath); 46 | 47 | File dir = new File(rootDir + "/" + relPath); 48 | if (!dir.exists()) { 49 | dir.mkdir(); 50 | } 51 | 52 | File afile = new File(rootDir + "/" + relPath + "/" 53 | + fileName); 54 | 55 | Writer out = new BufferedWriter(new OutputStreamWriter( 56 | new FileOutputStream(afile), "UTF-8")); 57 | 58 | t.process(propMap, out); 59 | out.close(); 60 | } catch (TemplateException e) { 61 | e.printStackTrace(); 62 | return false; 63 | } catch (IOException e) { 64 | e.printStackTrace(); 65 | return false; 66 | } 67 | 68 | return true; 69 | } 70 | 71 | public static boolean creatDirs(String aParentDir, String aSubDir) { 72 | File aFile = new File(aParentDir); 73 | if (aFile.exists()) { 74 | File aSubFile = new File(aParentDir + "/" + aSubDir); 75 | if (!aSubFile.exists()) { 76 | return aSubFile.mkdirs(); 77 | } else { 78 | return true; 79 | } 80 | } else { 81 | return false; 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/util/GetterSetterUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.thinkgem.jeesite.autocode.util; 5 | 6 | import java.lang.reflect.Field; 7 | 8 | import com.thinkgem.jeesite.autocode.model.ColumnModel; 9 | /** 10 | * 11 | */ 12 | public class GetterSetterUtils { 13 | 14 | /** 15 | * @param args 16 | */ 17 | public static void main(String[] args) { 18 | // TODO Auto-generated method stub 19 | //Class c = com.routdata.dm.equipment.queryFilter.ChangeQueryFilter.class; 20 | Class c = ColumnModel.class; 21 | Field[] fields = c.getDeclaredFields(); 22 | for(int i=0,len=fields.length-1;i<=len;i++){ 23 | /*if("java.lang.Double".equals(fields[i].getType().getName())){ 24 | System.out.println("public String get"+fields[i].getName().substring(0, 1).toUpperCase()+fields[i].getName().substring(1)+"Str(){"); 25 | System.out.println("return FormateUtil.getInstance().formateDouble(this."+fields[i].getName()+");"); 26 | System.out.println("}"); 27 | }else if("java.util.Date".equals(fields[i].getType().getName())){ 28 | System.out.println("public String get"+fields[i].getName().substring(0, 1).toUpperCase()+fields[i].getName().substring(1)+"Str(){"); 29 | System.out.println("return DateUtil.getInstance().formateDate(this."+fields[i].getName()+");"); 30 | System.out.println("}"); 31 | }*/ 32 | 33 | System.out.println("str.append(\""+fields[i].getName()+"=\").append("+fields[i].getName()+");"); 34 | } 35 | 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/util/SQLFormatter.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.util; 2 | 3 | import blanco.commons.sql.format.BlancoSqlFormatter; 4 | import blanco.commons.sql.format.BlancoSqlFormatterException; 5 | import blanco.commons.sql.format.BlancoSqlRule; 6 | 7 | /** 8 | * 格式化SQL语句 代码来源 https://github.com/kyama/SQLFormatter 9 | * 10 | */ 11 | public class SQLFormatter { 12 | public static String formatSql(String sql) { 13 | String newsql = new String(); 14 | BlancoSqlRule rule = new BlancoSqlRule(); 15 | String[] mySqlFuncs = { 16 | // getNumericFunctions 17 | "ABS", "ACOS", "ASIN", "ATAN", "ATAN2", "BIT_COUNT", "CEILING", 18 | "COS", "COT", "DEGREES", "EXP", 19 | "FLOOR", 20 | "LOG", 21 | "LOG10", 22 | "MAX", 23 | "MIN", 24 | "MOD", 25 | "PI", 26 | "POW", 27 | "POWER", 28 | "RADIANS", 29 | "RAND", 30 | "ROUND", 31 | "SIN", 32 | "SQRT", 33 | "TAN", 34 | "TRUNCATE", 35 | // getStringFunctions 36 | "ASCII", "BIN", "BIT_LENGTH", "CHAR", "CHARACTER_LENGTH", 37 | "CHAR_LENGTH", "CONCAT", "CONCAT_WS", "CONV", "ELT", 38 | "EXPORT_SET", "FIELD", "FIND_IN_SET", "HEX,INSERT", "INSTR", 39 | "LCASE", "LEFT", "LENGTH", "LOAD_FILE", "LOCATE", "LOCATE", 40 | "LOWER", "LPAD", "LTRIM", "MAKE_SET", "MATCH", "MID", "OCT", 41 | "OCTET_LENGTH", "ORD", "POSITION", "QUOTE", "REPEAT", 42 | "REPLACE", "REVERSE", "RIGHT", "RPAD", "RTRIM", "SOUNDEX", 43 | "SPACE", "STRCMP", "SUBSTRING", 44 | "SUBSTRING", 45 | "SUBSTRING", 46 | "SUBSTRING", 47 | "SUBSTRING_INDEX", 48 | "TRIM", 49 | "UCASE", 50 | "UPPER", 51 | // getSystemFunctions 52 | "DATABASE", "USER", 53 | "SYSTEM_USER", 54 | "SESSION_USER", 55 | "PASSWORD", 56 | "ENCRYPT", 57 | "LAST_INSERT_ID", 58 | "VERSION", 59 | // getTimeDateFunctions 60 | "DAYOFWEEK", "WEEKDAY", "DAYOFMONTH", "DAYOFYEAR", "MONTH", 61 | "DAYNAME", "MONTHNAME", "QUARTER", "WEEK", "YEAR", "HOUR", 62 | "MINUTE", "SECOND", "PERIOD_ADD", "PERIOD_DIFF", "TO_DAYS", 63 | "FROM_DAYS", "DATE_FORMAT", "TIME_FORMAT", "CURDATE", 64 | "CURRENT_DATE", "CURTIME", "CURRENT_TIME", "NOW", "SYSDATE", 65 | "CURRENT_TIMESTAMP", "UNIX_TIMESTAMP", "FROM_UNIXTIME", 66 | "SEC_TO_TIME", "TIME_TO_SEC" }; 67 | rule.setFunctionNames(mySqlFuncs); 68 | 69 | BlancoSqlFormatter formatter = new BlancoSqlFormatter(rule); 70 | 71 | try { 72 | newsql = formatter.format(sql); 73 | } catch (BlancoSqlFormatterException e) { 74 | return sql; 75 | } 76 | return newsql; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/util/XmlObjectCrud.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.util; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * crud xml 7 | * 8 | */ 9 | public class XmlObjectCrud extends XmlObjectUtils { 10 | public static String getLeastColumns(){ 11 | String userDir = System.getProperty("user.dir"); 12 | String fileName = userDir +"\\crud-columns.xml"; 13 | return fileName; 14 | } 15 | 16 | public static String getLeastTable(){ 17 | String userDir = System.getProperty("user.dir"); 18 | String fileName = userDir +"\\crud-table.xml"; 19 | return fileName; 20 | } 21 | 22 | public static String getFtlPath(){ 23 | String userDir = System.getProperty("user.dir"); 24 | File dir = new File(userDir+"\\jeesite"); 25 | if (!dir.exists()) { 26 | dir.mkdir(); 27 | } 28 | File cruddir = new File(userDir+"\\jeesite\\crud"); 29 | if (!cruddir.exists()) { 30 | cruddir.mkdir(); 31 | } 32 | return userDir+"\\jeesite\\crud\\ftl"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/util/XmlObjectReport.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.util; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * crud xml 7 | * 8 | */ 9 | public class XmlObjectReport extends XmlObjectUtils { 10 | public static String getLeastColumns(){ 11 | String userDir = System.getProperty("user.dir"); 12 | String fileName = userDir +"\\report-columns.xml"; 13 | return fileName; 14 | } 15 | 16 | public static String getLeastTable(){ 17 | String userDir = System.getProperty("user.dir"); 18 | String fileName = userDir +"\\report-table.xml"; 19 | return fileName; 20 | } 21 | 22 | public static String getFtlPath(){ 23 | String userDir = System.getProperty("user.dir"); 24 | File dir = new File(userDir+"\\jeesite"); 25 | if (!dir.exists()) { 26 | dir.mkdir(); 27 | } 28 | File cruddir = new File(userDir+"\\jeesite\\report"); 29 | if (!cruddir.exists()) { 30 | cruddir.mkdir(); 31 | } 32 | return userDir+"\\jeesite\\report\\ftl"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/util/XmlObjectTree.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.util; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * crud xml 7 | * 8 | */ 9 | public class XmlObjectTree extends XmlObjectUtils { 10 | public static String getLeastColumns(){ 11 | String userDir = System.getProperty("user.dir"); 12 | String fileName = userDir +"\\tree-columns.xml"; 13 | return fileName; 14 | } 15 | 16 | public static String getLeastTable(){ 17 | String userDir = System.getProperty("user.dir"); 18 | String fileName = userDir +"\\tree-table.xml"; 19 | return fileName; 20 | } 21 | 22 | public static String getFtlPath(){ 23 | String userDir = System.getProperty("user.dir"); 24 | File dir = new File(userDir+"\\jeesite"); 25 | if (!dir.exists()) { 26 | dir.mkdir(); 27 | } 28 | File cruddir = new File(userDir+"\\jeesite\\tree"); 29 | if (!cruddir.exists()) { 30 | cruddir.mkdir(); 31 | } 32 | return userDir+"\\jeesite\\tree\\ftl"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/com/thinkgem/jeesite/autocode/util/XmlObjectUtils.java: -------------------------------------------------------------------------------- 1 | package com.thinkgem.jeesite.autocode.util; 2 | 3 | import java.beans.XMLDecoder; 4 | import java.beans.XMLEncoder; 5 | import java.io.File; 6 | import java.io.FileInputStream; 7 | import java.io.FileNotFoundException; 8 | import java.io.FileOutputStream; 9 | import java.io.IOException; 10 | import java.net.URL; 11 | 12 | import com.thinkgem.jeesite.autocode.crud.StartCurdWizard; 13 | 14 | public class XmlObjectUtils { 15 | /** 16 | * 把java的可序列化的对象(实现Serializable接口)序列化保存到XML文件里面,如果想一次保存多个可序列化对象请用集合进行封装 17 | * 保存时将会用现在的对象原来的XML文件内容 18 | * 19 | * @param obj 20 | * 要序列化的可序列化的对象 21 | * @param fileName 22 | * 带完全的保存路径的文件名 23 | * @throws FileNotFoundException 24 | * 指定位置的文件不存在 25 | * @throws IOException 26 | * 输出时发生异常 27 | * @throws Exception 28 | * 其他运行时异常 29 | */ 30 | public static void objectXmlEncoder(Object obj, String fileName) { 31 | // 创建输出文件 32 | try { 33 | File fo = new File(fileName); 34 | // 文件不存在,就创建该文件 35 | if (!fo.exists()) { 36 | // 先创建文件的目录 37 | String path = fileName.substring(0, fileName.lastIndexOf('.')); 38 | File pFile = new File(path); 39 | pFile.mkdirs(); 40 | } 41 | // 创建文件输出流 42 | FileOutputStream fos = new FileOutputStream(fo); 43 | // 创建XML文件对象输出类实例 44 | XMLEncoder encoder = new XMLEncoder(fos); 45 | // 对象序列化输出到XML文件 46 | encoder.writeObject(obj); 47 | encoder.flush(); 48 | // 关闭序列化工具 49 | encoder.close(); 50 | // 关闭输出流 51 | fos.close(); 52 | } catch (FileNotFoundException e1) { 53 | e1.printStackTrace(); 54 | } catch (IOException e1) { 55 | e1.printStackTrace(); 56 | } catch (Exception e1) { 57 | e1.printStackTrace(); 58 | } 59 | } 60 | 61 | /** 62 | * 读取由objSource指定的XML文件中的序列化保存的对象,返回的结果经过了List封装 63 | * 64 | * @param objSource 65 | * 带全部文件路径的文件全名 66 | * @return 由XML文件里面保存的对象构成的List列表(可能是一个或者多个的序列化保存的对象) 67 | * @throws FileNotFoundException 68 | * 指定的对象读取资源不存在 69 | * @throws IOException 70 | * 读取发生错误 71 | * @throws Exception 72 | * 其他运行时异常发生 73 | */ 74 | public static Object objectXmlDecoder(String objSource) { 75 | Object obj = null; 76 | try { 77 | File fin = new File(objSource); 78 | if(fin.exists()){ 79 | FileInputStream fis = new FileInputStream(fin); 80 | XMLDecoder decoder = new XMLDecoder(fis); 81 | obj = decoder.readObject(); 82 | fis.close(); 83 | decoder.close(); 84 | } 85 | } catch (FileNotFoundException e1) { 86 | e1.printStackTrace(); 87 | } catch (IOException e1) { 88 | e1.printStackTrace(); 89 | } catch (Exception e1) { 90 | e1.printStackTrace(); 91 | } 92 | return obj; 93 | } 94 | 95 | /** 96 | * @return 97 | */ 98 | public static String getDataSourceFileName(){ 99 | String userDir = System.getProperty("user.dir"); 100 | String fileName = userDir +"\\datasource.xml"; 101 | return fileName; 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /swing2swt.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thinkgem/jeesite_autocode/485b381db107e63aa1341a8a5d2b6489b162e791/swing2swt.jar --------------------------------------------------------------------------------