This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python 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
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Spring Call a method from main  RSS feed

 
Ranch Hand
Posts: 1301
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

please, how could I call a method in Spring Boot? Having this main:



And been the method in another Class



From the browser I call localhost:8080/send

It reaches the sendL method but  the  lObject is empty. It looks to me like I am no passing any values thougth the arguments.
 
Angus Ferguson
Ranch Hand
Posts: 1301
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At the moment I am passing the parameter like this


From the browser I call

But as the lObject isnt a String I get the error;



Then how should I send an object to a method with Spring?

Also in the



I have instantiated a mock object like this



How could I get an object with a value in the called method?





 
Saloon Keeper
Posts: 1111
36
IBM DB2 Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're sending a complex object, you should use POST, not GET.



Try Postman or  Advanced REST client Chrome's extension to work with REST services requireng to POST entities (for example; I used to use those tools, I presume many others are available)
 
Sheriff
Posts: 21641
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need @RequestBody if you do a form POST and these form fields map to properties of the method argument. It possibly also works with GET request and query parameters, never tried it. @RequestBody is mostly used with JSON or XML request bodies.
 
Claude Moore
Saloon Keeper
Posts: 1111
36
IBM DB2 Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Spoor wrote:You don't need @RequestBody if you do a form POST and these form fields map to properties of the method argument. It possibly also works with GET request and query parameters, never tried it. @RequestBody is mostly used with JSON or XML request bodies.


Yes Rob, you're right. I presumed that OP was talking about a REST API, that's why I used @RequestBody. About using GET and query parameters, it should work,  but somehow I presumed that send() method was intended to create an entity, so that I assumed that a POST would have been a better choice.
 
Rob Spoor
Sheriff
Posts: 21641
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're right, POST would be a better option.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!