package cn.bunny.mvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/use")
@Controller
public class UseController {

    // 带参数访问
    @RequestMapping(value = "hello", method = RequestMethod.GET, params = {"name"})
    public String hello() {
        return "hello";
    }

    @GetMapping("jumpPage")
    public String jumpPage() {
        return "jumpPage";
    }

    @GetMapping("index")
    public String quick() {
        return "user";
    }

    // 跳转的页面
    @GetMapping("toJump")
    public String toJump() {
        return "redirect:jumpPage";
    }

    @GetMapping("getJson")
    @ResponseBody
    public List<String> getJson() {
        ArrayList<String> list = new ArrayList<>();
        list.add("a");
        list.add("b");
        list.add("c");

        return list;
    }

    // 将视图和模型拆开
    @GetMapping("test3")
    public String test3(Model model) {
        model.addAttribute("test3", "测试3");
        return "test/test3";
    }
}
