zoukankan      html  css  js  c++  java
  • spring使用@Value标签读取.properties文件的中文乱码问题的解决

    spring使用@Value标签读取.properties文件的中文乱码问题的解决

    spring 中文乱码 @Value *.properties


    在spring中我们常常使用.properties对一些属性进行一个提前配置, spring 在读取*.properties文件时,默认使用的是asci码, 这时 我们需要对其编码进行转换. 当然 方法有很多种 ,我说以下几种


    1.spring.xml,.properties使"utf8"在配置spring.xml文件时,声明所需的∗.properties文件时直接使用"utf−8"编码

    <context:property-placeholder location="classpath:conf/*.properties" file-encoding="UTF-8"/>
    • 1

    2.使:如果在所需类上注入可使用以下方式来声明编码格式:

    @Component
    @PropertySource(value = "classpath:conf/copyWriteUI.properties",encoding = "utf-8")
    @Getter
    public class CopyWriteUI {
        @Value("${a}")
        private String a;
        @Value("${b}")
        private String b;
        }

    3.,unicode不设置编码格式,编写文件时将中文转化为unicode编码
    4. IntelliJIDEA!!!idea,!
    idea 会自动帮我们进行如上的第三步的

     

    --------------------- 本文来自 J3oker 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/J3oker/article/details/53839210?utm_source=copy 

  • 相关阅读:
    UVa 482
    UVa 10360
    UVa 10812
    UVa 10420
    UVa 573
    UVa 357
    UVa 147
    UVa 674
    郑厂长系列故事——逃离迷宫 HDU4524
    威威猫系列故事——过生日 HDU 4523
  • 原文地址:https://www.cnblogs.com/coder-wzr/p/9719315.html
Copyright © 2011-2022 走看看