diff --git a/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend-maven-plugin/src/main/java/com/micro/fast/mybatis/generator/extend/mojo/MyabtisGeneratorExtendMojo.java b/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend-maven-plugin/src/main/java/com/micro/fast/mybatis/generator/extend/mojo/MyabtisGeneratorExtendMojo.java index 7194738..0c02aef 100644 --- a/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend-maven-plugin/src/main/java/com/micro/fast/mybatis/generator/extend/mojo/MyabtisGeneratorExtendMojo.java +++ b/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend-maven-plugin/src/main/java/com/micro/fast/mybatis/generator/extend/mojo/MyabtisGeneratorExtendMojo.java @@ -1,50 +1,42 @@ package com.micro.fast.mybatis.generator.extend.mojo; +import com.micro.fast.mybatis.generator.extend.service.MybatisGeneratorExtend; +import com.micro.fast.mybatis.generator.extend.util.FreemarkerUtil; +import com.micro.fast.mybatis.generator.extend.util.JarUtil; +import com.micro.fast.mybatis.generator.extend.util.PropertiesUtil; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; import java.util.Iterator; import java.util.Map; import java.util.Set; -import java.util.jar.JarEntry; -import java.util.jar.JarInputStream; @Mojo(name = "generateFiles") public class MyabtisGeneratorExtendMojo extends AbstractMojo { + + @Override public void execute() throws MojoExecutionException, MojoFailureException { - //获取当前项目jar包的路径 - String path = MyabtisGeneratorExtendMojo.class.getProtectionDomain().getCodeSource().getLocation().getPath(); - JarInputStream jarInputStream =null; - try { - jarInputStream = new JarInputStream(new FileInputStream(new File(path))); - } catch (IOException e) { - e.printStackTrace(); - }finally { - try { - jarInputStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - InputStream templates = this.getClass().getClassLoader().getResourceAsStream("templates"); - System.out.println(path); + String projectPath =null; Map pluginContext = getPluginContext(); Set set = pluginContext.entrySet(); Iterator iterator = set.iterator(); while (iterator.hasNext()){ Object next = iterator.next(); - System.out.println("---++++++++++++++++++++"+next); - System.out.println(pluginContext.get(next)+"++++++++++++++++++++++++"); + String s = next.toString(); + String[] split = s.split(" "); + for (String s1 : split) { + if (s1.endsWith("pom.xml")){ + int lastIndexOf = s1.lastIndexOf("pom.xml"); + projectPath = s1.substring(0,lastIndexOf-1); + } + } } - + new PropertiesUtil().loadProperties(projectPath); + MybatisGeneratorExtend.GenerateMybatisGeneratorNeedFilesByTemplates(projectPath); } } diff --git a/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend-maven-plugin/src/main/java/com/micro/fast/mybatis/generator/extend/service/MybatisGeneratorExtend.java b/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend-maven-plugin/src/main/java/com/micro/fast/mybatis/generator/extend/service/MybatisGeneratorExtend.java index 0546d15..d77f35e 100644 --- a/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend-maven-plugin/src/main/java/com/micro/fast/mybatis/generator/extend/service/MybatisGeneratorExtend.java +++ b/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend-maven-plugin/src/main/java/com/micro/fast/mybatis/generator/extend/service/MybatisGeneratorExtend.java @@ -4,8 +4,10 @@ import com.micro.fast.mybatis.generator.extend.db.JdbcConnection; import com.micro.fast.mybatis.generator.extend.pojo.Db; import com.micro.fast.mybatis.generator.extend.pojo.MybatisGenerator; import com.micro.fast.mybatis.generator.extend.util.FreemarkerUtil; +import com.micro.fast.mybatis.generator.extend.util.JarUtil; import com.micro.fast.mybatis.generator.extend.util.PropertiesUtil; +import java.io.File; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; @@ -46,7 +48,7 @@ public class MybatisGeneratorExtend { /** * 根据模板引擎生成mybatis-generator需要的文件 */ - public static void GenerateMybatisGeneratorNeedFilesByTemplates() { + public static void GenerateMybatisGeneratorNeedFilesByTemplates(String projectPath) { Connection jdbcConection = JdbcConnection.getJdbcConection(); Statement statement = null; ResultSet resultSet = null; @@ -77,8 +79,16 @@ public class MybatisGeneratorExtend { Map mybatisGeneratorModel = new HashMap<>(); mybatisGeneratorModel.put("db",MybatisGeneratorExtend.db); mybatisGeneratorModel.put("mybatisGenerator",MybatisGeneratorExtend.mybatisGenerator); - boolean mybatisGeneratorFileSuccess = FreemarkerUtil.createFile("mybatisGenerator.ftl", mybatisGeneratorModel, "mybatisGenerator.properties"); - boolean generatorConfigFileSuccess = FreemarkerUtil.createFile("generatorConfig.ftl", mybatisGeneratorModel, "generatorConfig.xml"); + boolean mybatisGeneratorFileSuccess = FreemarkerUtil.createFile("mybatisGenerator.ftl", mybatisGeneratorModel, "mybatisGenerator.properties",projectPath); + File file = new File(JarUtil.getThisJarPathParent() + "/templates" + "/mybatisGenerator.ftl"); + if (file.exists()){ + file.delete(); + } + boolean generatorConfigFileSuccess = FreemarkerUtil.createFile("generatorConfig.ftl", mybatisGeneratorModel, "generatorConfig.xml",projectPath); + File file1 = new File(JarUtil.getThisJarPathParent() + "/templates" + "/generatorConfig.ftl"); + if (file1.exists()){ + file1.delete(); + } } catch (SQLException e) { e.printStackTrace(); } finally { diff --git a/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend-maven-plugin/src/main/java/com/micro/fast/mybatis/generator/extend/util/FreemarkerUtil.java b/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend-maven-plugin/src/main/java/com/micro/fast/mybatis/generator/extend/util/FreemarkerUtil.java index 822d6af..845db48 100644 --- a/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend-maven-plugin/src/main/java/com/micro/fast/mybatis/generator/extend/util/FreemarkerUtil.java +++ b/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend-maven-plugin/src/main/java/com/micro/fast/mybatis/generator/extend/util/FreemarkerUtil.java @@ -1,12 +1,15 @@ package com.micro.fast.mybatis.generator.extend.util; +import com.micro.fast.mybatis.generator.extend.mojo.MyabtisGeneratorExtendMojo; import com.micro.fast.mybatis.generator.extend.service.MybatisGeneratorExtend; import freemarker.core.ParseException; import freemarker.template.*; import java.io.*; import java.net.URL; +import java.util.Iterator; import java.util.Map; +import java.util.Set; /** * 根据freemarker模板生成文件 @@ -36,14 +39,12 @@ public class FreemarkerUtil { //1.设置编码 cfg.setDefaultEncoding("utf-8"); - //2.设置加载模板文件的位置,这个位置是随着这个class加载的目录位置而确定的 - URL resource = FreemarkerUtil.class.getResource("/" + templatesDirUrl); - String path = resource.getPath(); + //2.解压所需要的jar中的文件,设置加载模板文件的位置 + JarUtil.unThisJar(); try { - cfg.setDirectoryForTemplateLoading(new File(path)); + cfg.setDirectoryForTemplateLoading(new File(JarUtil.getThisJarPathParent()+"/"+templatesDirUrl)); } catch (IOException e) { e.printStackTrace(); - System.out.println("-----------加载mybatis-generator-extend模板文件失败------------"); } } @@ -54,14 +55,11 @@ public class FreemarkerUtil { * @param targetFileName * @return */ - public static boolean createFile(String templateName, Map data, String targetFileName) { + public static boolean createFile(String templateName, Map data, String targetFileName,String projectPath) { Template template = null; Writer out = null; //1.获取当前项目classpath路径 - String classPath = FreemarkerUtil.class.getResource("/").getPath(); - int lastIndexOf = classPath.lastIndexOf("target"); - String projectDir = classPath.substring(0, lastIndexOf); - String resourcesDir = projectDir+"src/main/resources"; + String resourcesDir = projectPath+"/"+"src/main/resources"; File file = new File(resourcesDir); if (!file.exists()){ try { @@ -133,6 +131,5 @@ public class FreemarkerUtil { System.out.println(System.getProperty("user.dir")); //5.获取所有的类的jar的加载路径 System.out.println(System.getProperty("java.class.path")); - MybatisGeneratorExtend.GenerateMybatisGeneratorNeedFilesByTemplates(); } } diff --git a/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend-maven-plugin/src/main/java/com/micro/fast/mybatis/generator/extend/util/JarUtil.java b/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend-maven-plugin/src/main/java/com/micro/fast/mybatis/generator/extend/util/JarUtil.java index f8c8d1c..d68b3c3 100644 --- a/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend-maven-plugin/src/main/java/com/micro/fast/mybatis/generator/extend/util/JarUtil.java +++ b/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend-maven-plugin/src/main/java/com/micro/fast/mybatis/generator/extend/util/JarUtil.java @@ -19,16 +19,20 @@ public class JarUtil { JarInputStream jarInputStream = null; JarFile jarFile = null; try { + //1.获取当前项目jar包的路径 jarInputStream = new JarInputStream(new FileInputStream(new File(getThisJarPath()))); jarFile = new JarFile(new File(getThisJarPath())); JarEntry jarEntry = null; while ((jarEntry = jarInputStream.getNextJarEntry())!=null){ String fileName = jarEntry.getName(); - if ("generatorConfig.ftl".equals(fileName)||"mybatisGenerator.ftl".equals(fileName)){ + if (fileName.endsWith("generatorConfig.ftl")||fileName.endsWith("mybatisGenerator.ftl")){ File file = new File(getThisJarPathParent() +"/"+fileName); if (file.exists()){ file.delete(); } + if (!new File(file.getParent()).exists()){ + new File(file.getParent()).mkdirs(); + } InputStream inputStream = null; OutputStream outputStream = null; try { @@ -43,9 +47,7 @@ public class JarUtil { outputStream.close(); inputStream.close(); } - } - jarEntry = null; } } catch (IOException e) { e.printStackTrace(); diff --git a/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend-maven-plugin/src/main/java/com/micro/fast/mybatis/generator/extend/util/PropertiesUtil.java b/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend-maven-plugin/src/main/java/com/micro/fast/mybatis/generator/extend/util/PropertiesUtil.java index e22ea56..7c4ddd1 100644 --- a/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend-maven-plugin/src/main/java/com/micro/fast/mybatis/generator/extend/util/PropertiesUtil.java +++ b/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend-maven-plugin/src/main/java/com/micro/fast/mybatis/generator/extend/util/PropertiesUtil.java @@ -7,27 +7,7 @@ public class PropertiesUtil { private static final String PROPERTIES_PATH = "mybatisStart.properties"; private static Properties properties = null; static { - //1.获取当前项目classpath路径 - String classPath = FreemarkerUtil.class.getResource("/").getPath(); - //2.将mybatisStart.properties配置文件加载到输入流中 - File file = new File(classPath + PROPERTIES_PATH); - if (file.exists()){ - InputStream inputStream = null; - try { - inputStream = new FileInputStream(file); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - //3.将输入流写入到properties对象中 - if (properties==null){ - properties = new Properties(); - } - try { - properties.load(inputStream); - } catch (IOException e) { - e.printStackTrace(); - } - } + } /** @@ -58,4 +38,25 @@ public class PropertiesUtil { public static void setProperties(Properties properties) { PropertiesUtil.properties = properties; } + public void loadProperties(String projectPath){ + //2.将mybatisStart.properties配置文件加载到输入流中 + File file = new File( projectPath+"/src/main/resources/"+PROPERTIES_PATH); + if (file.exists()){ + InputStream inputStream = null; + try { + inputStream = new FileInputStream(file); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + //3.将输入流写入到properties对象中 + if (properties==null){ + properties = new Properties(); + } + try { + properties.load(inputStream); + } catch (IOException e) { + e.printStackTrace(); + } + } + } } diff --git a/ms/upms/src/main/java/com/micro/fast/upms/dao/UpmsSystemMapper.java b/ms/upms/src/main/java/com/micro/fast/upms/dao/UpmsSystemMapper.java new file mode 100644 index 0000000..f048422 --- /dev/null +++ b/ms/upms/src/main/java/com/micro/fast/upms/dao/UpmsSystemMapper.java @@ -0,0 +1,17 @@ +package com.micro.fast.upms.dao; + +import com.micro.fast.upms.pojo.UpmsSystem; + +public interface UpmsSystemMapper { + int deleteByPrimaryKey(Integer id); + + int insert(UpmsSystem record); + + int insertSelective(UpmsSystem record); + + UpmsSystem selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(UpmsSystem record); + + int updateByPrimaryKey(UpmsSystem record); +} \ No newline at end of file diff --git a/ms/upms/src/main/java/com/micro/fast/upms/pojo/UpmsSystem.java b/ms/upms/src/main/java/com/micro/fast/upms/pojo/UpmsSystem.java new file mode 100644 index 0000000..273c488 --- /dev/null +++ b/ms/upms/src/main/java/com/micro/fast/upms/pojo/UpmsSystem.java @@ -0,0 +1,156 @@ +package com.micro.fast.upms.pojo; + +import java.io.Serializable; + +public class UpmsSystem implements Serializable { + private Integer id; + + private String icon; + + private String banner; + + private String theme; + + private String basepath; + + private Byte status; + + private String name; + + private String title; + + private String description; + + private Long ctime; + + private Long orders; + + private static final long serialVersionUID = 1L; + + public UpmsSystem(Integer id, String icon, String banner, String theme, String basepath, Byte status, String name, String title, String description, Long ctime, Long orders) { + this.id = id; + this.icon = icon; + this.banner = banner; + this.theme = theme; + this.basepath = basepath; + this.status = status; + this.name = name; + this.title = title; + this.description = description; + this.ctime = ctime; + this.orders = orders; + } + + public UpmsSystem() { + super(); + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getIcon() { + return icon; + } + + public void setIcon(String icon) { + this.icon = icon == null ? null : icon.trim(); + } + + public String getBanner() { + return banner; + } + + public void setBanner(String banner) { + this.banner = banner == null ? null : banner.trim(); + } + + public String getTheme() { + return theme; + } + + public void setTheme(String theme) { + this.theme = theme == null ? null : theme.trim(); + } + + public String getBasepath() { + return basepath; + } + + public void setBasepath(String basepath) { + this.basepath = basepath == null ? null : basepath.trim(); + } + + public Byte getStatus() { + return status; + } + + public void setStatus(Byte status) { + this.status = status; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name == null ? null : name.trim(); + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title == null ? null : title.trim(); + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description == null ? null : description.trim(); + } + + public Long getCtime() { + return ctime; + } + + public void setCtime(Long ctime) { + this.ctime = ctime; + } + + public Long getOrders() { + return orders; + } + + public void setOrders(Long orders) { + this.orders = orders; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", id=").append(id); + sb.append(", icon=").append(icon); + sb.append(", banner=").append(banner); + sb.append(", theme=").append(theme); + sb.append(", basepath=").append(basepath); + sb.append(", status=").append(status); + sb.append(", name=").append(name); + sb.append(", title=").append(title); + sb.append(", description=").append(description); + sb.append(", ctime=").append(ctime); + sb.append(", orders=").append(orders); + sb.append("]"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/ms/upms/src/main/resources/generatorConfig--.xml b/ms/upms/src/main/resources/generatorConfig.xml similarity index 57% rename from ms/upms/src/main/resources/generatorConfig--.xml rename to ms/upms/src/main/resources/generatorConfig.xml index f2d383d..bc53172 100644 --- a/ms/upms/src/main/resources/generatorConfig--.xml +++ b/ms/upms/src/main/resources/generatorConfig.xml @@ -1,83 +1,80 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-
-
-
-
-
-
-
-
-
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/ms/upms/src/main/resources/mappers/UpmsSystemMapper.xml b/ms/upms/src/main/resources/mappers/UpmsSystemMapper.xml new file mode 100644 index 0000000..647a1bb --- /dev/null +++ b/ms/upms/src/main/resources/mappers/UpmsSystemMapper.xml @@ -0,0 +1,165 @@ + + + + + + + + + + + + + + + + + + + + id, icon, banner, theme, basepath, status, name, title, description, ctime, orders + + + + delete from upms_system + where id = #{id,jdbcType=INTEGER} + + + insert into upms_system (id, icon, banner, + theme, basepath, status, + name, title, description, + ctime, orders) + values (#{id,jdbcType=INTEGER}, #{icon,jdbcType=VARCHAR}, #{banner,jdbcType=VARCHAR}, + #{theme,jdbcType=VARCHAR}, #{basepath,jdbcType=VARCHAR}, #{status,jdbcType=TINYINT}, + #{name,jdbcType=VARCHAR}, #{title,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, + #{ctime,jdbcType=BIGINT}, #{orders,jdbcType=BIGINT}) + + + insert into upms_system + + + id, + + + icon, + + + banner, + + + theme, + + + basepath, + + + status, + + + name, + + + title, + + + description, + + + ctime, + + + orders, + + + + + #{id,jdbcType=INTEGER}, + + + #{icon,jdbcType=VARCHAR}, + + + #{banner,jdbcType=VARCHAR}, + + + #{theme,jdbcType=VARCHAR}, + + + #{basepath,jdbcType=VARCHAR}, + + + #{status,jdbcType=TINYINT}, + + + #{name,jdbcType=VARCHAR}, + + + #{title,jdbcType=VARCHAR}, + + + #{description,jdbcType=VARCHAR}, + + + #{ctime,jdbcType=BIGINT}, + + + #{orders,jdbcType=BIGINT}, + + + + + update upms_system + + + icon = #{icon,jdbcType=VARCHAR}, + + + banner = #{banner,jdbcType=VARCHAR}, + + + theme = #{theme,jdbcType=VARCHAR}, + + + basepath = #{basepath,jdbcType=VARCHAR}, + + + status = #{status,jdbcType=TINYINT}, + + + name = #{name,jdbcType=VARCHAR}, + + + title = #{title,jdbcType=VARCHAR}, + + + description = #{description,jdbcType=VARCHAR}, + + + ctime = #{ctime,jdbcType=BIGINT}, + + + orders = #{orders,jdbcType=BIGINT}, + + + where id = #{id,jdbcType=INTEGER} + + + update upms_system + set icon = #{icon,jdbcType=VARCHAR}, + banner = #{banner,jdbcType=VARCHAR}, + theme = #{theme,jdbcType=VARCHAR}, + basepath = #{basepath,jdbcType=VARCHAR}, + status = #{status,jdbcType=TINYINT}, + name = #{name,jdbcType=VARCHAR}, + title = #{title,jdbcType=VARCHAR}, + description = #{description,jdbcType=VARCHAR}, + ctime = #{ctime,jdbcType=BIGINT}, + orders = #{orders,jdbcType=BIGINT} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file diff --git a/ms/upms/src/main/resources/mybatisGenerator--.properties b/ms/upms/src/main/resources/mybatisGenerator.properties similarity index 57% rename from ms/upms/src/main/resources/mybatisGenerator--.properties rename to ms/upms/src/main/resources/mybatisGenerator.properties index b6818cf..93e5c90 100644 --- a/ms/upms/src/main/resources/mybatisGenerator--.properties +++ b/ms/upms/src/main/resources/mybatisGenerator.properties @@ -1,5 +1,5 @@ db.driverLocation=/root/mysql-connector-java-5.1.40-bin.jar db.driverClassName=com.mysql.jdbc.Driver -db.url=jdbc:mysql://172.17.0.1:3317/micro?useUncoide=true&chracterEncoding=utf-8&useSSL=false +db.url=jdbc:mysql://172.17.0.1:3317/micro?useUncoide=true&chracterEncoding=utf-8&useSSL=false db.username=root db.password=studyj2e \ No newline at end of file diff --git a/ms/upms/src/main/resources/mybatisStart.properties b/ms/upms/src/main/resources/mybatisStart.properties index 225a4d2..e2f677a 100644 --- a/ms/upms/src/main/resources/mybatisStart.properties +++ b/ms/upms/src/main/resources/mybatisStart.properties @@ -4,6 +4,6 @@ db.driverClassName=com.mysql.jdbc.Driver db.url=jdbc:mysql://172.17.0.1:3317/micro?useUncoide=true&chracterEncoding=utf-8&useSSL=false db.username=root db.password=studyj2e -mybatisGenerator.pojoPackage=pojoPackage -mybatisGenerator.daoPackage=daoPackage +mybatisGenerator.pojoPackage=com.micro.fast.upms.pojo +mybatisGenerator.daoPackage=com.micro.fast.upms.dao mybatisGenerator.tablesPrefix=upms \ No newline at end of file