完善案例

This commit is contained in:
JeffLi1993
2017-02-23 14:35:33 +08:00
committed by liqiangqiang
parent d1f6559143
commit 85d1de94fd
3 changed files with 24 additions and 4 deletions

View File

@@ -3,10 +3,8 @@ package org.spring.springboot.controller;
import org.spring.springboot.domain.City;
import org.spring.springboot.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@@ -22,9 +20,16 @@ public class CityController {
@Autowired
private CityService cityService;
@RequestMapping(value = "/api/city")
public String findOneCity(Model model, @RequestParam(value="id", required=false, defaultValue="1") Long id) {
@RequestMapping(value = "/api/city/{id}", method = RequestMethod.GET)
public String findOneCity(Model model, @PathVariable("id") Long id) {
model.addAttribute("city", cityService.findCityById(id));
return "city";
}
@RequestMapping(value = "/api/city", method = RequestMethod.GET)
public String findAllCity(Model model) {
List<City> cityList = cityService.findAllCity();
model.addAttribute("cityList",cityList);
return "cityList";
}
}

View File

@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<body>
<#list cityList as city>
City: ${city.cityName}! <br>
Q:Why I like? <br>
A:${city.description}!
</#list>
</body>
</html>