pom.xml
>@RestController
// Rest API를 제공하는 컨트롤러 의미
@RequestMapping(value="/member/rest")
//클래스 레벨로 기본 경로 /member 로 지정 http://localhost:8080/web/member/rest
public class MemberRestController {
private static final Logger logger =
LoggerFactory.getLogger(MemberRestController.class);
// MemberService 객체를 주입
@Autowired(required=true)
private MemberService memberService;
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public ResponseEntity<StudentVO> readMember(@PathVariable String id) throws Exception {
StudentVO student = memberService.readMember(id);
logger.info(" /member/rest/{id} REST-API GET method called. then method executed.");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(new MediaType("application", "json", Charset.forName("UTF-8"))); headers.set("My-Header", "MyHeaderValue");
return new ResponseEntity<StudentVO>(student, headers, HttpStatus.OK);
}
2.회원정보 등록
http://localhost:8080/web/member/rest 요청
@RequestMapping(method = RequestMethod.POST)
public String createMemberPost(@RequestBody StudentVO vo) throws Exception {
memberService.addMember(vo);
logger.info(vo.toString());
logger.info(" /member/rest/{id} REST-API POST method called. then method executed."); return "OK";
}
}