Java tutorial
/* * Project: greenline-hrs-out-service * * File Created at 2015-09-10 * Copyright 2012 Greenline.com Corporation Limited. * All rights reserved. * * This software is the confidential and proprietary information of * Greenline Company. ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into * with Greenline.com. */ package com.albert.swagger; import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; import io.swagger.annotations.Contact; @Api(value = "contacts-api", description = "CURD?", position = 5) @Controller @RequestMapping("/contacts") public class ContactController { /*@Autowired ContactService contactService;*/ @ResponseBody @RequestMapping(value = "/1.0/contact/get.do/{id}", method = RequestMethod.GET) public Contact get(@PathVariable Long id) { return null; } @ApiOperation(value = "", notes = "", response = Contact.class, position = 2) @RequestMapping(value = "/1.0/contact/add.do", method = RequestMethod.POST) public void add(@RequestBody Contact contact, HttpServletResponse response) { //contactService.create(contact); String location = ServletUriComponentsBuilder.fromCurrentRequest().pathSegment("{id}").buildAndExpand("") .toUriString(); response.setHeader("Location", location); } @RequestMapping(value = "/1.0/contact/update.do/{id}", method = RequestMethod.POST) @ApiResponses(value = { @ApiResponse(code = 200, message = "?", response = Contact.class), @ApiResponse(code = 404, message = "??"), @ApiResponse(code = 500, message = "") }) public void update(@ApiParam(name = "id", value = "?", required = true) @PathVariable Integer id, @RequestBody Contact contact) { // contact.setId(id);; // contactService.update(contact); } }