0

I have searched and everything seems to say as long as you use spring 4+ I should be able to use dot notation to bind request parameters to a pojo.

This is what my request looks like: enter image description here

And this is what my controller looks like: enter image description here

And my dto:

I even tried adding @RequestParam("p.page") int page in the controller to make sure my endpoint was getting hit and it does. Am I missing something obvious or am I not allowed to use dot notation to populate a pojo with a spring controller?

enter image description here

And the parent class:


public class JhmPageableDto
{
    private String query;
    private int page;
    private int size;
    private String sort;
    private boolean sortAsc;
    
    public String getQuery()
    {
        return query;
    }
    
    public void setQuery(String query)
    {
        this.query = query;
    }
    
    public int getPage()
    {
        return page;
    }
    
    public void setPage(int page)
    {
        this.page = page;
    }
    
    public int getSize()
    {
        return size;
    }
    
    public void setSize(int size)
    {
        this.size = size;
    }
    
    public String getSort()
    {
        return sort;
    }
    
    public void setSort(String sort)
    {
        this.sort = sort;
    }
    
    public boolean isSortAsc()
    {
        return sortAsc;
    }
    
    public void setSortAsc(boolean sortAsc)
    {
        this.sortAsc = sortAsc;
    }
    
}
testing123
  • 11,367
  • 10
  • 47
  • 61
  • Any reason you are not using Pageable? https://www.baeldung.com/spring-data-web-support – samabcde Jul 02 '22 at 02:47
  • Good question, I thought about it but wanted to include my search string (query and two other filter properties). – testing123 Jul 02 '22 at 16:15
  • I tried subclassing PageRequest, but when I do that I get a bad request error. If necessary I can just have the Pageable and my own "Searchable" object. I was just hoping I could combine the two and don't understand why the dot notation isn't working for me. It's probably something obvious that I am just missing...I can work around it, but I want to understand what I am doing wrong. – testing123 Jul 02 '22 at 16:51
  • And can you edit the post to show test instead of image? – samabcde Jul 03 '22 at 04:37
  • Does this answer your question? [Spring MVC: Complex object as GET @RequestParam](https://stackoverflow.com/questions/16942193/spring-mvc-complex-object-as-get-requestparam) – samabcde Jul 03 '22 at 04:47
  • 1
    Yes, I remember doing this previously but thought it was with RequestParam, but it was @Valid that did it. If you post your answer as an answer instead of a comment, I will mark it as the answer so you can get credit for this. – testing123 Jul 09 '22 at 18:15
  • Probably mark as duplicate is more appropriate – samabcde Jul 10 '22 at 02:31

0 Answers0