为了controller上的减少硬编码,在springmvc.xml中配置属性文件的加载,给controller提供使用。
1.编写crm.properties
customer_from_type=002
customer_industry_Type=001
customer_level_Type=006
2.在springmvc.xml中配置crm.properties
<!-- 属性文件加载 -->
<context:property-placeholder location="classpath:crm.properties"/>
3.在controller中调用属性
注意使用@Value注入
@Value("${customer_from_type}")
private String customer_from_type;
@Value("${customer_industry_Type}")
private String customer_industry_Type;
@Value("${customer_level_Type}")
private String customer_level_Type;
4.在controller方法体中调用属性
@RequestMapping("list")
public String list(Model model) throws Exception {
//查询来源
List<BaseDict> fromType = baseDictService.getBaseDictByCode(customer_from_type);
//查询行业
List<BaseDict> industryType = baseDictService.getBaseDictByCode(customer_industry_Type);
//查询级别
List<BaseDict> levelType = baseDictService.getBaseDictByCode(customer_level_Type);
//设置数据模型返回
model.addAttribute("fromType", fromType);
model.addAttribute("industryType", industryType);
model.addAttribute("levelType", levelType);
return "customer";
}