spring boot报Unsupported Media Type Content type '*/*;charset=UTF-8' not supported

1.请求设置Content-Type:application/json即可

ajax一般默认:Content-Type: application/x-www-form-urlencoded;charset=utf-8

spring boot报Unsupported Media Type  Content type '*/*;charset=UTF-8' not supported

2.服务端:

 controller

package com.example.demo;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class helloController {
    @RequestMapping(value="/hello")
    public String say(){
        String str="my spring boot web project hihihi";
        System.out.println(str);
        return str;
    }

    @RequestMapping(value="/test")
    public String testObj(@RequestBody User user){

        System.out.println(user.toString());
        return user.toString();
    }
}

实体user

package com.example.demo;

public class User {
    private String userName;
    private String pwd;

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public String toString(){
        return userName+""+pwd;
    }
}

3.输出

spring boot报Unsupported Media Type  Content type '*/*;charset=UTF-8' not supported

 

上一篇:CreateDatabase is not supported by the provider


下一篇:聊聊TCP的三次握手和四次挥手, 以及一些相关的面试问题