1. 程式人生 > 其它 >Springboot返回json物件

Springboot返回json物件

 1 package com.example.demo.vue_project_login.controller;
 2 
 3 import net.sf.json.JSON;
 4 import net.sf.json.JSONArray;
 5 import net.sf.json.JSONObject;
 6 import org.springframework.stereotype.Controller;
 7 import org.springframework.web.bind.annotation.RequestBody;
 8 import org.springframework.web.bind.annotation.RequestMapping;
9 import org.springframework.web.bind.annotation.ResponseBody; 10 import org.springframework.web.bind.annotation.RestController; 11 12 import javax.servlet.http.HttpServletResponse; 13 import java.util.LinkedHashMap; 14 import java.util.Map; 15 16 /** 17 * @author liuwenlong 18 * @create 2022-05-09 20:02:35
19 */ 20 @RestController 21 @SuppressWarnings("all") 22 public class ApiController { 23 24 @RequestMapping("receivingData1/masterDate") 25 public JSONObject getUser(@RequestBody String body, HttpServletResponse response){ 26 Map map = new LinkedHashMap<>(); 27 map.put("sign
","0"); 28 map.put("message","success"); 29 30 response.setContentType("application/json"); 31 JSONObject json = JSONObject.fromObject(map); 32 return json; 33 } 34 }