묻고 답해요
131만명의 커뮤니티!! 함께 토론해봐요.
인프런 TOP Writers
-
미해결스프링 MVC 1편 - 백엔드 웹 개발 핵심 기술
JSON응답에서 406메세지 에러때문에 잠오지않습니다
안녕하십니까 혼자 실습하는 중에 궁금한 점이 생겨 질문드립니다.강의에서 @ResponseBody는 객체를 받아서 HTTP 메시지 컨버터를 통해 JSON 응답을 하는 것으로 배웠습니다.postman 에서 api test 을 한 스샷입니다 그리고 디스패쳐 url-mapping을 *.h로 했습니다그리고 spring 소스와 설정내용이 아래와같습니다추가적으로 디스패쳐 url-pattern을 /* 으로 변경해서 api test을 하면url 확장자를 다르게 써서 하면 json 응답데이타를 받습니다 확장자 .h 뿐만아니라 .hh로 끝나는 url도 위와같이 406에러가납니다 왜 그런지 도무지 감이 안옵니다답변 부탁드립니다
-
미해결모든 개발자를 위한 HTTP 웹 기본 지식
안녕하세요 이 코드는 잘못된건가요?
RestController 가 있습니다 @PostMapping("/request") public ResponseEntity<> save(someDto dto) throws UnsupportedEncodingException, Exception { if(isAdmin()){ return new ResponseEntity<>( 어드민이 아닙니다,HttpStatus.BAD_REQUEST); } try { AService.save(dto.toEntity()); // 주문 생성 BService.createEstimate(dto.toEntity()); // 견적 생성 } catch (Exception e) { return new ResponseEntity<>(저장이 안되었다는 메세지,HttpStatus.BAD_REQUEST); } return new ResponseEntity<>(저장이 되었다는 메세지,HttpStatus.OK); } AService입니다 @Transactional(rollbackFor = {Exception.class}) public void save(Entity entity) throws Exception{ entityRepo.save(entity); } BService입니다 @Transactional(rollbackFor = {Exception.class}) public void createEstimate(Entity entity) throws Exception { entityRepo.save(entity); } 위와 같이 rest controller에도 throw exception과 동시에 저장,견적 을 생성하는 서비스를 각각 호출합니다.(서로 다른 클래스) 그런데 그 서비스에도 다 throw exception을 하고 있습니다. 어노테이션으로 Transactional(rollbackFor exception)을 하고 있고요. 위와 같이 코드를 작성하는 방법은 틀린것인가요?