DB insert시 unique 컬럼에 걸렸을때 DuplicateKeyException 이걸 던져준다

이걸 받아서 중복검사 해줄수 있다


/* 회원가입  > 회원저장 */

@RequestMapping(value = "/join/memberinsert", method = RequestMethod.POST)

@ResponseBody

public Map<String,Object> Memberinsert(HttpServletRequest request, HttpServletResponse response,@RequestBody MemberVO member) throws Exception {

/* Map<String, Object> map = new HashMap<String, Object>();

map.put("member", member);

*/

Map<String, Object> map = new HashMap<String, Object>();

try{

memberService.InsertMember(member);

} catch(Exception e){

if (e instanceof DuplicateKeyException) {

map.put("msg", "fail");

return map;

}

}

map.put("idx", member.getIdx());

map.put("authority", "ROLE_USER");

memberService.InsertMemberAuthority(map);

return map;

}


instanceof 이걸로 DuplicateKeyException 요거 받아와서 jsp로 던져줘서 처리해줌!


원래 컨트롤러에서 검사하면 안된다는데;; 조빱이라 그냥 여기서함


회원가입 ID중복검사 말고도 unique데이터를 검사해야할때 사용하면 좋을거같다

'IT' 카테고리의 다른 글

CentOS 6.7 iso  (0) 2017.07.11
Spring 회원가입 ID중복 검사 버튼  (1) 2017.03.15
jsp에서 controller로 데이터 ajax로 보내기  (0) 2017.03.08

+ Recent posts