diff --git a/dsUtils/pom.xml b/dsUtils/pom.xml index d6176859..acc65d25 100644 --- a/dsUtils/pom.xml +++ b/dsUtils/pom.xml @@ -35,6 +35,33 @@ cos ${jfinal-cos.version} + + + + com.zaxxer + HikariCP + ${HikariCP.version} + + + + mysql + mysql-connector-java + ${mysql.version} + + + + ch.qos.logback + logback-classic + 1.5.6 + + + + + + cn.hutool + hutool-all + ${hutool.version} + diff --git a/dsUtils/src/main/java/com/dsideal/GenerateCode/AutoCreatedEntityName.java b/dsUtils/src/main/java/com/dsideal/GenerateCode/AutoCreatedEntityName.java index dde9f121..3f2d68be 100644 --- a/dsUtils/src/main/java/com/dsideal/GenerateCode/AutoCreatedEntityName.java +++ b/dsUtils/src/main/java/com/dsideal/GenerateCode/AutoCreatedEntityName.java @@ -11,14 +11,9 @@ import java.util.Map; import com.jfinal.core.JFinal; import com.jfinal.plugin.activerecord.DbKit; -import com.dsideal.GenerateCode.so; public class AutoCreatedEntityName { - public AutoCreatedEntityName() { - - } - /*** * 生成表实体 */ @@ -91,54 +86,47 @@ public class AutoCreatedEntityName { * @param tableName 表名数组 */ public void created(String[] tableName,String packagename) { - DataBeasTypeToJavaType dtj=new DataBeasTypeToJavaType(); + DataBeasTypeToJavaType dtj = new DataBeasTypeToJavaType(); so.p("开始生成实体R文件"); Connection conn = null; PreparedStatement colunmsPs = null; - Map> all = new HashMap>(); + Map> all = new HashMap>(); try { conn = DbKit.getConfig().getConnection(); - for(int i=0;i colunms = new HashMap(); + Map colunms = new HashMap(); ResultSet columnsRs = colunmsPs.executeQuery(); // 获取对应表中的字段 while (columnsRs.next()) { // colunms.add(columnsRs.getString(1)); // so.p("字段 "+columnsRs.getString(1)+" "+columnsRs.getString(2).split(")")[0]); - colunms.put(columnsRs.getString(1),dtj.get(columnsRs.getString(2).split("\\(")[0])); + colunms.put(columnsRs.getString(1), dtj.get(columnsRs.getString(2).split("\\(")[0])); } so.p("表为 " + FileNameManager.CamelCase(tableName[i].split("_"))); - all.put(tableName[i],colunms); + all.put(tableName[i], colunms); colunmsPs.close(); } conn.close(); -// so.p(CreatedRFile(all,packagename)); so.p(packagename); - String[] pn=packagename.split("\\."); -// so.p(pn[0]); - StringBuffer file=new StringBuffer(); - String dir=JFinal.me().getServletContext().getRealPath("/"); - file.append(dir.substring(0, dir.length()-7)+"src"); - for(String p:pn) - { + String[] pn = packagename.split("\\."); + StringBuffer file = new StringBuffer(); + String dir = "D:\\dsWork\\dsProject\\dsUtils\\src\\main\\java"; + file.append(dir); + for (String p : pn) { file.append("\\"); file.append(p); } so.p(file.toString()); - FileWriter fileWriter=new FileWriter(file.toString()+"/"+"R.java"); - fileWriter.write(CreatedRFile(all,packagename)); + FileWriter fileWriter = new FileWriter(file + "/" + "R.java"); + fileWriter.write(CreatedRFile(all, packagename)); fileWriter.flush(); fileWriter.close(); so.p("生成完成"); // return getEntity(tableName, property); } catch (Exception e) { - // TODO Auto-generated catch block e.printStackTrace(); -// return null; } - } - } \ No newline at end of file diff --git a/dsUtils/src/main/java/com/dsideal/GenerateCode/AutoCreatedModelFile.java b/dsUtils/src/main/java/com/dsideal/GenerateCode/AutoCreatedModelFile.java index 20236428..8e0ad806 100644 --- a/dsUtils/src/main/java/com/dsideal/GenerateCode/AutoCreatedModelFile.java +++ b/dsUtils/src/main/java/com/dsideal/GenerateCode/AutoCreatedModelFile.java @@ -7,7 +7,6 @@ import java.util.Iterator; import java.util.Map; import com.jfinal.core.JFinal; -import com.dsideal.GenerateCode.so; /*** * 自动生成带setter与getter方法的Model @@ -16,70 +15,70 @@ import com.dsideal.GenerateCode.so; */ public class AutoCreatedModelFile { - public AutoCreatedModelFile(String tableName, Map property,String packageName) throws IOException{ + public AutoCreatedModelFile(String tableName, Map property, String packageName) throws IOException { //-----------------------拼装文件夹名 - String[] pn=packageName.split("\\."); - StringBuffer file=new StringBuffer(); - String dir=JFinal.me().getServletContext().getRealPath("/"); - file.append(dir.substring(0, dir.length()-7)+"src"); - for(String p:pn) - { + String[] pn = packageName.split("\\."); + StringBuffer file = new StringBuffer(); + String dir = "D:\\dsWork\\dsProject\\dsUtils\\src\\main\\java"; + file.append(dir); + for (String p : pn) { file.append("/"); file.append(p); } so.p(file.toString()); //------------------------------------- //---------------------创建文件 - String f=createdFile(file.toString()+"/"+tableName+"/",FileNameManager.upFirstName(tableName)+".java"); + String f = createdFile(file.toString() + "/" + tableName + "/", FileNameManager.upFirstName(tableName) + ".java"); - FileWriter fileWriter=new FileWriter(f); - fileWriter.write(getText(tableName,property,packageName)); + FileWriter fileWriter = new FileWriter(f); + fileWriter.write(getText(tableName, property, packageName)); fileWriter.flush(); fileWriter.close(); } + /*** * 创建文本内容 * @param tableName * @param property * @return */ - private String getText(String tableName, Map property,String packageName){ - String classname=FileNameManager.upFirstName(tableName); + private String getText(String tableName, Map property, String packageName) { + String classname = FileNameManager.upFirstName(tableName); //参数对组 - String para=entrypara(property); + String para = entrypara(property); String ln = "\r\n"; - String tab="\t\t"; + String tab = "\t\t"; StringBuffer sb = new StringBuffer(); - sb.append(ln +"package "+packageName+"."+tableName+";"+ln+ - "import com.jfinal.plugin.activerecord.Model;"+ln+ - "import com.jfinal.plugin.activerecord.TableMapping;"+ln+ - "import com.jfinal.plugin.activerecord.Db;"+ln+ - "import java.util.HashMap;"+ln+ - "import java.util.List;"+ln+ - "import java.util.Map;"+ln+ - inputPackage(property)+ - "/***"+ln+ - " * 自动生成的Model"+ln+ - " * @author 石啸天"+ln+ - " *"+ln+ - " */"+ln+ - "@SuppressWarnings(\"serial\")"+ln+ - "public class "+classname+" extends Model<"+classname+">{"+ln + sb.append(ln + "package " + packageName + "." + tableName + ";" + ln + + "import com.jfinal.plugin.activerecord.Model;" + ln + + "import com.jfinal.plugin.activerecord.TableMapping;" + ln + + "import com.jfinal.plugin.activerecord.Db;" + ln + + "import java.util.HashMap;" + ln + + "import java.util.List;" + ln + + "import java.util.Map;" + ln + + inputPackage(property) + + "/***" + ln + + " * 自动生成的Model" + ln + + " * @author 石啸天" + ln + + " *" + ln + + " */" + ln + + "@SuppressWarnings(\"serial\")" + ln + + "public class " + classname + " extends Model<" + classname + ">{" + ln ); //空构造与有参构造 sb.append(classTextStringLine(new String[]{ "//--------------setter和getter---------------", - entryBean(classname,property), + entryBean(classname, property), "//-------------------------------------------", "/***", "*数据库操作实体", "*/", - "public static final "+classname+" dao=new "+classname+"();", + "public static final " + classname + " dao=new " + classname + "();", "/**", "* 表名", "*/", - "public static final String tableName=\""+tableName+"\";", + "public static final String tableName=\"" + tableName + "\";", "/**", "* 表主键", "*/", @@ -87,20 +86,20 @@ public class AutoCreatedModelFile { "/***", "* 空构造", "*/", - "public "+classname+"(){}", + "public " + classname + "(){}", "/***", "* 有参构造", "*/", - "public "+classname+"(", + "public " + classname + "(", para, "){", - "setData("+ln+tab+entryparas(property)+ln+tab+");", + "setData(" + ln + tab + entryparas(property) + ln + tab + ");", "}", "/***", "*数据批量设置", "*/", - "public "+classname+" setData(" +ln+ - "\t\t"+para + + "public " + classname + " setData(" + ln + + "\t\t" + para + "){", setString(property), "return this;", @@ -115,23 +114,23 @@ public class AutoCreatedModelFile { "*/", "public Map paginate(int pageNumber, int pageSize,String para,Object value) throws Exception {", classTextStringLine(new String[]{ - tab+"Object[] o=new Object[]{};", - tab+"StringBuffer sb=new StringBuffer();", - tab+"sb.append(\"from \"+tableName);", - tab+"if(value!=null&&value!=null&&value!=\"\")", - tab+"{", - tab+tab+"o= new Object[]{value};", - tab+tab+"sb.append(\" where \"+para+\"=?\");", - tab+"}", - tab+"sb.append(\" order by \"+primaryKey+\" DESC\");", + tab + "Object[] o=new Object[]{};", + tab + "StringBuffer sb=new StringBuffer();", + tab + "sb.append(\"from \"+tableName);", + tab + "if(value!=null&&value!=null&&value!=\"\")", + tab + "{", + tab + tab + "o= new Object[]{value};", + tab + tab + "sb.append(\" where \"+para+\"=?\");", + tab + "}", + tab + "sb.append(\" order by \"+primaryKey+\" DESC\");", //----------------------", //数据封装", - tab+"Long num=Db.queryLong(\"select count(1) \"+sb.toString(),o);", - tab+"List data = paginate(pageNumber, pageSize, \"select *\", sb.toString(),o).getList();", - tab+"Map m=new HashMap();", - tab+tab+"m.put(\"data\", data);", - tab+tab+"m.put(\"num\", num);", - tab+"return m;", + tab + "Long num=Db.queryLong(\"select count(1) \"+sb.toString(),o);", + tab + "List data = paginate(pageNumber, pageSize, \"select *\", sb.toString(),o).getList();", + tab + "Map m=new HashMap();", + tab + tab + "m.put(\"data\", data);", + tab + tab + "m.put(\"num\", num);", + tab + "return m;", "}" }) @@ -139,6 +138,7 @@ public class AutoCreatedModelFile { sb.append(ln + "}"); return sb.toString(); } + /*** * 创建文件 * @param path @@ -146,40 +146,36 @@ public class AutoCreatedModelFile { * @return * @throws IOException */ - private String createdFile(String path,String filename) throws IOException - { + private String createdFile(String path, String filename) throws IOException { //判断文件夹是否存在 - File dir=new File(path); - if(!dir.exists())dir.mkdirs(); + File dir = new File(path); + if (!dir.exists()) dir.mkdirs(); so.p(dir.getPath()); //判断文件是否存在 - File f=new File(dir.getPath()+"/"+filename); - if(!f.exists()) - { + File f = new File(dir.getPath() + "/" + filename); + if (!f.exists()) { f.createNewFile(); - } - else - { + } else { f.delete(); f.createNewFile(); } return f.getPath(); } + /*** * 文本格式化 * @param s * @return */ - private String classTextStringLine(String[] s) - { - StringBuffer sb=new StringBuffer(); - for(String k:s) - { - sb.append("\t\t" +k+"\r\n"); + private String classTextStringLine(String[] s) { + StringBuffer sb = new StringBuffer(); + for (String k : s) { + sb.append("\t\t" + k + "\r\n"); } return sb.toString(); } + /*** * 构建类似Bean * @param classname @@ -187,9 +183,8 @@ public class AutoCreatedModelFile { * @return */ @SuppressWarnings("rawtypes") - private String entryBean(String classname,Map property) - { - StringBuffer sb=new StringBuffer(); + private String entryBean(String classname, Map property) { + StringBuffer sb = new StringBuffer(); sb.append("\r\n"); /*//构建引用 Iterator i=property.entrySet().iterator(); @@ -199,106 +194,113 @@ public class AutoCreatedModelFile { + com.dsideal.GenerateCode.FileNameManager.CamelCase(e.getKey().toString().split("_"))+";" + "\r\n"); }*/ //构建setter和getter - Iterator k=property.entrySet().iterator(); - while(k.hasNext()){//只遍历一次,速度快 - Map.Entry e=(Map.Entry)k.next(); - String propetyname=FileNameManager.CamelCase(e.getKey().toString().split("_")); + Iterator k = property.entrySet().iterator(); + while (k.hasNext()) {//只遍历一次,速度快 + Map.Entry e = (Map.Entry) k.next(); + String propetyname = FileNameManager.CamelCase(e.getKey().toString().split("_")); //setter - sb.append("\t\tpublic "+classname+" set" + sb.append("\t\tpublic " + classname + " set" + FileNameManager.upFirstNameNoLowerCase(propetyname) - +"("+e.getValue()+" "+propetyname+"){" +"\r\n"+ + + "(" + e.getValue() + " " + propetyname + "){" + "\r\n" + classTextStringLine( new String[]{ // tab"\t\t" +"this." +propetyname+"="+propetyname+ ";", - "\t\t" +"set(\""+e.getKey()+"\","+propetyname+");", - "\t\t" +"return this;", - "\t\t" +"}" + "\t\t" + "set(\"" + e.getKey() + "\"," + propetyname + ");", + "\t\t" + "return this;", + "\t\t" + "}" } ) + "\r\n"); - sb.append("\t\tpublic "+e.getValue()+" get" + sb.append("\t\tpublic " + e.getValue() + " get" + FileNameManager.upFirstNameNoLowerCase(propetyname) - +"(){" +"\r\n"+ + + "(){" + "\r\n" + classTextStringLine( new String[]{ - "\t\t" +"return get(\""+e.getKey()+"\");", - "\t\t" +"}" + "\t\t" + "return get(\"" + e.getKey() + "\");", + "\t\t" + "}" } ) + "\r\n"); } return sb.toString(); } + /*** * 构建传参的字符串 * @param property * @return */ @SuppressWarnings("rawtypes") - private String entrypara(Map property) - { - StringBuffer sb=new StringBuffer(); + private String entrypara(Map property) { + StringBuffer sb = new StringBuffer(); //构建引用 sb.append("\r\n"); - Iterator i=property.entrySet().iterator(); - while(i.hasNext()){//只遍历一次,速度快 - Map.Entry e=(Map.Entry)i.next(); - String propetyname=FileNameManager.CamelCase(e.getKey().toString().split("_")); - sb.append("\t\t\t\t"+e.getValue().toString()+" " - + propetyname+","+"\r\n"); + Iterator i = property.entrySet().iterator(); + while (i.hasNext()) {//只遍历一次,速度快 + Map.Entry e = (Map.Entry) i.next(); + String propetyname = FileNameManager.CamelCase(e.getKey().toString().split("_")); + sb.append("\t\t\t\t" + e.getValue().toString() + " " + + propetyname + "," + "\r\n"); } return sb.substring(4, sb.lastIndexOf(",")); } + @SuppressWarnings("rawtypes") - private String entryparas(Map property) - { - StringBuffer sb=new StringBuffer(); + private String entryparas(Map property) { + StringBuffer sb = new StringBuffer(); //构建引用 sb.append("\r\n"); - Iterator i=property.entrySet().iterator(); - while(i.hasNext()){//只遍历一次,速度快 - Map.Entry e=(Map.Entry)i.next(); - String propetyname=FileNameManager.CamelCase(e.getKey().toString().split("_")); - sb.append("\t\t\t\t"+propetyname+","+"\r\n"); + Iterator i = property.entrySet().iterator(); + while (i.hasNext()) {//只遍历一次,速度快 + Map.Entry e = (Map.Entry) i.next(); + String propetyname = FileNameManager.CamelCase(e.getKey().toString().split("_")); + sb.append("\t\t\t\t" + propetyname + "," + "\r\n"); } return sb.substring(4, sb.lastIndexOf(",")); } + /*** * 批量set * @param property * @return */ @SuppressWarnings("rawtypes") - private String setString(Map property) - { - StringBuffer sb=new StringBuffer(); + private String setString(Map property) { + StringBuffer sb = new StringBuffer(); //构建引用 sb.append("\r\n"); - Iterator i=property.entrySet().iterator(); - while(i.hasNext()){//只遍历一次,速度快 - Map.Entry e=(Map.Entry)i.next(); - String propetyname=FileNameManager.CamelCase(e.getKey().toString().split("_")); - sb.append("\t\t\t\tset(\""+e.getKey().toString()+"\","+ propetyname+");\r\n"); + Iterator i = property.entrySet().iterator(); + while (i.hasNext()) {//只遍历一次,速度快 + Map.Entry e = (Map.Entry) i.next(); + String propetyname = FileNameManager.CamelCase(e.getKey().toString().split("_")); + sb.append("\t\t\t\tset(\"" + e.getKey().toString() + "\"," + propetyname + ");\r\n"); } - return sb.substring(4, sb.length()-2); + return sb.substring(4, sb.length() - 2); } + @SuppressWarnings("rawtypes") - private String inputPackage(Map property) - { - StringBuffer sb=new StringBuffer(); + private String inputPackage(Map property) { + StringBuffer sb = new StringBuffer(); //构建引用 sb.append("\r\n"); - Iterator i=property.entrySet().iterator(); - while(i.hasNext()){//只遍历一次,速度快 - Map.Entry e=(Map.Entry)i.next(); - String type=e.getValue().toString(); - String packages=null; - if(type.equals("BigInteger")){packages="import java.math.BigIntege;\r\nr";} - else if(type.equals("BigDecimal")){packages="import java.math.BigDecimal;\r\n";} - else if(type.equals("Date")){packages="import java.util.Date;\r\n";} - else if(type.equals("Timestamp")){packages="import java.sql.Timestamp;\r\n";} - else if(type.equals("Time")){packages="import java.sql.Time;\r\n";} - else{ packages="";} + Iterator i = property.entrySet().iterator(); + while (i.hasNext()) {//只遍历一次,速度快 + Map.Entry e = (Map.Entry) i.next(); + String type = e.getValue().toString(); + String packages = null; + if (type.equals("BigInteger")) { + packages = "import java.math.BigIntege;\r\nr"; + } else if (type.equals("BigDecimal")) { + packages = "import java.math.BigDecimal;\r\n"; + } else if (type.equals("Date")) { + packages = "import java.util.Date;\r\n"; + } else if (type.equals("Timestamp")) { + packages = "import java.sql.Timestamp;\r\n"; + } else if (type.equals("Time")) { + packages = "import java.sql.Time;\r\n"; + } else { + packages = ""; + } sb.append(packages); } return sb.toString(); diff --git a/dsUtils/src/main/java/com/dsideal/GenerateCode/DataBeasTypeToJavaType.java b/dsUtils/src/main/java/com/dsideal/GenerateCode/DataBeasTypeToJavaType.java index 5dcb332e..8da1ec66 100644 --- a/dsUtils/src/main/java/com/dsideal/GenerateCode/DataBeasTypeToJavaType.java +++ b/dsUtils/src/main/java/com/dsideal/GenerateCode/DataBeasTypeToJavaType.java @@ -2,27 +2,47 @@ package com.dsideal.GenerateCode; public class DataBeasTypeToJavaType { - public String get(String type) - { - if(type.equals("char")){return "String";} - else if(type.equals("varchar")){return "String";} - else if(type.equals("blob")){return "Byte[]";} - else if(type.equals("text")){return "String";} - else if(type.equals("int")){return "Integer";} - else if(type.equals("tinyint")){return "Integer";} - else if(type.equals("smallint")){return "Integer";} - else if(type.equals("mediumint")){return "Integer";} - else if(type.equals("bit")){return "Boolean";} - else if(type.equals("bigint")){return "BigInteger";} - else if(type.equals("decimal")){return "BigDecimal";} - else if(type.equals("date")){return "Date";} - else if(type.equals("datetime")){return "Timestamp";} - else if(type.equals("timestamp")){return "Timestamp";} - else if(type.equals("time")){return "Time";} - else if(type.equals("year")){return "Date";} - else if(type.equals("float")){return "Float";} - else if(type.equals("double")){return "Double";} - else if(type.equals("integer")){return "Long";} - else{return null;} + public String get(String type) { + if (type.equals("char")) { + return "String"; + } else if (type.equals("varchar")) { + return "String"; + } else if (type.equals("blob")) { + return "Byte[]"; + } else if (type.equals("text")) { + return "String"; + } else if (type.equals("int")) { + return "Integer"; + } else if (type.equals("tinyint")) { + return "Integer"; + } else if (type.equals("smallint")) { + return "Integer"; + } else if (type.equals("mediumint")) { + return "Integer"; + } else if (type.equals("bit")) { + return "Boolean"; + } else if (type.equals("bigint")) { + return "BigInteger"; + } else if (type.equals("decimal")) { + return "BigDecimal"; + } else if (type.equals("date")) { + return "Date"; + } else if (type.equals("datetime")) { + return "Timestamp"; + } else if (type.equals("timestamp")) { + return "Timestamp"; + } else if (type.equals("time")) { + return "Time"; + } else if (type.equals("year")) { + return "Date"; + } else if (type.equals("float")) { + return "Float"; + } else if (type.equals("double")) { + return "Double"; + } else if (type.equals("integer")) { + return "Long"; + } else { + return null; + } } } diff --git a/dsUtils/src/main/java/com/dsideal/GenerateCode/FileNameManager.java b/dsUtils/src/main/java/com/dsideal/GenerateCode/FileNameManager.java index 7129cd42..c20b9a2a 100644 --- a/dsUtils/src/main/java/com/dsideal/GenerateCode/FileNameManager.java +++ b/dsUtils/src/main/java/com/dsideal/GenerateCode/FileNameManager.java @@ -8,71 +8,64 @@ public class FileNameManager { * 注意:先所有字符小写化 * */ - public static String upFirstName(String name) - { - String s=null; - if(name!=null) - { - s=name.toLowerCase(); - String first=""+s.charAt(0); - first=first.toUpperCase(); - s=first+s.substring(1, s.length()); + public static String upFirstName(String name) { + String s = null; + if (name != null) { + s = name.toLowerCase(); + String first = "" + s.charAt(0); + first = first.toUpperCase(); + s = first + s.substring(1, s.length()); } return s; } + /*** * * 首字母大写处理 * */ - public static String upFirstNameNoLowerCase(String name) - { - String s=null; - if(name!=null) - { - s=name; - String first=""+s.charAt(0); - first=first.toUpperCase(); - s=first+s.substring(1, s.length()); + public static String upFirstNameNoLowerCase(String name) { + String s = null; + if (name != null) { + s = name; + String first = "" + s.charAt(0); + first = first.toUpperCase(); + s = first + s.substring(1, s.length()); } return s; } + /*** * * 字符数组驼峰命名法处理 * */ - public static String CamelCase(String n[]) - { - String s=null; - if(n!=null&&n.length>0) - { - StringBuffer b=new StringBuffer(); + public static String CamelCase(String n[]) { + String s = null; + if (n != null && n.length > 0) { + StringBuffer b = new StringBuffer(); b.append(n[0].toLowerCase()); - for(int i=1;i0) - { - StringBuffer b=new StringBuffer(); - for(int i=0;i 0) { + StringBuffer b = new StringBuffer(); + for (int i = 0; i < n.length; i++) { b.append(upFirstName(n[i])); } - s=b.toString(); + s = b.toString(); } return s; } diff --git a/dsUtils/src/main/java/com/dsideal/GenerateCode/getJavaBean.java b/dsUtils/src/main/java/com/dsideal/GenerateCode/getJavaBean.java new file mode 100644 index 00000000..1c663c67 --- /dev/null +++ b/dsUtils/src/main/java/com/dsideal/GenerateCode/getJavaBean.java @@ -0,0 +1,31 @@ +package com.dsideal.GenerateCode; + +import com.jfinal.plugin.activerecord.ActiveRecordPlugin; +import com.jfinal.plugin.hikaricp.HikariCpPlugin; + +import javax.sql.DataSource; +import java.io.File; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; +import java.util.*; + +public class getJavaBean { + + public static void main(String[] args) throws Exception { + // 配置Druid数据源插件 + HikariCpPlugin hpPlugin = new HikariCpPlugin( + "jdbc:mysql://10.10.14.210:22066/ds_db?useUnicode=true&characterEncoding=UTF-8&useSSL=false", + "root", + "DsideaL147258369", + "com.mysql.cj.jdbc.Driver"); + + // 配置ActiveRecord插件 + ActiveRecordPlugin arp = new ActiveRecordPlugin(hpPlugin); + hpPlugin.start(); + arp.start(); + + AutoCreatedEntityName autoCreatedEntityName = new AutoCreatedEntityName(); + autoCreatedEntityName.created(new String[]{"t_wx_record"},"com.dsideal"); + } +} diff --git a/dsUtils/src/main/java/com/dsideal/R.java b/dsUtils/src/main/java/com/dsideal/R.java new file mode 100644 index 00000000..c3cd141f --- /dev/null +++ b/dsUtils/src/main/java/com/dsideal/R.java @@ -0,0 +1,50 @@ + +package com.dsideal; +/*** + * 表文件结构。 + * 对应表文件名。 + * 在Model中不需要记住对应的表名。 + * 只用此文件中对应的名称。 + * 同时避免了字段名修改,删除后程序结构破坏。 + * @author 石啸天 + * + */ +public final class R { + + /*** + *表名:t_wx_record + */ + public static final class tWxRecord{ + public static final String tableName="t_wx_record"; + public static final String stationName="station_name"; + public static final String connectorno="connectorNo"; + public static final String typeName="type_name"; + public static final String createTime="create_time"; + public static final String connectorid="connectorId"; + public static final String typeId="type_id"; + public static final String stationId="station_id"; + public static final String memo="memo"; + public static final String equipmentid="equipmentId"; + public static final String wxOpenid="wx_openid"; + public static final String statusId="status_id"; + public static final String equipmentname="equipmentName"; + public static final String id="id"; + public static final String[] all={ + stationName, + connectorno, + typeName, + createTime, + connectorid, + typeId, + stationId, + memo, + equipmentid, + wxOpenid, + statusId, + equipmentname, + id + }; + public static final Integer size=13; + } + +} \ No newline at end of file diff --git a/dsUtils/src/main/java/com/dsideal/tWxRecord/Twxrecord.java b/dsUtils/src/main/java/com/dsideal/tWxRecord/Twxrecord.java new file mode 100644 index 00000000..0de2522b --- /dev/null +++ b/dsUtils/src/main/java/com/dsideal/tWxRecord/Twxrecord.java @@ -0,0 +1,255 @@ + +package com.dsideal.tWxRecord; + +import com.jfinal.plugin.activerecord.Model; +import com.jfinal.plugin.activerecord.TableMapping; +import com.jfinal.plugin.activerecord.Db; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import java.sql.Timestamp; + +/*** + * 自动生成的Model + * @author 石啸天 + * + */ +@SuppressWarnings("serial") +public class Twxrecord extends Model { + //--------------setter和getter--------------- + + public Twxrecord setStationName(String stationName) { + set("station_name", stationName); + return this; + } + + public String getStationName() { + return get("station_name"); + } + + public Twxrecord setConnectorno(String connectorno) { + set("connectorNo", connectorno); + return this; + } + + public String getConnectorno() { + return get("connectorNo"); + } + + public Twxrecord setTypeName(String typeName) { + set("type_name", typeName); + return this; + } + + public String getTypeName() { + return get("type_name"); + } + + public Twxrecord setCreateTime(Timestamp createTime) { + set("create_time", createTime); + return this; + } + + public Timestamp getCreateTime() { + return get("create_time"); + } + + public Twxrecord setConnectorid(Integer connectorid) { + set("connectorId", connectorid); + return this; + } + + public Integer getConnectorid() { + return get("connectorId"); + } + + public Twxrecord setTypeId(Integer typeId) { + set("type_id", typeId); + return this; + } + + public Integer getTypeId() { + return get("type_id"); + } + + public Twxrecord setStationId(Integer stationId) { + set("station_id", stationId); + return this; + } + + public Integer getStationId() { + return get("station_id"); + } + + public Twxrecord setMemo(String memo) { + set("memo", memo); + return this; + } + + public String getMemo() { + return get("memo"); + } + + public Twxrecord setEquipmentid(Integer equipmentid) { + set("equipmentId", equipmentid); + return this; + } + + public Integer getEquipmentid() { + return get("equipmentId"); + } + + public Twxrecord setWxOpenid(String wxOpenid) { + set("wx_openid", wxOpenid); + return this; + } + + public String getWxOpenid() { + return get("wx_openid"); + } + + public Twxrecord setStatusId(Integer statusId) { + set("status_id", statusId); + return this; + } + + public Integer getStatusId() { + return get("status_id"); + } + + public Twxrecord setEquipmentname(String equipmentname) { + set("equipmentName", equipmentname); + return this; + } + + public String getEquipmentname() { + return get("equipmentName"); + } + + public Twxrecord setId(Integer id) { + set("id", id); + return this; + } + + public Integer getId() { + return get("id"); + } + + + //------------------------------------------- + /*** + *数据库操作实体 + */ + public static final Twxrecord dao = new Twxrecord(); + /** + * 表名 + */ + public static final String tableName = "tWxRecord"; + /** + * 表主键 + */ + public static final String[] primaryKey = TableMapping.me().getTable(dao.getClass()).getPrimaryKey(); + + /*** + * 空构造 + */ + public Twxrecord() { + } + + /*** + * 有参构造 + */ + public Twxrecord( + String stationName, + String connectorno, + String typeName, + Timestamp createTime, + Integer connectorid, + Integer typeId, + Integer stationId, + String memo, + Integer equipmentid, + String wxOpenid, + Integer statusId, + String equipmentname, + Integer id + ) { + setData( + stationName, + connectorno, + typeName, + createTime, + connectorid, + typeId, + stationId, + memo, + equipmentid, + wxOpenid, + statusId, + equipmentname, + id + ); + } + + /*** + *数据批量设置 + */ + public Twxrecord setData( + String stationName, + String connectorno, + String typeName, + Timestamp createTime, + Integer connectorid, + Integer typeId, + Integer stationId, + String memo, + Integer equipmentid, + String wxOpenid, + Integer statusId, + String equipmentname, + Integer id) { + set("station_name", stationName); + set("connectorNo", connectorno); + set("type_name", typeName); + set("create_time", createTime); + set("connectorId", connectorid); + set("type_id", typeId); + set("station_id", stationId); + set("memo", memo); + set("equipmentId", equipmentid); + set("wx_openid", wxOpenid); + set("status_id", statusId); + set("equipmentName", equipmentname); + set("id", id); + return this; + } + + /*** + * 按ID逆序查询全部数据 + * 出现SQL注入漏洞 + * @param pageNumber 页码 + * @param pageSize 每页记录数 + * @return + * @throws Exception + */ + public Map paginate(int pageNumber, int pageSize, String para, Object value) throws Exception { + Object[] o = new Object[]{}; + StringBuffer sb = new StringBuffer(); + sb.append("from " + tableName); + if (value != null && value != null && value != "") { + o = new Object[]{value}; + sb.append(" where " + para + "=?"); + } + sb.append(" order by " + primaryKey + " DESC"); + Long num = Db.queryLong("select count(1) " + sb.toString(), o); + List data = paginate(pageNumber, pageSize, "select *", sb.toString(), o).getList(); + Map m = new HashMap(); + m.put("data", data); + m.put("num", num); + return m; + } + + +} \ No newline at end of file