文件抽取的应用

比如对应Controller 层里面的 某些属性如果写死 会造成维护麻烦

我们可以抽取出来:

 

 properties文件的抽取:

customer_from_type=002
customer_industry_type=001
customer_level_type=006

  

扫描这个配置文件:

  <context:property-placeholder location="classpath:crm.properties" />

 

注入应用: 

package com.toov5.crm.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.toov5.crm.pojo.BaseDict;
import com.toov5.crm.service.BaseDictService;

@Controller
@RequestMapping("customer")
public class CustomerController {
    @Autowired
    private BaseDictService baseDictService;
    
    @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;
    
    
    @RequestMapping("list")
    public String list(Model model) {

        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";
    }

}

 

 properties 文件 =====》 xml 扫描 ======》通过 @Value("xx")

 

posted @ 2019-01-14 19:57  toov5  阅读(266)  评论(0编辑  收藏  举报