Why is the beginning of SpringMvc injection parameters not case sensitive?

Without further ado, go directly to the code

package com.mcgx;

public class Data {

    private String sign;

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }
    
}
package com.mcgx;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class,args);
    }

    @RequestMapping("test")
    public String test(Data data){
        System.out.println(data.getSign());
        return "OK";
    }

}

We receive the attributes passed through the Data entity class in the test interface. Let's take a look at our parameter test. It can be passed into sign or Sign.

Passed into SIgn, not allowed

It's a bit magical, why?

We know that when Spring injects parameters into objects, it is injected through the set method, and the parameters are obtained through get.

Smart classmates should guess this sentence when they see it. When you pass parameters above, whether it is sign or sign ,

The injection is done through the setSign method, so capitalization is possible here ,

But when the parameter you pass is SIgn, I am embarrassed that there is no setSIgn method, so it cannot be injected, and the question and answer ends.

Published 38 original articles · won 17 · 9024 visits

Guess you like

Origin blog.csdn.net/cainiao1412/article/details/98218914