79720870

Date: 2025-07-31 06:41:52
Score: 1
Natty:
Report link

I just found a related SO question, and one of the simpler "hack" solutions is to add a setter.

    @GetMapping("/modeltest")
    public void testModel(@ModelAttribute Test test) {
        log.info("{}", test);
    }

    @Data
    public static class Test {
        private String keyword;
        private String xqId;

        public void setXq_id(String xqId) { //setxq_id also seems to work
            this.xqId = xqId;
        }
    }

upon calling curl -X GET 'http://localhost:8080/modeltest?xq_id=1' --header 'Content-Type: application/json', it logged Test(keyword=null, xqId=1) . Though this may not work for every case (i.e. if the request param is kebab case xq-id).

source:
How to customize parameter names when binding Spring MVC command objects?

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
Posted by: pebble unit