Reputation: 1
I am working on a tutorial problem using Spring MVC, with another teammate for an internship. I'm not familiar with Spring (that's why I'm learning it)
We first wrote the code without any framework support, plain old hand-written MVC
We are using Spring 2.5, and integrated Hibernate, used the Autowire, Controller, Repository annotations etc.. I'm not interested in the view part yet. So we linked to the database, but the models remained the old models something like :
public class Client {
private String name;
private String bankAccount;
public String getName() {
return name;
}
public String getBankAccount() {
return bankAccount;
}
public Client(String name, String bankAccount) {
this.name = name;
this.bankAccount = bankAccount;
}
}
How is this model properly done as the 'M' part in the Spring 2.5 MVC? I'm thinking something among the lines of autowiring, and constructor injection and remaining immutable.
I just can't wrap my mind how this is properly done in the framework. Any help would be greatly appreciated, thanks.
Upvotes: 0
Views: 75
Reputation: 15
In Spring MVC - as you mentioned, we can focus just on M - Model and C - Controller part. If I understood your question correct, you asking "How to use Client model correctly with Spring framework? " So if you not focus on view part, model is place where you can get data from database and fill the details and return it to the caller of that controller. Good way to handle M-C flow ===>
Hope I was able to help. If there is more question or I gave little different answer let me know.
Upvotes: 1
Reputation: 11
Basically, your model is a mechanism for the controller to send information to the view, thus it's just great the way it is; no changes are required. You'll perform something like this to use the framework with your model:
@RequestMapping(value="/client/view")
public String viewClientPage(Model m) {
Client client = new Client( "sanyam", "123456" );
m.addAttribute( "client", client );
return "[name of a client using view goes here]";
}
in the view to get:
<h1>Name : ${client.name}</h1>
<h2>Account Number : ${client.account}</h2>
Upvotes: 1