注意第一个Helloworld项目:浏览发送/hello请求,响应hello,SpringBoot 2
原始SSM:MVC麻烦
1.创建Maven工程
2.引入依赖
<!--导入Springboot-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
</parent>
<dependencies>
<!--导入web场景启动器,因为要开发Web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
3.创建主程序
package com.cxy.boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* 主程序类:@SpringBootApplication---这是一个SpringBoot应用
*/
@SpringBootApplication
public class MainAppliaction {
public static void main(String[] args){
SpringApplication.run(MainAppliaction.class,args);
}
}
4.编写业务
package com.cxy.boot.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
//@ResponseBody
//@Controller
@RestController
public class HelloController {
@ResponseBody
@RequestMapping("/hello")//映射请求
public String handle01(){
return "Hello Spring boot2!";
}
}
5.测试;运行main方法
6.简化配置:application.properties
7.简化部署:打成jar包,直接执行
<!--为了创建一个可执行的jar,
我们需要添加spring-boot-maven-plugin致我们的pom.xml文件。-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
注意取消CMD的快速依赖