1 创建SpringBoot项目

 条件:JDK1.8以及以上版本+maven

 创建一个maven的java项目,由于我们使用spring-boot-starter-web的启动器,它内置有Tomcat和SpringMVC所以我们创建一个java程序就可以不需要创建一个web程序。

SpringBoot之helloWord

在pom.xml中添加SpringBoot的依赖

<!-- 添加springboot的父级 -->
  <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
  </parent>
  <!-- 添加不同类型的启动依赖 -->
  <dependencies>
  <dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
  </dependency>

  </dependencies>

编写一个web程序

package xin.caoyong.controller;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 
 * Description:编写一个SpringBoot的HelloWord
 * @author CaoYong
 * @time 2018年7月9日 下午10:15:18
 */
@RestController
@pringBootApplication
public class IndexController {

/**

* Description:
* @author CaoYong
* @time 2018年7月9日 下午10:17:38
* @return
* @return String
*/
@RequestMapping("/index")
public String index() {
return "SprinBoot的第一个项目helloword";
}

public static void main(String[] args) {
SpringApplication.run(IndexController.class, args);
}

}

运行:

SpringBoot之helloWord

SpringBoot之helloWord

第一个红色框便是启动成功,第二个红色框表示Tomcat启动成功端口号是8080

解释各个注解的含义

@RestController:表示@Controller(表示Controller层并且添加到Spring容器中)[email protected](该类中所有方法返回json格式)的集合

@EnableAutoConfiguration :表示自动配置会自动扫描pom.xml文件

SpringApplication.run(IndexController.class, args):启动项目



相关文章:

  • 2021-09-24
  • 2022-02-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-05
猜你喜欢
  • 2021-08-24
  • 2021-03-31
  • 2021-04-20
  • 2021-10-12
  • 2021-07-16
  • 2021-09-29
  • 2022-12-23
相关资源
相似解决方案