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 

  • 相关阅读:
    从Object对象中读取属性的值
    CentOS7安装Mysql
    CentOS初使用命令总结
    linux安装git、node、pm2
    将 ELASTICSEARCH 写入速度优化到极限
    Elasticsearch
    elasticsearch5.0.1集群索引分片丢失的处理
    ELASTICSEARCH健康red的解决
    使用linux远程登录另一台linux
    fiddler构造表单上传文件的请求
  • 原文地址:https://www.cnblogs.com/coder-wzr/p/9719315.html
Copyright © 2011-2022 走看看