com.weib.spittr.web.SpittleController.java Source code

Java tutorial

Introduction

Here is the source code for com.weib.spittr.web.SpittleController.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.weib.spittr.web;

import com.weib.spittr.repostory.SpittleRepository;
import com.weib.spittr.repostory.data.Spittle;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import static org.springframework.web.bind.annotation.RequestMethod.*;
import org.springframework.web.bind.annotation.RequestParam;

/**
 *
 * @author zhangjingwei
 */
@Controller
public class SpittleController {

    public SpittleRepository spittleRepository;

    @Autowired
    SpittleController(SpittleRepository spittleRepository) { //Repository
        this.spittleRepository = spittleRepository;
    }

    @RequestMapping(value = "/spittles", method = GET)
    public String spittles(Model model) {
        //modelKEY-ValueMap?KEY?List<Spittle> : spittleList
        model.addAttribute("spittleList11", this.spittleRepository.findSpittles(Long.MAX_VALUE, 20)); //??
        return "spittles";
    }

    //??
    //??: spittle_list
    //???: spittleList
    @RequestMapping(value = "/spittle_list", method = GET)
    public List<Spittle> spittles() {
        return this.spittleRepository.findSpittles(Long.MAX_VALUE, 20); //??
    }

    @RequestMapping(value = "/spittle_page", method = GET)
    public String spittles(@RequestParam(value = "max", defaultValue = "1000") long max,
            @RequestParam(value = "count", defaultValue = "10") int count, Model model) {
        model.addAttribute("spittleList", this.spittleRepository.findSpittles(max, count));
        model.addAttribute("max", max);
        model.addAttribute("count", count);
        return "spittle_page"; //??
    }

    @RequestMapping(value = "/spittle/{spittleId}", method = GET)
    public String spittle_show(@PathVariable long spittleId, Model model) {
        model.addAttribute("spittle", this.spittleRepository.findOne(spittleId));
        model.addAttribute(spittleId);
        return "spittle_show";
    }
}