Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Why does @GetMapping return my request parameter?

 
Ranch Hand
Posts: 49
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why does @GetMapping return my request parameter?

You can see my jsp and controller files and link. JSP shows parameter which I sent by request, although their names are different.







http://localhost:8080/UCM-controller/ULD_details?ID=1144

in result , jsp shows 1144 on table

Thanks in advance.



 
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that you may want to do something like
You can read more about this here http://www.baeldung.com/spring-requestmapping
It looks like before you were returning a hard coded string value.

To return an POJO I think you would want something kind of like
 
Miri Yusifli
Ranch Hand
Posts: 49
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Pete Letkeman wrote:I think that you may want to do something like
You can read more about this here http://www.baeldung.com/spring-requestmapping
It looks like before you were returning a hard coded string value.

To return an POJO I think you would want something kind of like



Thanks, but this code works perfectly without @RequestParam


Why when I set class as parameter it works described above?
 
Pete Letkeman
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Miri Yusifli wrote:Why when I set class as parameter it works described above?

I'm not too sure what you mean by this statement.
If I were to rephrase this, would this be correct?

When I pass a class as a parameter this method seems to work, however I'm not too sure why I need to pass in a class when I only need a single string/int value.


If this is the case then I suspect this has to do with how Spring reads in the values from either the GET or from the POST methods.
What if you change the way you navigate to the page, maybe the data is coming from a form or session values?
 
Miri Yusifli
Ranch Hand
Posts: 49
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Pete Letkeman wrote:

Miri Yusifli wrote:Why when I set class as parameter it works described above?

I'm not too sure what you mean by this statement.
If I were to rephrase this, would this be correct?

When I pass a class as a parameter this method seems to work, however I'm not too sure why I need to pass in a class when I only need a single string/int value.


If this is the case then I suspect this has to do with how Spring reads in the values from either the GET or from the POST methods.
What if you change the way you navigate to the page, maybe the data is coming from a form or session values?




If I get param as primitive type or String it works correctly, but when I try to get all params as fields of a object, it works described above.Also, I test another class instead of Palet in other method and result is the same.
 
Pete Letkeman
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Miri Yusifli wrote:If I get param as primitive type or String it works correctly, but when I try to get all params as fields of a object, it works described above.


Oh, okay sorry for the misunderstanding.

Here are two possible reasons:
  • For field name mapping, spelling matter, including case. (can be overridden)
  • Most of the time you should send only a very limited amount of data using GET.

  • From what I'm able to find many people do not send full POJOs using GET.
    You may want to look into use the @ModelAttribute annotation as this may allow this type of binding.
    Alternatively, I suspect that you could create a method which injects all of the GET values into your POJO.
     
    Consider Paul's rocket mass heater.
      Bookmark Topic Watch Topic
    • New Topic