美文网首页
SSM测试接口,报405错误

SSM测试接口,报405错误

作者: feng_wy | 来源:发表于2020-04-26 14:31 被阅读0次

    1.直接在网页里面测试post接口

    http://localhost:8080/ssm_war_exploded//account/login3
    

    2.页面报错如下

    HTTP Status 405 – 方法不允许
    
    Type Status Report
    消息 Request method 'GET' not supported
    描述 请求行中接收的方法由源服务器知道,但目标资源不支持
    
    Apache Tomcat/8.5.53
    

    3.代码如下

    package shop.jitou.ssm.controller;
    
    import io.swagger.annotations.Api;
    import io.swagger.annotations.ApiOperation;
    import io.swagger.annotations.ApiResponse;
    import io.swagger.annotations.ApiResponses;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.http.HttpMethod;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.MethodArgumentNotValidException;
    import org.springframework.web.bind.annotation.*;
    import shop.jitou.ssm.domain.Account;
    import shop.jitou.ssm.service.AccountService;
    
    import java.io.UnsupportedEncodingException;
    import java.util.List;
    
    @Api(value = "/account", tags = "USER模块")
    @Controller
    public class AccountController {
        
        @ResponseBody
        @PostMapping(value = "/account/login3", produces = "application/json;charset=utf-8")
        public Account login3() {
            Account account = new Account();
            account.setMoney(100.0);
            account.setName("王燿");
            account.setId(0);
            return account;  //在视图解析器中配置了前缀后缀
        }
    
    }
    

    4.解决如下
    postman里面这样(post方法)

    http://localhost:8080/ssm_war_exploded/account/login3?phone=15638659156
    

    相关文章

      网友评论

          本文标题:SSM测试接口,报405错误

          本文链接:https://www.haomeiwen.com/subject/azbdwhtx.html