背景:
如上图,所属行业从数据库字典表中获取
//所属行业
List<BaseDict> industryType = baseDictService.queryBaseDictByDictTypeCode("001");
这边的"001"存在硬编码,能否把字典表中dic_type_code类别分类的值集写在配置文件properties中,然后Controller层读取配置文件的值。
properties文件的如下: crm.properties
customer_from_type=002
customer_industry_type=001
customer_level_type=006
加载 crm.properties,Controller需要的配置文件信息必须添加到springmvc的配置文件中
在springmvc.xml中,添加如下信息
<!-- 属性文件的加载 -->
<context:property-placeholder location="classpath:crm.properties"/>
在Controller类中,使用@Value注解来获取properties文件的值,注意要用${}包裹属性的名称,例如@Value("${customer_from_type}")
@Controller
@RequestMapping("customer")
public class CustomerControll {