在代码中使用

@Controller
public class IndexController {
    
    @Value("${CONTENT_LUNBO_ID}")
    private Long CONTENT_LUNBO_ID;
    
    @Autowired
    private ContentService contentService;

    @RequestMapping("/index")
    public String showIndex(Model model) {
        //查询内容列表
        List<TbContent> ad1List = contentService.getContentListByCid(CONTENT_LUNBO_ID);
        // 把结果传递给页面
        model.addAttribute("ad1List", ad1List);
        return "index";
    }
}
View Code

.properties

CONTENT_LUNBO_ID=89
View Code

在springMVC中加载:

<!-- 加载配置文件 -->
    <context:property-placeholder location="classpath:conf/resource.properties" />

posted on 2018-04-07 11:50  lshan  阅读(135)  评论(0编辑  收藏  举报