Spring4.0MVC learning materials, detailed explanation and use of methods in Controller (4)
In the past, the mvc framework was basically the struts framework. But now it's different. Springmvc came out. Spring's mvc framework is no less than struts. spring mvc comes out and we have more options.
Spring MVC is a follow-up product of SpringFrameWork and has been integrated into Spring Web Flow. The Spring framework provides a full-featured MVC module for Building Web applications. Using Spring-pluggable MVC Architecture, you can choose to use a built-in Spring Web framework or a Web framework such as Struts. Through the policy interface, the Spring framework is highly configurable and contains multiple view technologies, such as assumerver Pages (JSP), Velocity, Tiles, iText, and POI. The Spring MVC Framework does not know the view used, so it does not force you to only use JSP technology. Spring MVC separates the roles of controllers, model objects, schedulers, and processing program objects, making them easier to customize.
I will not talk about the introduction of the jar package. As mentioned in the previous chapters, the corresponding jar package is also available in my download resources for download.
Let's take a look at the web. xml configuration:
Spring
Org. springframework. web. servlet. DispatcherServlet
ContextConfigLocation
Classpath: com/herman/ss/config/testAjax. xml
1
Spring
*. Herman
Index. jsp
Check the spring configuration file, testAjax. xml.
Application/json; charset = UTF-8
OK. Everything is ready. Check out HermanController. java.
Package com. herman. ss. controller; import javax. servlet. http. httpServletRequest; import javax. servlet. http. httpServletResponse; import javax. servlet. http. httpSession; import org. springframework. stereotype. controller; import org. springframework. web. bind. annotation. requestMapping; import org. springframework. web. bind. annotation. responseBody; import org. springframework. web. servlet. modelAndView; @ Controller @ RequestMapping ("super") public class HermanController {@ RequestMapping ("testAjax") @ ResponseBodypublic String testAjax () {System. out. println ("I'm testing Spring mvc ...... "); return" {id: 4, text: 'spring mvc '} ";}@ RequestMapping (" html ") public String testHtml () {// The request is redirected to herman. return "redirect:/herman. jsp ";}@ RequestMapping (" testforward ") public String testforward () {// The request is forwarded to forward. return "forward:/forward. jsp ";}@ RequestMapping (value =" root ") public String root () {return" root. jsp ";}@ RequestMapping (value =" test ") public String test () {return" html/test.html ";}@ RequestMapping (value =" suffix ") public String suffix () {// if you want to return a page without a suffix, you must configure p: suffix = "" // For example: p: suffix = ". jsp "return" suffix ";}@ RequestMapping (value =" mav ") public ModelAndView mav () {// if you want to return a page without a suffix, you must configure p: suffix = "" // For example, p: suffix = ". jsp "ModelAndView mav = new ModelAndView (); mav. setViewName ("html/mav.html"); return mav ;}@ RequestMapping (value = "request") public ModelAndView request (HttpServletRequest request, HttpServletResponse response) {// example with request Parameters // For example, p: suffix = ". jsp "ModelAndView mav = new ModelAndView (); mav. setViewName ("html/mav.html"); System. out. println (request. getParameter ("testVale"); return mav ;}@ RequestMapping (value = "request") public ModelAndView session (HttpSession httpSession, HttpServletResponse response) {// example with request Parameters // For example, p: suffix = ". jsp "ModelAndView mav = new ModelAndView (); mav. setViewName ("html/mav.html"); return mav ;}}
Let's end it here. Let's see you next chapter. Welcome to my blog !!
If you have any questions or problems, or need source code, add QQ group: 135430763 for feedback and learn together!