• 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

    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.输出

  • 相关阅读:
    NSUserDefaults存储自定义类
    beginBackgroundTaskWithExpirationHandle
    instancetype
    #define const extern
    singleton
    报错:说改变了系统文件。解决方法
    不合法语句 self.contentView.frame.origin.x = x;
    google应用商店的解决
    笔记
    读流testDemo
  • 原文地址:https://www.cnblogs.com/pu20065226/p/10733787.html
Copyright © 2020-2023  润新知