Python 官方文档:入门教程 => 点击学习
目录一、工具类二、测试一、工具类 public class FreemarkerUtil { public static void execute(String f
public class FreemarkerUtil {
public static void execute(String ftlNameWithPath, Map<String, Object> data, String aimFileName) throws ioException, TemplateException {
Configuration cfg = new Configuration(Configuration.VERSION_2_3_25);//创建Freemarker配置实例
int i = ftlNameWithPath.lastIndexOf("/") == -1 ? ftlNameWithPath.lastIndexOf("\\") : ftlNameWithPath.lastIndexOf("/");
cfg.setDirectoryForTemplateLoading(new File(ftlNameWithPath.substring(0, i + 1)));
cfg.setDefaultEncoding("UTF-8");
Template t1 = cfg.getTemplate(ftlNameWithPath.substring(i + 1));//加载模板文件
Writer out = new FileWriter(new File(aimFileName));
t1.process(data, out);
out.flush();
out.close();
}
}
package com.resume.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.resume.domain.${className};
import java.util.List;
public interface ${className}Service extends IService<${className}> {
List<${className}> listAllUsable${className}();
boolean modify${className}Status(Integer id, Integer status);
boolean modify(${className} ${objName});
}
public class GenApplication {
private static String className = "Project";
private static String objName = "project";
private static String comment = "期日经验";
private static String basePath = "src/main/java/com/resume/";
public static void main(String[] args) throws IOException, TemplateException {
// 生成Service接口
genService(className, objName, comment);
}
private static void genService(String className, String objName, String comment) throws IOException, TemplateException {
String ftlNameWithPath = basePath + "utils/gen/ftl/service.ftl";
String aimFileName = basePath + "service/" + className + "Service.java";
Map<String, Object> map = new HashMap<>();
map.put("objName", objName);
map.put("className", className);
map.put("comment", comment);
FreemarkerUtil.execute(ftlNameWithPath, map, aimFileName);
}
}
到此这篇关于Java超级实用的Freemarker工具类的文章就介绍到这了,更多相关实用的Freemarker工具类内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: Java超级实用的Freemarker工具类
本文链接: https://lsjlt.com/news/139720.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0