SpringBoot注解解释

1.@SpringBootApplication

启动项目注释

2.@RestController

@Controller处理http请求(必须配合模版使用)

@RestController = @Controller + @ResponseBody

3.@RequestMapping

@RequestMapping 支持多个url访问,下面的代码我访问/hello和/hi都进入welcome方法

@RequestMapping(value = {"/hello", "/hi"}, method = RequestMethod.GET)
	public String welcome(){
		return "hollo spring boot";
	}

@RequestMapping(value单个url访问

@RequestMapping(value = "/hello", method = RequestMethod.GET)
	public String welcome(){
		return "hollo spring boot";
	}

4.@Value("$配置文件的变量名")
    private 类型 变量名

5.@ConfigurationProperties

application.properties配置文件内容:

people.username=马少
people.sex=男
people.age=29
people.job=程序员

新建对象PeopleProperties

@Component  这个注解是为了让别的地方能注入

@Component
@ConfigurationProperties(prefix = "people")
public class PeopleProperties {
	
	private String  username;
	
	private String  age;
	
	private String  job;

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getAge() {
		return age;
	}

	public void setAge(String age) {
		this.age = age;
	}

	public String getJob() {
		return job;
	}

	public void setJob(String job) {
		this.job = job;
	}
}

猜你喜欢

转载自my.oschina.net/u/1858920/blog/1816249
今日推荐