main
黄海 10 months ago
parent bd962e6fe6
commit 26a8868108

@ -35,6 +35,33 @@
<artifactId>cos</artifactId>
<version>${jfinal-cos.version}</version>
</dependency>
<!--引用光-->
<!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>${HikariCP.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<!--日志logback-->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<!--安装hutool-->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>${hutool.version}</version>
</dependency>
</dependencies>
<build>
<resources>

@ -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() {
}
/***
*
*/
@ -114,31 +109,24 @@ public class AutoCreatedEntityName {
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 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 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;
}
}
}

@ -7,7 +7,6 @@ import java.util.Iterator;
import java.util.Map;
import com.jfinal.core.JFinal;
import com.dsideal.GenerateCode.so;
/***
* settergetterModel
@ -20,10 +19,9 @@ public class AutoCreatedModelFile {
//-----------------------拼装文件夹名
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 dir = "D:\\dsWork\\dsProject\\dsUtils\\src\\main\\java";
file.append(dir);
for (String p : pn) {
file.append("/");
file.append(p);
}
@ -37,6 +35,7 @@ public class AutoCreatedModelFile {
fileWriter.flush();
fileWriter.close();
}
/***
*
* @param tableName
@ -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();
so.p(dir.getPath());
//判断文件是否存在
File f = new File(dir.getPath() + "/" + filename);
if(!f.exists())
{
if (!f.exists()) {
f.createNewFile();
}
else
{
} else {
f.delete();
f.createNewFile();
}
return f.getPath();
}
/***
*
* @param s
* @return
*/
private String classTextStringLine(String[] s)
{
private String classTextStringLine(String[] s) {
StringBuffer sb = new StringBuffer();
for(String k:s)
{
for (String k : s) {
sb.append("\t\t" + k + "\r\n");
}
return sb.toString();
}
/***
* Bean
* @param classname
@ -187,8 +183,7 @@ public class AutoCreatedModelFile {
* @return
*/
@SuppressWarnings("rawtypes")
private String entryBean(String classname,Map<String,String> property)
{
private String entryBean(String classname, Map<String, String> property) {
StringBuffer sb = new StringBuffer();
sb.append("\r\n");
/*//构建引用
@ -229,14 +224,14 @@ public class AutoCreatedModelFile {
}
return sb.toString();
}
/***
*
* @param property
* @return
*/
@SuppressWarnings("rawtypes")
private String entrypara(Map<String,String> property)
{
private String entrypara(Map<String, String> property) {
StringBuffer sb = new StringBuffer();
//构建引用
sb.append("\r\n");
@ -249,9 +244,9 @@ public class AutoCreatedModelFile {
}
return sb.substring(4, sb.lastIndexOf(","));
}
@SuppressWarnings("rawtypes")
private String entryparas(Map<String,String> property)
{
private String entryparas(Map<String, String> property) {
StringBuffer sb = new StringBuffer();
//构建引用
sb.append("\r\n");
@ -263,14 +258,14 @@ public class AutoCreatedModelFile {
}
return sb.substring(4, sb.lastIndexOf(","));
}
/***
* set
* @param property
* @return
*/
@SuppressWarnings("rawtypes")
private String setString(Map<String,String> property)
{
private String setString(Map<String, String> property) {
StringBuffer sb = new StringBuffer();
//构建引用
sb.append("\r\n");
@ -282,9 +277,9 @@ public class AutoCreatedModelFile {
}
return sb.substring(4, sb.length() - 2);
}
@SuppressWarnings("rawtypes")
private String inputPackage(Map<String,String> property)
{
private String inputPackage(Map<String, String> property) {
StringBuffer sb = new StringBuffer();
//构建引用
sb.append("\r\n");
@ -293,12 +288,19 @@ public class AutoCreatedModelFile {
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="";}
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();

@ -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;
}
}
}

@ -8,11 +8,9 @@ public class FileNameManager {
*
*
*/
public static String upFirstName(String name)
{
public static String upFirstName(String name) {
String s = null;
if(name!=null)
{
if (name != null) {
s = name.toLowerCase();
String first = "" + s.charAt(0);
first = first.toUpperCase();
@ -20,16 +18,15 @@ public class FileNameManager {
}
return s;
}
/***
*
*
*
*/
public static String upFirstNameNoLowerCase(String name)
{
public static String upFirstNameNoLowerCase(String name) {
String s = null;
if(name!=null)
{
if (name != null) {
s = name;
String first = "" + s.charAt(0);
first = first.toUpperCase();
@ -37,39 +34,35 @@ public class FileNameManager {
}
return s;
}
/***
*
*
*
*/
public static String CamelCase(String n[])
{
public static String CamelCase(String n[]) {
String s = null;
if(n!=null&&n.length>0)
{
if (n != null && n.length > 0) {
StringBuffer b = new StringBuffer();
b.append(n[0].toLowerCase());
for(int i=1;i<n.length;i++)
{
for (int i = 1; i < n.length; i++) {
b.append(upFirstName(n[i]));
}
s = b.toString();
}
return s;
}
/***
*
*
*
*/
public static String upFirstName(String n[])
{
public static String upFirstName(String n[]) {
String s = null;
if(n!=null&&n.length>0)
{
if (n != null && n.length > 0) {
StringBuffer b = new StringBuffer();
for(int i=0;i<n.length;i++)
{
for (int i = 0; i < n.length; i++) {
b.append(upFirstName(n[i]));
}
s = b.toString();

@ -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");
}
}

@ -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;
}
}

@ -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<Twxrecord> {
//--------------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<String, Object> 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<String, Object> m = new HashMap<String, Object>();
m.put("data", data);
m.put("num", num);
return m;
}
}
Loading…
Cancel
Save