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 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.repository.AttractionsRepository; import cn.cuizuoli.gotour.repository.InternalRepository; import cn.cuizuoli.gotour.repository.ItineraryRepository; import cn.cuizuoli.gotour.repository.LocalRepository; import cn.cuizuoli.gotour.repository.OutdoorRepository; import cn.cuizuoli.gotour.repository.TrainingRepository; import cn.cuizuoli.gotour.service.CategoryService; import cn.cuizuoli.gotour.service.ProductService; /** * WebDetailController * @author cuizuoli */ @Controller @RequestMapping("/w/d") public class WebDetailController extends SimpleController { @Resource private ProductService productService; @Resource private CategoryService categoryService; @Resource private LocalRepository localRepository; @Resource private InternalRepository internalRepository; @Resource private ItineraryRepository itineraryRepository; @Resource private OutdoorRepository outdoorRepository; @Resource private AttractionsRepository attractionsRepository; @Resource private TrainingRepository trainingRepository; @RequestMapping("{productCode}/{categoryCode}/{id}") public ModelAndView index(@PathVariable String productCode, @PathVariable String categoryCode, @PathVariable int id) { Info product = productService.getProduct(productCode); Info category = categoryService.getCategory(categoryCode); if (StringUtils.equals(productCode, ProductType.LOCAL.getCode())) { Local detail = localRepository.selectOne(id); return new ModelAndView("web/detail").addObject("product", product).addObject("category", category) .addObject("productCode", productCode).addObject("categoryCode", categoryCode) .addObject("detail", detail).addObject("id", id); } if (StringUtils.equals(productCode, ProductType.INTERNAL.getCode())) { Internal detail = internalRepository.selectOne(id); detail.setItineraryList(itineraryRepository.selectList(id)); return new ModelAndView("web/detail").addObject("product", product).addObject("category", category) .addObject("productCode", productCode).addObject("categoryCode", categoryCode) .addObject("detail", detail).addObject("id", id); } if (StringUtils.equals(productCode, ProductType.OUTDOOR.getCode())) { Outdoor detail = outdoorRepository.selectOne(id); return new ModelAndView("web/detail").addObject("product", product).addObject("category", category) .addObject("productCode", productCode).addObject("categoryCode", categoryCode) .addObject("detail", detail).addObject("id", id); } if (StringUtils.equals(productCode, ProductType.ATTRACTIONS.getCode())) { Attractions detail = attractionsRepository.selectOne(id); return new ModelAndView("web/detail").addObject("product", product).addObject("category", category) .addObject("productCode", productCode).addObject("categoryCode", categoryCode) .addObject("detail", detail).addObject("id", id); } if (StringUtils.equals(productCode, ProductType.EXPANSION_TRAINING.getCode())) { Training detail = trainingRepository.selectOne(id); return new ModelAndView("web/detail").addObject("product", product).addObject("category", category) .addObject("productCode", productCode).addObject("categoryCode", categoryCode) .addObject("detail", detail).addObject("id", id); } return new ModelAndView("web/detail").addObject("product", product).addObject("category", category) .addObject("productCode", productCode).addObject("categoryCode", categoryCode).addObject("id", id); } }