Java tutorial
/* * Copyright 2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package cn.cuizuoli.gotour.controller; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import cn.cuizuoli.gotour.enumeration.ProductType; import cn.cuizuoli.gotour.model.Attractions; import cn.cuizuoli.gotour.model.Info; import cn.cuizuoli.gotour.model.Internal; import cn.cuizuoli.gotour.model.Local; import cn.cuizuoli.gotour.model.Outdoor; import cn.cuizuoli.gotour.model.Training; import cn.cuizuoli.gotour.service.CategoryService; import cn.cuizuoli.gotour.service.ProductService; import cn.cuizuoli.gotour.service.WebCategoryService; /** * WebCategoryController * @author cuizuoli */ @Controller @RequestMapping("/w/c") public class WebCategoryController { @Resource private ProductService productService; @Resource private CategoryService categoryService; @Resource private WebCategoryService webCategoryService; @SuppressWarnings({ "unchecked", "rawtypes" }) @RequestMapping("{productCode}") public ModelAndView index(@PathVariable String productCode) { List<Info> productList = productService.getProductList(); Info product = productService.getProduct(productCode); List<Info> categoryList = categoryService.getAllCategoryList(productCode); Map categoryMap = null; if (StringUtils.equals(productCode, ProductType.LOCAL.getCode())) { categoryMap = new HashMap<Info, List<Local>>(); for (Info category : categoryList) { List<Local> localList = webCategoryService.getTopLocalList(category.getInfoCode()); if (localList.size() > 0) { categoryMap.put(category, localList); } } } if (StringUtils.equals(productCode, ProductType.INTERNAL.getCode())) { categoryMap = new HashMap<Info, List<Internal>>(); for (Info category : categoryList) { List<Internal> internalList = webCategoryService.getTopInternalList(category.getInfoCode()); if (internalList.size() > 0) { categoryMap.put(category, internalList); } } } if (StringUtils.equals(productCode, ProductType.OUTDOOR.getCode())) { categoryMap = new HashMap<Info, List<Outdoor>>(); for (Info category : categoryList) { List<Outdoor> outdoorList = webCategoryService.getTopOutdoorList(category.getInfoCode()); if (outdoorList.size() > 0) { categoryMap.put(category, outdoorList); } } } if (StringUtils.equals(productCode, ProductType.ATTRACTIONS.getCode())) { categoryMap = new HashMap<Info, List<Attractions>>(); for (Info category : categoryList) { List<Attractions> attractionsList = webCategoryService .getTopAttractionsList(category.getInfoCode()); if (attractionsList.size() > 0) { categoryMap.put(category, attractionsList); } } } if (StringUtils.equals(productCode, ProductType.EXPANSION_TRAINING.getCode())) { categoryMap = new HashMap<Info, List<Training>>(); for (Info category : categoryList) { List<Training> trainingList = webCategoryService.getTopTrainingList(category.getInfoCode()); if (trainingList.size() > 0) { categoryMap.put(category, trainingList); } } } if (StringUtils.equals(productCode, ProductType.ABOUT_US.getCode())) { return new ModelAndView("web/about").addObject("product", product).addObject("productCode", productCode) .addObject("productList", productList); } return new ModelAndView("web/category").addObject("product", product).addObject("productCode", productCode) .addObject("productList", productList).addObject("categoryMap", categoryMap); } @RequestMapping("{productCode}/{page}") public ModelAndView about(@PathVariable String productCode, @PathVariable String page) { List<Info> productList = productService.getProductList(); Info product = productService.getProduct(productCode); return new ModelAndView("web/about" + page).addObject("product", product) .addObject("productCode", productCode).addObject("productList", productList); } }