SpringMVC-lesson08-json-3-2023-03-24
阿里巴巴开发的JSON
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.60</version>
</dependency>
@RequestMapping( "/j4")
//@ResponseBody //它就不会走视图解析器,它会直接返回一个字符串 或用RestController替代@Controller
public String json4() throws JsonProcessingException {
List<User> userList =new ArrayList<User>();
User user1 = new User("飞剑5",11,"男");
User user2 = new User("飞剑6",22,"男");
User user3 = new User("飞剑7",33,"男");
User user4 = new User("飞剑8",44,"男");
userList.add(user1);
userList.add(user2);
userList.add(user3);
userList.add(user4);
String string = JSON.toJSONString(userList);
return string;