package com.itheima.controller; import com.itheima.controller.pojo.User; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.websocket.server.PathParam; import java.lang.reflect.Array; import java.net.http.HttpRequest; import java.time.LocalDateTime; import java.util.Arrays; import java.util.List; @RestController public class SimpleController { // @RequestMapping("/simpleMethod") // public String simpleMethod(HttpServletRequest request){ // String name = request.getParameter("name"); // String ageStr = request.getParameter("age"); // int age = Integer.parseInt(ageStr); // System.out.println(name+":"+age); // return "ok"; // } @RequestMapping("/simpleMethod") public String simpleMethod(String name, @RequestParam(name = "age", required = false) Integer agestr) { System.out.println(name + ":" + agestr); return "ok"; } @RequestMapping("/simpleUser") public String simpleUser(User user) { System.out.println(user); return "ok"; } @RequestMapping("/jsonParam") public String jsonParam(@RequestBody User user) { System.out.println(user); return "ok"; } @RequestMapping("/arrayParam") public String arrayParam(String[] hobby) { System.out.println(Arrays.toString(hobby)); return "ok"; } @RequestMapping("/listParam") public String listParam( @RequestParam List<String> hobby) { System.out.println(hobby); return "ok"; } @RequestMapping("/dateParam") public String dateParam(@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime updatetime) { System.out.println(updatetime); return "ok"; } @RequestMapping("/pathParam/{id}/{name}") public String pathParam(@PathVariable Integer id,@PathVariable String name) { System.out.println(id); System.out.println(name); return "ok"; } }
首先在idea中创建一个Springboot项目,然后在src/main/java创建的包下,创建一个contorller,在里面书写内容。
写好之后,先启动Springboot项目,然后在Aipfox里面创建接口,发送请求。
?