mirror of
https://github.com/moshowgame/SpringBootCodeGenerator.git
synced 2025-12-26 13:52:39 +08:00
修复FreemarkerUtil的Path问题导致JAR包运行时无法获取template的问题。
This commit is contained in:
parent
83f15b4034
commit
0ed4d7ace6
@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
|更新日期|更新内容|
|
|更新日期|更新内容|
|
||||||
|----|----|
|
|----|----|
|
||||||
|
|20200621|修复FreemarkerUtil的Path问题导致JAR包运行时无法获取template的问题。|
|
||||||
|20200525|1.一些fix,关于封装工具类以及layui模板优化等.<br> 2.优化表备注的获取逻辑.<br> 3.生成时间格式改为yyyy-MM-dd,移除具体的时间,只保留日期|
|
|20200525|1.一些fix,关于封装工具类以及layui模板优化等.<br> 2.优化表备注的获取逻辑.<br> 3.生成时间格式改为yyyy-MM-dd,移除具体的时间,只保留日期|
|
||||||
|20200522|1.新增insert-sql模式,支持对"insert into table (xxx) values (xxx)"语句进行处理,生成java代码(感谢三叔的建议).|
|
|20200522|1.新增insert-sql模式,支持对"insert into table (xxx) values (xxx)"语句进行处理,生成java代码(感谢三叔的建议).|
|
||||||
|20200517|1.代码重构!异常处理优化,Freemarker相关工具类优化,简化模板生成部分,通过template.json来配置需要生成的模板,不需要配置java文件.<br> 2.修复包含comment关键字时注释无法识别的问题.(感谢@1nchaos的反馈).<br> 3.赞赏优化,感谢大家的赞赏.<br> 4.新增mapper2(Mybatis-Annotation模板)(感谢@baisi525和@CHKEGit的建议).|
|
|20200517|1.代码重构!异常处理优化,Freemarker相关工具类优化,简化模板生成部分,通过template.json来配置需要生成的模板,不需要配置java文件.<br> 2.修复包含comment关键字时注释无法识别的问题.(感谢@1nchaos的反馈).<br> 3.赞赏优化,感谢大家的赞赏.<br> 4.新增mapper2(Mybatis-Annotation模板)(感谢@baisi525和@CHKEGit的建议).|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.softdev.system.generator.util;
|
package com.softdev.system.generator.util;
|
||||||
|
|
||||||
|
import freemarker.cache.ClassTemplateLoader;
|
||||||
import freemarker.template.Configuration;
|
import freemarker.template.Configuration;
|
||||||
import freemarker.template.Template;
|
import freemarker.template.Template;
|
||||||
import freemarker.template.TemplateException;
|
import freemarker.template.TemplateException;
|
||||||
@ -8,10 +9,8 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,20 +39,13 @@ public class FreemarkerUtil {
|
|||||||
*/
|
*/
|
||||||
private static Configuration freemarkerConfig = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
|
private static Configuration freemarkerConfig = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
|
||||||
static{
|
static{
|
||||||
String templatePath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
|
|
||||||
int wei = templatePath.lastIndexOf("WEB-INF/classes/");
|
|
||||||
if (wei > -1) {
|
|
||||||
templatePath = templatePath.substring(0, wei);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
freemarkerConfig.setDirectoryForTemplateLoading(new File(templatePath, "templates/code-generator"));
|
//2020-06-21 zhengkai 修复path问题导致jar无法运行而本地项目可以运行的bug
|
||||||
freemarkerConfig.setNumberFormat("#");
|
freemarkerConfig.setClassForTemplateLoading(FreemarkerUtil.class, "/templates/code-generator");
|
||||||
freemarkerConfig.setClassicCompatible(true);
|
freemarkerConfig.setTemplateLoader(new ClassTemplateLoader(FreemarkerUtil.class, "/templates/code-generator"));
|
||||||
freemarkerConfig.setDefaultEncoding("UTF-8");
|
//freemarkerConfig.setDirectoryForTemplateLoading(new File(templatePath, "templates/code-generator"));
|
||||||
freemarkerConfig.setLocale(Locale.CHINA);
|
|
||||||
freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
|
freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,6 +40,8 @@ spring:
|
|||||||
expose-request-attributes: true
|
expose-request-attributes: true
|
||||||
expose-session-attributes: true
|
expose-session-attributes: true
|
||||||
expose-spring-macro-helpers: true
|
expose-spring-macro-helpers: true
|
||||||
#template-loader-path: classpath:/templates/
|
settings:
|
||||||
|
number_format: 0.##
|
||||||
|
#template_loader: /templates/
|
||||||
mvc:
|
mvc:
|
||||||
static-path-pattern: /static/**
|
static-path-pattern: /static/**
|
||||||
@ -128,6 +128,25 @@ public class ${classInfo.className}Controller {
|
|||||||
${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("${classInfo.className?uncap_first}_id",id));
|
${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("${classInfo.className?uncap_first}_id",id));
|
||||||
return new ModelAndView("cms/${classInfo.className?uncap_first}-edit","${classInfo.className?uncap_first}",${classInfo.className?uncap_first});
|
return new ModelAndView("cms/${classInfo.className?uncap_first}-edit","${classInfo.className?uncap_first}",${classInfo.className?uncap_first});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发布/暂停(如不需要请屏蔽)
|
||||||
|
*/
|
||||||
|
@PostMapping("/publish")
|
||||||
|
public Object publish(int id,Integer status){
|
||||||
|
${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("${classInfo.className?uncap_first}_id",id));
|
||||||
|
if(${classInfo.className?uncap_first}!=null){
|
||||||
|
${classInfo.className?uncap_first}.setUpdateTime(new Date());
|
||||||
|
${classInfo.className?uncap_first}.setStatus(status);
|
||||||
|
${classInfo.className?uncap_first}Mapper.updateById(${classInfo.className?uncap_first});
|
||||||
|
return ReturnT.SUCCESS((status==1)?"已发布":"已暂停");
|
||||||
|
}else if(status.equals(${classInfo.className?uncap_first}.getStatus())){
|
||||||
|
return ReturnT.SUCCESS("状态不正确");
|
||||||
|
}else{
|
||||||
|
return ReturnT.ERROR();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -183,13 +183,40 @@
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
layer.msg(responseData.msg, function () {
|
layer.msg(responseData.msg, function () {
|
||||||
//window.location = '/index.html';
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
layer.close(index);
|
layer.close(index);
|
||||||
});
|
});
|
||||||
|
}else if (obj.event === 'publish') {
|
||||||
|
layer.confirm('确定要发布吗?', function (index) {
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: "¥{request.contextPath}/${classInfo.className?uncap_first}/publish",
|
||||||
|
data:{"id":obj.data.${classInfo.className?uncap_first}Id,"status":"1"},
|
||||||
|
success: function (responseData) {
|
||||||
|
searchBtn.click();
|
||||||
|
layer.msg(responseData.msg, function () {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
layer.close(index);
|
||||||
|
});
|
||||||
|
}else if (obj.event === 'unpublish') {
|
||||||
|
layer.confirm('确定要停止吗?', function (index) {
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: "¥{request.contextPath}/${classInfo.className?uncap_first}/publish",
|
||||||
|
data:{"id":obj.data.${classInfo.className?uncap_first}Id,"status":"0"},
|
||||||
|
success: function (responseData) {
|
||||||
|
searchBtn.click();
|
||||||
|
layer.msg(responseData.msg, function () {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
layer.close(index);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user