mirror of
https://github.com/JeffLi1993/springboot-learning-example.git
synced 2026-03-14 22:23:54 +08:00
Spring Boot 属性配置文件
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package org.spring.springboot;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* Spring Boot 应用启动类
|
||||
*
|
||||
* Created by bysocket on 16/4/26.
|
||||
*/
|
||||
// Spring Boot 应用的标识
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 程序启动入口
|
||||
// 启动嵌入式的 Tomcat 并初始化 Spring 环境及其各 Spring 组件
|
||||
SpringApplication.run(Application.class,args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package org.spring.springboot.property;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 家乡属性
|
||||
*
|
||||
* Created by bysocket on 17/04/2017.
|
||||
*/
|
||||
@Component
|
||||
public class HomeProperties {
|
||||
|
||||
/**
|
||||
* 省份
|
||||
*/
|
||||
@Value("${home.province}")
|
||||
private String province;
|
||||
|
||||
/**
|
||||
* 城市
|
||||
*/
|
||||
@Value("${home.city}")
|
||||
private String city;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@Value("${home.desc}")
|
||||
private String desc;
|
||||
|
||||
public String getProvince() {
|
||||
return province;
|
||||
}
|
||||
|
||||
public void setProvince(String province) {
|
||||
this.province = province;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.spring.springboot.web;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* Spring Boot HelloWorld 案例
|
||||
*
|
||||
* Created by bysocket on 16/4/26.
|
||||
*/
|
||||
@RestController
|
||||
public class HelloWorldController {
|
||||
|
||||
@RequestMapping("/")
|
||||
public String sayHello() {
|
||||
return "Hello,World!";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user