A Journey Into the Emotions of Software Developers
MVC on the server and on the client: Integrating Spring MVC and Backbone.js
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
Active Approach Controller View
Observer
pattern
Model
8. Spring MVC in action
C @Controller
O public class ContactsController {
N @Autowired
T private ContactService service;
R
O @RequestMapping(value=”/list”, method = RequestMethod.GET)
L public @ResponseBody List<Contact> getContacts() {
L return service.getContacts();
E }
R }
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
\n\npring MVC delegates to a HttpMessageConverter to perform the serialization. In this case, Spring MVC invokes a MappingJacksonHttpMessageConverterbuilt on the Jackson JSON processor. This implementation is enabled automatically when you use the mvc:annotation-driven configuration element with Jackson present in your classpath.\n