• 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 

  • 相关阅读:
    JavaWeb--JDBC
    JavaWeb--过滤器、监听器
    Javaweb-MVC三层架构
    JavaWeb--JSP
    JavaWeb--Cookie、Session
    JavaWeb--Servlet
    实用记录文档
    分库分表Sharding-JDBC + MyBatis-Plus动态表名
    如何不靠运气变得富有 (九) —— 互联网极大地丰富了职业发展的可能性
    如何不靠运气变得富有 (八) —— 给社会提供它不知道如何获得的东西
  • 原文地址:https://www.cnblogs.com/coder-wzr/p/9719315.html
Copyright © 2020-2023  润新知