SpringBoot中JSONObject 和 JSONArray的请求解析

it2026-02-20  5

package springboot.controller; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import springboot.service.IService; @RestController public class HelloController { @Autowired private IService iService; @PostMapping("hello") public String hello(@RequestBody JSONArray jsonArray){ System.out.println(jsonArray); return "jsonArray "+jsonArray; } @PostMapping("hello1") public String hello1(@RequestBody JSONObject jsonObejct){ System.out.println(jsonObejct); return "jsonObejct="+jsonObejct; } @GetMapping("test") public String test(){ iService.testAsync(); return "调用接口返回"; } }

最新回复(0)