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

JAVA/Java74

java, mybatis resulttype=hashmap, map형태로 데이터 받기 @Controller @SuppressWarnings({"all"}) public class DevController extends BaseController { @Resource(name="DevService") protected DevService devService; @RequestMapping(value="/dev/downloadExcel.do") public void downloadExcel(HttpServletRequest request, HttpServletResponse response,@RequestParam Map paramMap) throws IOException { List list = devService.selectDevData(paramMap); ..... } controller.. 2022. 5. 19.
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.
controller에서 url로 동적 매핑하기 @PathVariable 테이블 n개를 조회하고싶은데 sql 및 controller구조가 똑같을 때 많이 쓰면 비효율적이니까 한번에 쓰기 위한 ! @RequestMapping("/api/List/{id}") @ResponseBody public Map selectList(@PathVariable("id") String id) throws Exception { ... HashMap resultMap = new HashMap(); //데이터 List list = apiService.selectList(id); resultMap.put("data",list); return resultMap; } requestMapping에 동적으로 받을 애를 { }안에 써주고 ex) {id} @PathVariable("id") String id로 받.. 2022. 3. 25.
enum의 name()과 tostring()의 차이점 The main difference between name() and toString() is that name() is a final method, so it cannot be overridden. The toString() method returns the same value that name() does by default, but toString() can be overridden by subclasses of Enum. Therefore, if you need the name of the field itself, use name(). If you need a string representation of the value of the field, use toString(). => 쉽게 말해 tos.. 2022. 1. 10.
session time변경 httpSession.setMaxInactiveInterval(3600); 초단위라서 1800이면 30분 3600이면 1시간 2021. 12. 2.
@SuppressWarnings("rawtypes")는 뭘까 @SuppressWarnings("rawtypes") 와 같은 어노테이션을 사용하는 이유는? 자바에서 노란색으로 Warnings이 나타나는 경우 어노테이션을 이용하여 문제를 해결할 수 있다. @SuppressWarnings - 컴파일 경고를 무시함 @SuppressWarnings("rawtypes")=> 하나만 적용할 경우 @SuppressWarnings({"rawtypes", "unchecked"})=> 두개 이상 적용할 경우 all : 모든 경고 cast : 캐스트 연산자 관련 경고 dep-ann : 사용하지 말아야 할 주석 관련 경고 deprecation : 사용하지 말아야 할 메서드 관련 경고 fallthrough : switch문에서 break 누락 관련 경고 finally : 반환하지 않는 f.. 2021. 6. 17.
20201123 _스프링 톰캣 맛보기 new project - web - Dynamic Web Project 이름 설정하고 finish (runtime에서 경로설정까지 같이 해줄 수도 있다 tomcat경로로지정하기) JSP파일 생성해주고 UTF-8로 바꿔줌 Run On Server tomcat검색- 9.0 browse에서 내가 tomcat깔았던 경로 설정해주고 finish누르면 이렇게 뜨고 밑에도 뭐 localhost 잘 뜬듯..? = 1) { result *= n--; } return result; } %> ._. 결과: 2020. 11. 23.
728x90
LIST