jeesite.properties属性文件为utf-8格式时的加载修改

版权声明:本文为博主原创文章,但是你也可以随意转载。 https://blog.csdn.net/smartcore/article/details/79352709

在idea内修改jeesite(https://github.com/thinkgem/jeesite)时,首要的一个地方就是修改jeesite.properties。

通常的,我们会在idea内将properties文件的编码设置为UTF-8,因此,你在修改jeesite.properties后,就会出现一些乱码的问题:

比如,jeesite登录页面的网站标题是在jeesite.properties文件内的productName属性进行设置的,但是修改运行后此标题将会变成乱码。

本文的解决方法是:在jeesite项目内PropertiesLoader类的加载属性方法loadProperties加载属性文件时,为输入流指定编码,如下:

修改前:

// com.thinkgem.jeesite.common.utils.PropertiesLoader类

 

/**
    * 载入多个文件, 文件路径使用Spring Resource格式.
    */
  
private Properties loadProperties(String... resourcesPaths) {
      // 省略……
            Resource resource = resourceLoader.getResource(location);
            is = resource.getInputStream();
            props.load(is);
         } catch (IOException ex) {
      // 省略……

      return props;
   }

 

 

修改后(见红色部分):

// com.thinkgem.jeesite.common.utils.PropertiesLoader类

 

/**
    * 载入多个文件, 文件路径使用Spring Resource格式.
    */
  
private Properties loadProperties(String... resourcesPaths) {
      // 省略……
            Resource resource = resourceLoader.getResource(location);
            is = resource.getInputStream();
            // props.load(is);

            props.load(new InputStreamReader(is, "UTF-8"));
         } catch (IOException ex) {
      // 省略……

      return props;
   }

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章