1.快熟搭建一个MVC项目的基本步骤:
1.1 引入基本依赖:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
1.2 启动项目的主函数和注解:(其中args如果没有参数可以省略)
@SpringBootApplication
public class BootApplication {
public static void main(String[] args) {
SpringApplication.run(BootApplication.class,args);
}
}
运行代码:成功进入,但是没有界面,界面404;
1.3 开始写一个简单界面:(创建如图所示的类)
@Controller
public class HelloController {
@GetMapping("hello")
@ResponseBody
public String hello(){
return "hello,spring boot!";
}
}
成功访问: