What AJAX libraries work well with Spring MVC?
I'm new to developing with Spring and Spring MVC. From the documentation at http://www.springsource.org I'm not yet understanding what AJAX framework Spring MVC has built-in or what third party APIs and tooling might be suggested as working well with developing a Spring MVC application.
All recommendations are appreciated.
I did search through previous SO discussions on this subject, but I didn't get any clear direction.
Spring is super easy to use with Ajax. If Jackson is on the classpath Spring can use it for returning JSON to the caller. Something like this:
@RequestMapping( "/my/path" )
public @ResponseBody MyObject doSomething( @RequestParam Long myVal ) {
MyObject result = new MyObject( myVal );
// do something interesting
return result;
}
Then you can use jQuery (or your other favorite javascript library) to make a request to http://myserver/my/path
and handle the resulting JSON object.
Google's GSON is also easy to use. As in:
@RequestMapping( "/my/path" )
public ResponseEntity<String> MyObject doSomething( @RequestParam Long myVal ) {
MyObject result = new MyObject( myVal );
// do something interesting
HttpHeaders headers = new HttpHeaders();
headers.set( "Content-Type", "application/json" );
String json = gson.toJson( result );
return new ResponseEntity<String>( json, headers, HttpStatus.CREATED );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With