springboot提示不支持post请求

img


虽然不支持post请求,但是还是支持get请求的

img


package com.company.controller;

import com.company.controller.utils.ResultObject;
import com.company.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController //这个注释的作用就是@Controller+@ResponseBody
@RequestMapping("/userLogin")
public class UserController {
//http://localhost/userLogin/id   查询指定用户信息  Get 查询

    @Autowired
    private UserService userService;

//    得到全部的用户
    @GetMapping
    public ResultObject getAll(){
        ResultObject r = new ResultObject(true,userService.list());
        return r;
    }

//  验证用户登录用户名或密码是否正确
    @GetMapping("/{username}/{password}")
    public ResultObject verifyLogin(@PathVariable String username,@PathVariable String password){

        System.out.println(username);
        System.out.println(password);

        ResultObject r = new ResultObject(true,userService.userLogin(username,password));

      return r;
    }

    @PostMapping("/{username}/{password}")
    public ResultObject login(@PathVariable("username") String username,@PathVariable("password")  String password){
        System.out.println(username);
        System.out.println(password);

        ResultObject r = new ResultObject(true,userService.userLogin(username,password));

        return r;

    }
//@PostMapping("{username}/{password}")
//public ResultObject verifyLogin(@PathVariable String username,@PathVariable String password){
//
//    System.out.println(username);
//    System.out.println(password);
//
//    ResultObject r = new ResultObject(true,userService.userLogin(username,password));
//
//    return r;
//}


}

img

img

一个接口地址想要同时支持get和post直接用下面写法


@RequestMapping (value =  "/{username}/{password}" , method = {RequestMethod. POST ,RequestMethod. GET })
 public ResultObject verifyLogin(@PathVariable String username,@PathVariable String password){
 
        System.out.println(username);
        System.out.println(password);
 
        ResultObject r = new ResultObject(true,userService.userLogin(username,password));
 
      return r;
    }