From 85d1de94fdbe70c0af0a638bd86c46fc35e4886a Mon Sep 17 00:00:00 2001 From: JeffLi1993 Date: Thu, 23 Feb 2017 14:35:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=A1=88=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springboot/controller/CityController.java | 13 +++++++++---- .../src/main/resources/{city => web}/city.ftl | 0 .../src/main/resources/web/cityList.ftl | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) rename springboot-freemarker/src/main/resources/{city => web}/city.ftl (100%) create mode 100644 springboot-freemarker/src/main/resources/web/cityList.ftl 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