diff --git a/springboot-freemarker/src/main/java/org/spring/springboot/controller/CityController.java b/springboot-freemarker/src/main/java/org/spring/springboot/controller/CityController.java index 577aad6..0b6f430 100644 --- a/springboot-freemarker/src/main/java/org/spring/springboot/controller/CityController.java +++ b/springboot-freemarker/src/main/java/org/spring/springboot/controller/CityController.java @@ -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 cityList = cityService.findAllCity(); + model.addAttribute("cityList",cityList); + return "cityList"; + } } diff --git a/springboot-freemarker/src/main/resources/city/city.ftl b/springboot-freemarker/src/main/resources/web/city.ftl similarity index 100% rename from springboot-freemarker/src/main/resources/city/city.ftl rename to springboot-freemarker/src/main/resources/web/city.ftl diff --git a/springboot-freemarker/src/main/resources/web/cityList.ftl b/springboot-freemarker/src/main/resources/web/cityList.ftl new file mode 100644 index 0000000..08cde70 --- /dev/null +++ b/springboot-freemarker/src/main/resources/web/cityList.ftl @@ -0,0 +1,15 @@ + + + + + +<#list cityList as city> + +City: ${city.cityName}!
+Q:Why I like?
+A:${city.description}! + + + + + \ No newline at end of file