Spring Boot

Spring官方网站的位置

https://spring.io/

 

Spring Boot 初始项目的位置

http://start.spring.io/

 

创建Spring Boot 工程

 

创建好的工程

 

运行程序

 1 package com.mannycat.springbootlesson1;
 2 
 3 import org.springframework.boot.SpringApplication;
 4 import org.springframework.boot.autoconfigure.SpringBootApplication;
 5 
 6 @SpringBootApplication
 7 public class SpringBootLesson1Application {
 8 
 9     public static void main(String[] args) {
10         SpringApplication.run(SpringBootLesson1Application.class, args);
11     }
12 }

 

控制台会输出很多重要的信息

 

访问 http://localhost:8080/

 

修改代码

 1 package com.mannycat.springbootlesson1;
 2 
 3 import org.springframework.boot.SpringApplication;
 4 import org.springframework.boot.autoconfigure.SpringBootApplication;
 5 import org.springframework.stereotype.Controller;
 6 import org.springframework.web.bind.annotation.RequestMapping;
 7 import org.springframework.web.bind.annotation.ResponseBody;
 8 
 9 @Controller
10 @SpringBootApplication
11 public class SpringBootLesson1Application {
12 
13     public static void main(String[] args) {
14         SpringApplication.run(SpringBootLesson1Application.class, args);
15     }
16     
17     @RequestMapping("/")
18     @ResponseBody
19     String home() {
20         return "Hello World!";
21     }
22 }

 

重新启动,看控制台的输出"/"对应了hom()方法

 

重新访问http://localhost:8080

 

继续添加rest风格请求

 1 package com.mannycat.springbootlesson1;
 2 
 3 import org.springframework.boot.SpringApplication;
 4 import org.springframework.boot.autoconfigure.SpringBootApplication;
 5 import org.springframework.stereotype.Controller;
 6 import org.springframework.web.bind.annotation.RequestMapping;
 7 import org.springframework.web.bind.annotation.ResponseBody;
 8 
 9 import java.util.HashMap;
10 import java.util.Map;
11 
12 @Controller
13 @SpringBootApplication
14 public class SpringBootLesson1Application {
15 
16     public static void main(String[] args) {
17         SpringApplication.run(SpringBootLesson1Application.class, args);
18     }
19 
20     @RequestMapping("/")
21     @ResponseBody
22     String home() {
23         return "Hello World!";
24     }
25 
26     @RequestMapping("/rest")
27     @ResponseBody
28     public Map<String, Object> rest() {
29         Map<String, Object> data = new HashMap<String, Object>();
30 
31         data.put("1", "A");
32         data.put("2", 2);
33         
34         return data;
35     }
36 }

 

 从控制台查看是否配置成功

 

访问http://localhost:8080/rest

 

修改application.properties文件,修改端口

 

查看控制台是否修改成功

 

 访问http://localhost:7001/

 

在POM里添加依赖

 

application.properties配置文件加上

 

控制台同时启动8080和8081

 

 8081会启动管理运维

http://localhost:8081/actuator

 

转载于:https://www.cnblogs.com/mannycat/p/9336759.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值