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.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import cn.cuizuoli.gotour.enumeration.ProductType; import cn.cuizuoli.gotour.model.DataResult; import cn.cuizuoli.gotour.model.Info; import cn.cuizuoli.gotour.model.SearchCondition; import cn.cuizuoli.gotour.service.AttractionsService; import cn.cuizuoli.gotour.service.CategoryService; import cn.cuizuoli.gotour.service.InternalService; import cn.cuizuoli.gotour.service.LocalService; import cn.cuizuoli.gotour.service.OutdoorService; import cn.cuizuoli.gotour.service.ProductService; import cn.cuizuoli.gotour.service.TrainingService; /** * WebListController * @author cuizuoli */ @Controller @RequestMapping("/w/l") public class WebListController extends SimpleController { @Resource private ProductService productService; @Resource private CategoryService categoryService; @Resource private LocalService localService; @Resource private InternalService internalService; @Resource private OutdoorService outdoorService; @Resource private AttractionsService attractionsService; @Resource private TrainingService trainingService; @RequestMapping("{productCode}/{categoryCode}") public ModelAndView index(@PathVariable String productCode, @PathVariable String categoryCode) { Info product = productService.getProduct(productCode); Info category = categoryService.getCategory(categoryCode); return new ModelAndView("web/list").addObject("product", product).addObject("category", category) .addObject("productCode", productCode).addObject("categoryCode", categoryCode); } @RequestMapping("list") @ResponseBody public DataResult list(@RequestBody SearchCondition searchCondition) { searchCondition.setPageSize(100); DataResult dataResult = new DataResult(); if (StringUtils.equals(searchCondition.getProductCode(), ProductType.LOCAL.getCode())) { dataResult = localService.getLocalList(searchCondition); } if (StringUtils.equals(searchCondition.getProductCode(), ProductType.INTERNAL.getCode())) { dataResult = internalService.getInternalList(searchCondition); } if (StringUtils.equals(searchCondition.getProductCode(), ProductType.OUTDOOR.getCode())) { dataResult = outdoorService.getOutdoorList(searchCondition); } if (StringUtils.equals(searchCondition.getProductCode(), ProductType.ATTRACTIONS.getCode())) { dataResult = attractionsService.getAttractionsList(searchCondition); } if (StringUtils.equals(searchCondition.getProductCode(), ProductType.EXPANSION_TRAINING.getCode())) { dataResult = trainingService.getTrainingList(searchCondition); } return dataResult; } }