傻瓜式学JAVA---springboot入门
功能:浏览器发送hello请求,服务器接收并处理,响应hello spring字符串
一、创建Maven工程

创建项目:springboot_hello


选择自佛那个导入jar包

选择设置Maven配置

修改Maven配置

二、导入Spring boot相关依赖
使用Maven创建项目,需要导入依赖:
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.1.RELEASE</version></parent><!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web --><dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency></dependency>

三、编写主程序
1.创建主程序

package com.learn;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;//SpringBootApplication标注主程序类@SpringBootApplicationpublic class HelloSpringMainApplication { public static void main(String[] args) { //Spring 应用启动 SpringApplication.run(HelloSpringMainApplication.class,args); }}
四、编写相关Controller、Service
package com.learn.com.learn.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HelloController {
@ResponseBody
@RequestMapping("/hello")
public String hello(){
return "hello springboot";
}
}
五、启动springboot项目

项目启动端口为 8080
网页访问路径:http://localhost:8080/hello

六、应用打包
加入依赖:将应用打包成一个可执行的jar包
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>

七、运行程序包
运行JAR包:
命令:Java -jar springboot_hello-1.0-SNAPSHOT.jar

八、使用IDEA自动创建Springboot项目





编写Controller
package com.learn.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;@Controllerpublic class hello { @ResponseBody @RequestMapping("/hd") public String Hello(){ return "hello Spriongboot"; }}
启动运行:

欢迎关注公众号---后台服务器开发,更多精彩等你来看~