temp - json 형식으로 값 셋팅하기

2018. 1. 10. 23:40BASIC/jsp

* home.jsp


* controller

@RequestMapping(value = "/", method = RequestMethod.GET)
	public String home() {
		logger.info("■■■■■HOME■■■■■");
		return "home";
	}

	@RequestMapping(value = "/member_list")
	@ResponseBody
	public List getList() {
		MemberDto dto1 = new MemberDto(1, "김구라", "노량진");
		MemberDto dto2 = new MemberDto(2, "해골", "행신동");
		MemberDto dto3 = new MemberDto(3, "원숭이", "상도동");
		List list = new ArrayList<>();
		list.add(dto1);
		list.add(dto2);
		list.add(dto3);
		return list;
	}

	@RequestMapping(value = "/checkid")
	@ResponseBody
	public Map checkid(@RequestParam String inputId) {
		boolean isExist = false;
		if (inputId.equals("gura")) {
			isExist = true;
		}
		Map map = new HashMap<>();
		map.put("isExist", isExist);
		return map;
	}

	@RequestMapping(value = "/json01", produces = "application/json;charset=utf-8")
	@ResponseBody
	public String json01() {
		return "{\"num\":999}";
	}

	@RequestMapping(value = "/json02")
	@ResponseBody
	public Map json02() {
		Map map = new HashMap<>();
		map.put("num", 1);
		map.put("name", "김구라");
		map.put("isMan", true);
		return map;
	}

	@RequestMapping(value = "/json03")
	@ResponseBody
	public List json03() {
		List list = new ArrayList<>();
		list.add("김구라");
		list.add("해골");
		list.add("원숭이");
		return list;
	}

	@RequestMapping(value = "/json04")
	@ResponseBody
	public List> json04() {
		List> list = new ArrayList>();
		Map map1 = new HashMap<>();
		map1.put("num", 1);
		map1.put("name", "김구라");
		map1.put("isMan", true);
		Map map2 = new HashMap<>();
		map2.put("num", 2);
		map2.put("name", "해골");
		map2.put("isMan", false);
		list.add(map1);
		list.add(map2);
		return list;
	}

	@RequestMapping("/json05")
	@ResponseBody
	public FriendDto json05() {
		FriendDto dto = new FriendDto(1, "김구라", true);
		return dto;
	}