重定向的坑,GET方法不支持异常

package com.yuanming.admin.controller;

import com.yuanming.admin.pojo.DemoUser;
import com.yuanming.admin.service.DemoUserService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@ApiModel("用户信息处理")
@RequestMapping("/web")
public class DemoUserController {


    @Autowired
    DemoUserService demoUserService;


    @DeleteMapping("/demo_users")
    @ApiOperation("获取所有的用户")
    @RequestMapping(value = "/demo_users",method = RequestMethod.GET )
    public String getAllDemoUser(Map<String,Object> map){
        List<DemoUser> allDemoUser = demoUserService.getAllDemoUser();
        map.put("demoUsers", allDemoUser);
        return "demoUserList";
    }

    @RequestMapping(value = "/demo_user/demo_users",method = RequestMethod.GET )
    public String getAllDemoUsers(Map<String,Object> map){
        List<DemoUser> allDemoUser = demoUserService.getAllDemoUser();
        map.put("demoUsers", allDemoUser);
        return "demoUserList";
    }

    @ApiOperation("删除指定的用户,重定向到index页面!")
    @RequestMapping(value = "/demo_user/{id}",method = RequestMethod.DELETE)
    public String del(@PathVariable("id") Integer id){
        demoUserService.delById(id);
        System.out.println(id);
        return "redirect:/web/demo_users";
    }

    @RequestMapping(value = "/demo_user",method = RequestMethod.PUT)
    public String modifyUser(DemoUser demoUser){
        demoUserService.modifyUser(demoUser);
        return "redirect:/web/demo_users";
    }

}

> 还是基础不扎实惹的祸

1.重定向不带 “/” 的基础路径是:当前需要重定向的controller所映射的路径

>如果controller处理 http://localhost:8080/darui/web/demo_user,返回 redirec : demo_users

        实际上:http://localhost:8080/darui/web/demo_user/demo_users

        如果需求是处理:http://localhost:8080/darui/web/demo_users

        此时------------>浏览器报405异常,显示GET方法不支持异常

2.重定向带 “/” 的基础路径是:项目的根目录 http://localhost:8080/darui

>如果controller处理 http://localhost:8080/darui/web/demo_user,返回 redirec : /web/demo_users

实际上:http://localhost:8080/darui/web/demo_users

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值