通过 @Value("${com.springboot.name}")
注解的方式:
application.properties 文件的内容如下:
com.springboot.name=qujianlei
com.springboot.title=studyhadoop
com.springboot.desc=${com.springboot.name} work hard ${com.springboot.title}
com.springboot.random.string=${random.value}
com.springboot.random.int=${random.int}
com.springboot.random.long=${random.long}
比方说我们现在要在 Controller 中获取 com.springboot.name 的值,只需像下面这样既可:
package com.qjl.bootstart.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qjl.bootstart.yml.User;
import com.qjl.bootstart.yml.YmlUtil;
/**
* 类名称:SpringMVC的控制器
* 全限定性类名: com.qjl.bootstart.controller.BootController
* @author 曲健磊
* @date 2018年8月4日上午10:38:23
* @version V1