(1),json依赖
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.7.11.RELEASE</version>
</dependency>
(2),响应json格式数据
@Controller
@RequestMapping(value = "/studentConter")
public class StudentController {
// 路径映射
@RequestMapping(value = "/studentQuery", method = RequestMethod.GET)
@ResponseBody // 返回客户端json数据格式
public String studentQuery(HttpServletRequest request) {
List<StudentVo> studentVoList = initList();
String jsonList = JSONArray.toJSONString(studentVoList);
return jsonList;
}
/****
* @date: 2022/11/2 20:31
* @desc: 初始化集合值
* */
private List<StudentVo> initList( ) {
StudentVo studentVo1 = new StudentVo();
studentVo1.setsName("zhangsan");
studentVo1.setsAge(18);
StudentVo studentVo2 = new StudentVo();
studentVo2.setsName("lisi");
studentVo2.setsAge(19);
ArrayList<StudentVo> studentVoArrayList = new ArrayList<StudentVo>();
studentVoArrayList.add(studentVo1);
studentVoArrayList.add(studentVo2);
return studentVoArrayList;
}
}
(3),请求测试
http://localhost:8085/bl_mave_wf_war_exploded/studentConter/studentQuery?stuName=zhangsan
(4),响应截图