【实例简介】
【实例截图】
【核心代码】
package com.spb.SpringBootDemo.rest;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
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.RestController;
import com.spb.SpringBootDemo.service.ICityService;
import com.spb.SpringBootDemo.vo.City;
@RestController
public class CityContorller {
@Autowired
private ICityService cityService;
@RequestMapping(value = "/api/city/{id}", method = RequestMethod.GET)
public City findOneCity(@PathVariable("id") Long id) {
return cityService.findCityById(id);
}
@RequestMapping(value = "/api/city", method = RequestMethod.GET)
public List findAllCity() {
return cityService.findAllCity();
}
@RequestMapping(value = "/api/city", method = RequestMethod.POST)
public void createCity(@RequestBody City city) {
cityService.saveCity(city);
}
@RequestMapping(value = "/api/city", method = RequestMethod.PUT)
public void modifyCity(@RequestBody City city) {
cityService.updateCity(city);
}
@RequestMapping(value = "/api/city/{id}", method = RequestMethod.DELETE)
public void modifyCity(@PathVariable("id") Long id) {
cityService.deleteCity(id);
}
}