初识spring Boot 超精简MVC实现

file-new -Spring Stater project  web依赖

@RestController
@SpringBootApplication
public class HelloSpringBootApplication {
	@RequestMapping("/")
		public String hello(){
			return "hello SpringBoot";
	}
	public static void main(String[] args) {
		SpringApplication.run(HelloSpringBootApplication.class, args);
	}
}
localhost:8080/ 

10行实现SpringMVC 不需要配置任何XML文件。

file-new-spring stater project  web Thymeleaf依赖

@Controller
@SpringBootApplication
public class HelloSpringBootApplication {
	@RequestMapping("/")
		public String hello(){
			return "index";
	}
	public static void main(String[] args) {
		SpringApplication.run(HelloSpringBootApplication.class, args);
	}
}
定向到index.html
index.html 放到resource/templates里




Insert title here


HEllo SpringBoot

localhost:8080/ 

上面2个程序主要的不同是 @RestController和@Controller

@RestController 是@Controller和ResponseBody的结合体 说明return的是response




PS:

SpringBootApplication  开启自动配置    

 SpringApplication.run(Main.class,args)   Spring boot 入口 

application.properties 配置

tomcat:

server.port=***

Profile 不同环境对不同配置提供支持

不同的配置文件  application-{profile}.properties

在application.properties里配置

spring.profiles.active= profile

你可能感兴趣的:(spring,Boot)