学年设计1

2021-07-16  本文已影响0人  恰我年少时

SpringBoot:

Maven

构建Maven项目:

1.配置SpringBoot核心启动器spring-boot-stater-parent

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

2.添加starter模块

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>2.5.1</version>
</dependency>

环境搭建

通过main方法启动SpringBoot项目,不需要配置Tomcat

测试

编写测试代码

在src/main/java目录下,创建com.test包,并将在该报中创建TestController类

package com.test;
import……
@RestController
public class TestController{
@RequestMapping("/hello")
public String hello(){
  return "Hello , SpringBoot!"
  }

创建应用程序的APP类(启动类)

在com.test包中创建chapter3_1类:

package com.test;
import……
@SpringBootApplication
public class chapter3_1{
@RequestMapping("/hello")
public static void main(String[] args){
  chapter3_1.run(chapter3_1.class,args);
  }
}

启动之后,默认访问地址:http://localhost:8080/
通过http://localhost:8080/hello访问项目,hello和测试类Controller中@RequestMapping(“/hello”)对应

除了Maven手工搭建,还可以使用http://start.spring.io和Spring Tool Suite搭建

上一篇 下一篇

猜你喜欢

热点阅读