Cute Happy Ghost
본문 바로가기
728x90
SMALL

JAVA116

Restful API 개발 (3) dataType별(json,xml) 출력하기, controller에서 xml json변환하기 먼저 dependency추가하고 기본 format을 xml로 해놓기 com.fasterxml.jackson.dataformat jackson-dataformat-xml ${jackson.version} 1. 분기점이 되는 mtd - 기본 : json type 만약 parameter의 dataType이 xml이라면 contentType을 xml로 변경해주기 - location 을 반환 @RequestMapping(value="/api/{name}/{id}/list") public String selectList(HttpServletRequest request, RedirectAttributes redirectAttributes ,@PathVariable("name") String name,@PathVari.. 2022. 3. 28.
Restful API 개발 (2) 정보 조회 ApiController.java @RequestMapping(value="/api/{name}/{id}/list", produces = {ApiConst.APPLICATION_JSON_VALUE}) @ResponseBody public Map selectList(@PathVariable("name") String name,@PathVariable("id") String id) throws Exception { HashMap finalresultMap = new LinkedHashMap(); HashMap header = new LinkedHashMap(); //상태코드 HashMap resultMap = new LinkedHashMap(); //데이터 String resultCode = "00"; St.. 2022. 3. 25.
Restful API 개발 (1) 데이터 저장 api개발 및 api테스트 사이트 url로 데이터를 전송하면 저장이 되는 api를 개발해야함 view는 없어도 됨 @RestController = @Controller + @ResponseBody RestController를 써도 되지만 나는 다른 기능때문에 일단은 분리하여 개발 구조는 contoller,service,serviceImpl,Dao,Vo,mapper파일이고 상수만 설정해놓은 파일도 하나 생성했다 Apicontroller.java @Controller @SuppressWarnings({"all"}) public class ApiController extends BaseController { @Resource(name="ApiService") protected ApiService apiService; @RequestMappin.. 2022. 3. 25.
Map에 넣은 순서대로 나오게 하는 방법 (HashMap, LinkedHashMap) HashMap resultMap = new HashMap(); resultMap.put("header",header); resultMap.put("data",list); 이렇게 하니까 원하는대로 header , data가 뜨는게 아니라 data부터 먼저 출력이 되었다... Map은 약간 랜덤이라서 내가 넣은대로 정렬이 안된다 내가 원하는건 오름차순, 내림차순이 아니라 그냥 넣은대로 빼고싶기때문에 LinkedHashMap만 쓰면 되는 문제임 HashMap resultMap = new LinkedHashMap(); resultMap.put("header",header); resultMap.put("data",list); HashMap을 LinkedHashMap으로만 바꾸면내가 넣은대로 출력이 잘 된다 2022. 3. 25.
728x90
LIST