package com.api.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.MatrixVariable;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class RequestController {

    @GetMapping("/goto")
    public String goTo(HttpServletRequest request) {
        request.setAttribute("zhang","xiaoyu");
        return "forward:/success";
    }
    @GetMapping("/success")
    @ResponseBody
    public String success(@RequestAttribute("zhang") String zhang, HttpServletRequest request) {
        return "我是";
    }
    // 矩阵变量的测试
    // /matrix/mm;low=34;name=zhang,xiao,yu
    // tip注意 springboot默认是关闭矩阵变量功能
    @GetMapping("/matrix/{path}")
    @ResponseBody
    public String matrix(@MatrixVariable("low") String low,
                         @MatrixVariable("name")List<String> names) {
        System.out.println(low);
        System.out.println(names);
        return low;
    }
}
