Spring MVC Knowledge

Source: Internet
Author: User

F-sm-1. Talk about the comparative advantages of SPRINGMVC and struts1,struts2.

  性能上Struts1>SpringMvc>Struts2 开发速度上SpringMvc和Struts2差不多,比Struts1要高
F-sm-2. What is the core entrance class of SPRINGMVC, and what is the difference between struts1,struts2?
  SpringMvc的是DispatchServlet,Struts1的是ActionServlet,Struts2的是StrutsPrepareAndExecuteFilter
F-sm-3. SPRINGMVC Controller is not a singleton mode, if yes, what is the problem, how to solve
  是单例模式,所以在多线程访问的时候有线程安全问题,不要用同步,会影响性能的,解决方案是在控制器里面不能写字段
F-sm-4. Annotations for controllers in Spingmvc generally with that, there are no other annotations to replace
  一般用@Conntroller注解,表示是表现层,不能用用别的注解代替.
F-sm-5. What does @RequestMapping annotation do with a class?
  用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径。
F-sm-6. How to map a request to a specific method
  直接在方法上面加上注解@RequestMapping,并且在这个注解里面写上要拦截的路径
F-sm-7. If in the interception request, I want to intercept the method that the Get method commits, how to configure
  可以在@RequestMapping注解里面加上method=RequestMethod.GET
F-sm-8. If in the interception request, I want to intercept the commit parameter contains the "Type=test" string, How to configure
  可以在@RequestMapping注解里面加上params="type=test"
F-sm-9. I want to get the parameters from the foreground in the interception method, how to get
  直接在形参里面声明这个参数就可以,但必须名字和传过来的参数一样
F-sm-10. If the foreground has a number of parameters passed in, and these parameters are all an object, then how to get this object quickly
  直接在方法中声明这个对象,SpringMvc就自动会把属性赋值到这个对象里面
F-sm-11. How to get a request in a method, or a session
  直接在方法的形参中声明request,SpringMvc就自动把request对象传入
F-sm-12. What is the return value of the function in Springmvc.
  返回值可以有很多类型,有String, ModelAndView,当一般用String比较好
F-sm-13. Springmvc How to handle the return value
  SpringMvc根据配置文件中InternalResourceViewResolver的前缀和后缀,用前缀+返回值+后缀组成完整的返回值
F-sm-14. Springmvc how to set redirection and forwarding
  在返回值前面加"forward:"就可以让结果转发,譬如"forward:user.do?name=method4" 在返回值前面加"redirect:"就可以让返回值重定向,譬如"redirect:http://www.baidu.com"
F-sm-15. Springmvc what objects are used to pass data from the background to the foreground
  通过ModelMap对象,可以在这个对象里面用put方法,把对象加到里面,前台就可以通过el表达式拿到
F-sm-16. There's a class in SPRINGMVC that combines views and data together, what's called
  叫ModelAndView
F-SM-17. How to put the data inside the Modelmap into the session
  可以在类上面加上@SessionAttributes注解,里面包含的字符串就是要放入session里面的key
F-sm-18. How SPRINGMVC and Ajax call each other.
  通过Jackson框架就可以把Java里面的对象直接转化成Js可以识别的Json对象  具体步骤如下  1.加入Jackson.jar  2.在配置文件中配置json的映射  3.在接受Ajax方法里面可以直接返回Object,List等,但方法前面要加上@ResponseBody注解
F-sm-19. What to do when a method returns special objects to Ajax, such as object,list, etc.
  要加上@ResponseBody注解
F-sm-20. SPRINGMVC, what did the Interceptor say?
  有两种写法,一种是实现接口,另外一种是继承适配器类,然后在SpringMvc的配置文件中配置拦截器即可:  <!-- 配置SpringMvc的拦截器 --><mvc:interceptors>    <!-- 配置一个拦截器的Bean就可以了 默认是对所有请求都拦截 -->    <bean id="myInterceptor" class="com.et.action.MyHandlerInterceptor"></bean>    <!-- 只针对部分请求拦截 -->    <mvc:interceptor>       <mvc:mapping path="/modelMap.do" />       <bean class="com.et.action.MyHandlerInterceptorAdapter" />    </mvc:interceptor></mvc:interceptors>
F-sm-21. Talk about the SPRINGMVC implementation process
       系统启动的时候根据配置文件创建spring的容器, 首先是发送http请求到核心控制器disPatherServlet,spring容器通过映射器去寻找业务控制器,使用适配器找到相应的业务类,在进业务类时进行数据封装,在封装前可能会涉及到类型转换,执行完业务类后使用ModelAndView进行视图转发,数据放在model中,用map传递数据进行页面显示。

Spring MVC Knowledge

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.