在快速入门课程的基础上做了一些修改,作为父工程
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<!--核心模块,包括自动配置支持、日志和YAML-->
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<!--测试模块,包括JUnit、Hamcrest、Mockito-->
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
引入Web模块,方便后面测试
<dependency>
<groupId>org.springframework.boot</groupId>
<!--web模块-->
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
创建controller类com.zjq.demo.controller.TestController,内容如下
@RestController
public class TestController {
@RequestMapping(value = "/hello")
public String hello(){
return "HelloWorld";
}
}
启动主程序,访问 http://localhost:8080/hello ,可以看到页面输出 HelloWorld
1.使用idea,点击File,new >>project,老版idea可以直接用 SPRING INITIALIZR 新建项目,新版的idea需要添加
Spring Assistant插件,添加好后重启idea,点击File,new >>project,选择Spring Assistant,选择SDK版本,使用default https://start.spring.io/ 构建项目
4.可以看到pom.xml文件中自动引入了这些依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
引入Web模块,方便后面测
创建controller类com.zjq.demo.controller.TestController,内容如下
@RestController
public class TestController {
@RequestMapping(value = "/hello")
public String hello(){
return "HelloWorldByIdea";
}
}
启动主程序,访问 http://localhost:8080/hello ,可以看到页面输出 HelloWorldByIdea