MVC is a well-known pattern used to reduce complexity and to increase reusability of your code, widely adopted in server-side languages. Spring MVC is an example of a really powerful framework that adopts this pattern extensively allowing you to create easily RESTful web services. MVC can also be applied to the client now and this approach really suits AJAX applications and single page applications. Backbone.js is one of the frameworks available to enforce this pattern. In this session we will explore how well you can integrate Spring MVC and Backbone.js in a really performant and neat single page application. Focus will be put on how Backbone.js can consume RESTful web services.
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
MVC on the Server and on the Client: How to Integrate Spring MVC and Backbone.js: Sebastiano Armeli-Battana
1. MVC on the server and
on the client
How to integrate Spring MVC and
Backbone.js
Sebastiano Armeli-Battana
@sebarmeli
July 10 , 2012 JAXConf, San Francisco
2. Model - View - Controller
Architectural Design Pattern Model
Business logic / presentation layer
View Controller
Reusability
Components isolation
3. Passive and Active MVC
View Model
Passive Approach
Controller
Controller View
Active Approach
Observer
pattern
Model
8. Spring MVC in action
@Controller
public class ContactsController {
@Autowired
private ContactService service;
CONTROLLER
@RequestMapping(value=”/list”, method = RequestMethod.GET)
public @ResponseBody List<Contact> getContacts() {
return service.getContacts();
}
}
Service Layer (@Service)
VIEW
DAO (@Repository) [{
“id” : 31,
“firstname” : “LeBron”,
“lastname” : “James”,
MODEL
“telephone” : “111-222-3333”
}]
9. What about the Model?
@Entity
@Table(name=”Contacts”)
public class Contact {
@Id
@Column(name = ”ID”)
@GeneratedValue
private Integer id;
@Column(name = “FIRSTNAME”)
private String firstname;
public String getFirstname(){
return firstname;
}
public void setFirstname(){
this.firstname = firstname;
}
...
}
10.
11. Why MVC in JavaScript ??
AJAX application with lots of JS code
Managing efficiently jQuery selectors and callbacks
Decoupling components
Simplify communication with RESTful WS