Spring接受參數忽略參數名大小寫敏感


一 概述

  最近做個防火牆控制器,移動要求各個廠商接受參數名大小寫不敏感,為了測試對接方面.

二 配置

  1 pom文件引入(springboot版本2.4.0)    

    <dependency>
                <groupId>org.codehaus.jackson</groupId>
                <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.13</version>
    </dependency>

   2 yml文件配置(忽略參數名大小寫不敏感spring.jackson.mapper.accept-case-insensitive-properties=true)  

spring:
  jackson:
    mapper:
      accept-case-insensitive-properties: true

  3實體類    

@Data
@AllArgsConstructor
@NoArgsConstructor
public class People {
    private String Name;      
    private int age;
}

  4 postman測試()    

{
    "name":"tom",
    "AGE" :25

}

    Controller層:

  

        @PostMapping
        @ResponseStatus(HttpStatus.CREATED)
        public String  createSecurityPolicy(@RequestBody People people) {
            
            System.out.println("name=="+people.getName());
            System.out.println("age=="+people.getAge());
            return    null;
             
        }

 

 測試結果:

    

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM