com.banyou.backend.web.front.HomepageController.java Source code

Java tutorial

Introduction

Here is the source code for com.banyou.backend.web.front.HomepageController.java

Source

/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.banyou.backend.web.front;

import java.util.List;

import com.banyou.backend.entity.AdContent;
import com.banyou.backend.service.ad.AdService;
import com.banyou.backend.service.product.DestService;

import org.apache.commons.lang3.ArrayUtils;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

import org.slf4j.Logger;

/**
 * ??Controller, RestfulUrls:
 * 
 * List page : GET /product/ Create page : GET /product/create Create action
 * :POST /product/create Update page : GET /product/update/{id} Update action
 * :POST /product/update Delete action : GET /product/delete/{id}
 * 
 * @author calvin
 */
@Controller
@RequestMapping(value = "/front")
public class HomepageController {
    private Logger log = LoggerFactory.getLogger(getClass());

    public static final String DEST_CODE = "_USER_DEST";
    @Autowired
    private DestService destService;
    @Autowired
    private AdService adService;

    @RequestMapping(value = { "/", "index", "" }, method = RequestMethod.GET)
    public String index(HttpSession session, Model model) {
        String lunboCode = "INDEX_LUNBO";
        Long[] ids = (Long[]) session.getAttribute(DEST_CODE);

        if (!ArrayUtils.isEmpty(ids)) {
            model.addAttribute("dests", destService.findDests(ids));
        }
        List<AdContent> lunboAD = adService.getAdPositionByCode(lunboCode).getContent();
        int lunboMax = 1;
        if (!lunboAD.isEmpty()) {
            model.addAttribute("lunboAd", lunboAD.subList(0, Math.min(lunboAD.size(), lunboMax)));
        }

        destService.findDests(ids);
        return "front/index";
    }

}