2021年6月9日

编写一个http接口

1、1、在主程序的同级目录下,新建一个controller包,一定要在同级目录下,否则识别不到

 

2、代码

 1 package com.example.app01.demo.api;
 2 
 3 import org.springframework.stereotype.Controller;
 4 import org.springframework.ui.Model;
 5 import org.springframework.web.bind.annotation.GetMapping;
 6 import org.springframework.web.bind.annotation.RequestMapping;
 7 import org.springframework.web.bind.annotation.RequestParam;
 8 import org.springframework.web.bind.annotation.RestController;
 9 
10 @RestController
11 public class HelloController {
12     @RequestMapping("/")
13     public String index() {
14         return "Greetings from Spring Boot!";
15     }
16     @RequestMapping("/hello")
17     public String hello(){
18         return "hello world.";
19     }
20     @GetMapping("/greeting")
21     public String greeting( ) {
22 
23         return "greeting";
24     }
25 }

3、运行

 

4、效果

 

 

 







 

 

posted @ 2021-06-09 12:48 中年码农蜀黍 阅读(392) 评论(0) 推荐(0)

摘要: 1、File->New Project。 http://start.springboot.io 2、下一步。 3、选择依赖。 4、生成项目。 5、运行。 6、设置Tomcat端口 src\main\resources\application.properties server.port=9001 阅读全文

posted @ 2021-06-09 09:08 中年码农蜀黍 阅读(86) 评论(0) 推荐(0)


随笔 - 2, 文章 - 0, 评论 - 0, 阅读 - 514

Copyright © 2025 中年码农蜀黍
Powered by .NET 9.0 on Kubernetes

点击右上角即可分享
微信分享提示