本文共 1438 字,大约阅读时间需要 4 分钟。
org.springframework.boot spring-boot-configuration-processor true
name=zhangsanperson.name=zhangsanperson.age=18person.addr=beijing
package com.learn.controller;import org.springframework.boot.context.properties.ConfigurationProperties;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;@Controller@ConfigurationProperties(prefix = "person")public class Quick3Controller { private String name; private String addr; private Integer age; @RequestMapping("/quick3") @ResponseBody public String quick2(){ //获得配置文件的信息 return "name:"+name+",addr="+addr+",age="+age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAddr() { return addr; } public void setAddr(String addr) { this.addr = addr; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; }}
package com.learn;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class SpringbootQuick2Application { public static void main(String[] args) { SpringApplication.run(SpringbootQuick2Application.class, args); }}
转载地址:http://fwkzb.baihongyu.com/