转发和重定向

package com.example.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/user")
public class UserController {
    @GetMapping("/info")
    public String info() {
        // 转发
        return "app";
    }

    @GetMapping("/post-test")
    public String info2(String name) {
        // 转发
        System.out.println("name = " + name);
        return "forward:/index.jsp";
    }

    @GetMapping("/info3")
    public String info3() {
        // 转发
        return "redirect:/index.jsp";
    }
}

最后更新于

这有帮助吗?