SpringMVC框架中在controller层获取自定义配置文件的属性值

第一步:写自定义的properties文件

SpringMVC框架中在controller层获取自定义配置文件的属性值_第1张图片

第二步:在springMvc配置文件spring-servlet文件中配置文件属性(必须是springMvc配置文件


    
    classpath:config/law-url.properties
    
    

注:

  1. 配置单个文件是
  2. 配置多个文件是
    
        
           text/html;charset=UTF-8
           application/json;charset=UTF-8
        
    

     

第三步:在controller层需要从配置文件中获取的属性上加注解

@Value("${url}")
private String url;

需要导入的包是

import org.springframework.beans.factory.annotation.Value;

 

你可能感兴趣的:(spring)