Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.mycompany.geocoordinate.controller; import com.fasterxml.jackson.databind.ObjectMapper; import com.mycompany.geocoordinate.mappers.CoordinateMapper; import com.mycompany.geocoordinate.model.GeoObject; import com.mycompany.geocoordinate.model.GeoType; import java.io.IOException; import java.net.URI; import java.util.List; import javax.json.JsonException; import javax.ws.rs.core.Context; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseStatus; import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.Response; import org.springframework.http.ResponseEntity; /** * * @author andrey */ @Controller @RequestMapping("/") @Configuration public class PolygonController { @Autowired private CoordinateMapper coordinateMapper; @ResponseStatus(HttpStatus.CREATED) @PostMapping(value = "/polygon", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public @ResponseBody ResponseEntity<List<Integer>> polygon(@RequestBody GeoObject geoObject) throws IOException, JsonException { boolean check = coordinateMapper.isThereGeoObjectFromPolygontype(GeoType.POLYGON) != null & coordinateMapper.selectCoordinateForLineorCircle(geoObject.getCoordinate()) != null; coordinateMapper.insertCoordinateForLineorCircle(GeoType.POLYGON, geoObject.getCoordinate()); List<Integer> responseType = coordinateMapper.selectIdGeo(geoObject.getCoordinate()); return ResponseEntity.created(URI.create("/polygon/id")).body(responseType); } }