编写一个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、效果