- 一、创建父工程
- 1.1 创建maven工程
- 1.2 修改pom.xml文件
- 二、HelloWorld
- 2.1 创建子工程(_001.helloworld)
- 2.2 子工程结构
- 2.3 TestController
- 2.4 启动类 SpringMvcApplication
- 2.5 运行 SpringMvcApplication
创建一个普通的maven工程boot-springmvc-test,把工程里面的其他内容都删掉,只保留.idea和pom.xml。如下图:
1.2 修改pom.xml文件二、HelloWorld 2.1 创建子工程(_001.helloworld) 2.2 子工程结构 2.3 TestController4.0.0 pom _001.helloworld org.springframework.boot spring-boot-starter-parent 2.5.6 prv.dongruan springmvc 1.0-SNAPSHOT 11 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test
package prv.dongruan.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/test")
public class TestController {
@GetMapping
public String sayHello() {
return "hello world";
}
}
2.4 启动类 SpringMvcApplication
特别说明:启动类不能和TestController在同一层目录,必须在它的父目录里面
package prv.dongruan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringMvcApplication {
public static void main(String[] args) {
SpringApplication.run(SpringMvcApplication.class);
}
}
2.5 运行 SpringMvcApplication
运行成功后。即可通过 http://localhost:8080/test 访问 TestController



