#ssm#模板#打包成jar无法加载配置文件

解决方法

  @SneakyThrows
    @Override
    public void print(String fromPath, String fromTemplate, Map<String, Object> model) {
        // File ss = fileUtils.getResourceFile(from);
        Configuration cfg = new Configuration();
        // FileTemplateLoader ftl = new FileTemplateLoader(ss);
        cfg.setClassForTemplateLoading(getClass(), "/"+fromPath);


        Template t = cfg.getTemplate(fromTemplate);

        t.process(model,new PrintWriter(System.out));

    }

    @SneakyThrows
    @Override
    public void build(String from, String fromFile, Consumer<Template> callback) {
        // File ss = fileUtils.getResourceFile(from);
        Configuration cfg = new Configuration();
        // FileTemplateLoader ftl = new FileTemplateLoader(ss);
        cfg.setClassForTemplateLoading(getClass(), "/"+from);

        Template t = cfg.getTemplate(fromFile);
        callback.accept(t);
    }
@PostConstruct
    public void init() {
        log.info("加载 autoCode 的配置文件");
        this.properties = new Properties();
        // File f = fileUtils.getResourceFile("autoCode/TypeConfig.properties");

        try (InputStream is = new ClassPathResource("autoCode/TypeConfig.properties").getInputStream();) {
            Properties local = new Properties();
            local.load(is);
            properties.putAll(local);
        } catch (Exception e) {
            log.error("加载 autoCode配置时候出现异常了 {}", e.getMessage());
        }

        String[] prefixList = this.properties.getProperty("tableRemovePrefixes", "").split(",");
        if (prefixList.length > 0) {
            prefix.addAll(Arrays.asList(prefixList));
        }

    }

使用 流的方式读取 .properteis 的配置文件
参考文章如下:

freemaker加载资源文件

SSM(Spring+SpringMVC+MyBatis)框架集由Spring、MyBatis两个开源框架整合而(SpringMVC是Spring中的部分内容)。常作为数据源较简单的web项目的框架。 Spring   Spring就像是整个项目中装配bean的大工厂,在配置文件中可以指定使用特定的参数去调用实体类的构造方法来实例化对象。也可以称之为项目中的粘合剂。   Spring的核心思想是IoC(控制反转),即不再需要程序员去显式地`new`一个对象,而是让Spring框架帮你来完这一切。   SpringMVC   SpringMVC在项目中拦截用户请求,它的核心Servlet即DispatcherServlet承担中介或是前台这样的职责,将用户请求通过HandlerMapping去匹配Controller,Controller就是具体对应请求所执行的操作。SpringMVC相当于SSH框架中struts。   mybatis   mybatis是对jdbc的封装,它让数据库底层操作变的透明。mybatis的操作都是围绕一个sqlSessionFactory实例展开的。mybatis通过配置文件关联到各实体类的Mapper文件,Mapper文件中配置了每个类对数据库所需进行的sql语句映射。在每次与数据库交互时,通过sqlSessionFactory拿到一个sqlSession,再执行sql命令。 页面发送请求给控制器,控制器调用业务层处理逻辑,逻辑层向持久层发送请求,持久层与数据库交互,后将结果返回给业务层,业务层将处理逻辑发送给控制器,控制器再调用视图展现数据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值