问题
I used spring MVC in the following manner:
@Controller
class MyControllerClass {
@RequestMapping...
method(){
ServiceCall()...
//put something to modelAndView object here and redirect to jsp page.
return "home"; // this will redirect data to home.jsp
}
}
@Service
class MyServiceClass{
@Transactional
SomeServiceMethod(){
DaoMethod();
}
}
@Repository
class MyDaoClass{
DaoMethdon(){...}
}
/view/myjsps.jsp path to view directory set in spring.xml
Question:
Can any body explain to me (preferably with actual real world code example(s)), that what alternatives do I have, for the above mentioned MVC pattern, in Java EE 6/7. ie. controller, service, dao, view layers.
Further more, how to redirect pages, (I believe plain requestDispatcher
is an old way of doing things, there got to be some automated ways. Same goes with modelAndView
.
I have googled a lot but all I find is spring mvc examples
.
回答1:
Java EE doesn't have a 'standard' MVC package. If you go straight Java EE you'll be dealing directly with HttpServletRequests, PortletRequests etc. Putting objects in the 'model' in plain Java EE is basically HttpServletRequest.setAttribute(), or HttpSession.setAttribute() (if @SessionAttributes)
来源:https://stackoverflow.com/questions/24360391/mvc-pattern-in-java-ee-and-migrating-from-spring-to-java-ee-7