Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

解决本地代码生成器在生成文件之后乱码问题 #16

Open
lzyznl opened this issue Jan 7, 2024 · 0 comments
Open

解决本地代码生成器在生成文件之后乱码问题 #16

lzyznl opened this issue Jan 7, 2024 · 0 comments

Comments

@lzyznl
Copy link

lzyznl commented Jan 7, 2024

在文件写入时设置编码为UTF-8即可

public static void dynamicGenerator(String inputPath,String outputPath,String templateName,String GeneratorFileName,Object Model) throws IOException, TemplateException {
        Configuration cfg = new Configuration(Configuration.VERSION_2_3_31);
        cfg.setDirectoryForTemplateLoading(new File(inputPath));
        cfg.setDefaultEncoding("UTF-8");
        //获取到对应的模板
        Template template = cfg.getTemplate(templateName);

        //指定模板引擎生成的文件路径
        FileOutputStream fileOutputStream = new FileOutputStream(outputPath+File.separator+GeneratorFileName);
        Writer output = new OutputStreamWriter(fileOutputStream,StandardCharsets.UTF_8);
        template.process(Model,output);
        output.close();
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant