Spring MVC知识点补充

      Spring MVC的核心是DispatcherServlet,其初始化配置拥有一系列的组件。拥有默认的组件实现。

  1.DispatcherServlet装配各型组件的逻辑

组件类型发现机制
文件上传解析器

1)查找名为multipartResolver类型为MultipartResolver的Bean作为该类型组件

2)没有默认的实现类

如果用户没有在上下文中显式的定义这一类型的组件,DispatcherServlet将不会拥有该类型的组件。

本地化解析器

1)查找名为localeResolver类型为LocaleResolver的Bean作为该类型组件

2)如果1)找不到,使用默认的实现类(AcceptHeaderLocaleResolver)创建该类型组件

主题解析器

1)查找名为themeResolver类型为ThemeResolver的Bean作为该类型组件

2)如果1)找不到,使用默认的实现类(FixedThemeResolver)创建该类型组件
处理器映射器*(多个实例 order属性确定优先级)

1)如果detectAllHandlerMappings属性为true,默认为true根据类型匹配机制查找上下文及父Spring容器中所有类型为HandlerMapping的Bean,将他们作为该类型组件

2)如果detectAllHandlerMappings属性为false,查找名为handlerMapping,类型为HandlerMapping的的Bean作为该类型组件

3)如果通过以上两种方式都找不到,使用BeanNameUrlHandlerMapping实现类创建该类型组件

处理器适配器*(多个实例 order属性确定优先级)

1)如果detectAllHandlerAdapters属性为true,默认为true根据类型匹配机制查找上下文及父Spring容器中所有类型为HandlerAdapter的Bean,将他们作为该类型组件

2)如果detectAllHandlerAdapters属性为false,查找名为handlerAdapter,类型为HandlerAdapter的的Bean作为该类型组件

3)如果通过以上两种方式都找不到,使用DispatcherServlet.proeprties配置文件中指定的三个实现类分别创建一个适配器,添加到适配器列表中
处理器异常解析器(多个实例 order属性确定优先级)

1)如果detectAllHandlerExceptionResolvers属性为true,默认为true根据类型匹配机制查找上下文及父Spring容器中所有类型为HandlerExceptionResolver的Bean,将他们作为该类型组件

2)如果detectAllHandlerExceptionResolvers属性为false,查找名为handlerExceptionResolver类型为HandlerExceptionResolver的的Bean作为该类型组件

3)如果通过以上两种方式都找不到,使用DispatcherServlet.proeprties默认实现类
视图名称翻译器

1)查找名为viewNameTranslator;类型为RequestToViewNameTranslator的Bean作为该类型组件

2)如果1)找不到,使用默认的实现类(DefaultRequestToViewNameTranslator)创建该类型组件

视图解析器(多个实例 order属性确定优先级)

1)如果detectAllResolvers属性为true,默认为true根据类型匹配机制查找上下文及父Spring容器中所有类型为ViewResolver的Bean,将他们作为该类型组件

2)如果detectAllResolvers属性为false,查找名为viewResolver,类型为ViewResolver的的Bean作为该类型组件

3)如果通过以上两种方式都找不到,使用DispatcherServlet.proeprties配置文件中定义的默认实现类(InternalResourceViewResolver)创建该类型组件

 

 

 

Spring  MVC

  C:Contorller ,Spring 3.0支持以注解方式的驱动器,使得普通POJO类可以成为处理HTTP请求的控制器

@Controller
public class UserContorller{

   @RequestMapping("user/register")
   public String register(){
      return "user/register";

}
   @RequestMapping("{userId}")
   public ModelAndView showDetail(@PathVariable("userId")String userId){
       ModelAndView mav=new ModelAndView();
       mav.setViewName("user/showDetail");
       mav.addObject("user",userService.getUserId(userId));
      return mav;

}

}

   @RequestMapping不仅支持标准URL,还支持Ant风格的?* **  {XXX},占位符URL是Spring3.0新增功能

    占位符可以通过@PathVariable绑定到方法的入参中

 

   @RequestMapping(value="/delete",method=RequestMethod.Post,params="userId",headers="content-type=text/*")

@RequestMapping除了可以使用请求URL映射请求外,还可以使用请求方法,请求头参数和请求参数(报文体和URL包含的请求参数)映射请求。

value->请求URL    method->请求方法  params->请求参数  headers->报文头

params headers支持简单的表达式 params演示:

  • param1  包含
  • !param1 不包含
  • param1!=value1 包含param1的请求参数,其值不能为value1

 Spring  MVC处理方法

处理方法签名详细说明:(设置方法入参绑定请求信息,定义返回值类型,Spring MVC对不同签名的处理方法如何进行调用等)

@RequestParam绑定请求参数值  属性 value  required defaultValue

@CookieValue 绑定请求中的Cookie值  属性 value  required defaultValue

@RequestHeader 绑定请求报文头的属性值  属性 value  required defaultValue

使用命令、表单对象绑定请求参数值  POJO类拥有若干属性,会自动装配

使用Servlet  API对象 HttpServletRequest  HttpServletResponse  HttpSession

Spring MVC定义了代理类 WebRequest  NativeWebRequest

使用IO对象作为入参 (即OutputStream=>ServletResponse.getOutputStream()  

Writer=>Serv;etResponse.getWriter()   InputStream=>ServletRequest.getInputStream()  Reader=>ServletRequest.getReader())

其他类型参数 如Locale=>  HttpServletRequest.getLocale()

                          Principle=>HttpServletRequest.getUserPrincipal()

 

 

2.HttpMessageConverter<T>

Spring3.0新增的重要接口,他负责将请求信息转换为一个对象(类型T),将对象(类型T)输出为响应信息

public interface HttpMessageConverter<T> {

	/**
	 * Indicates whether the given class can be read by this converter.
	 * @param clazz the class to test for readability
	 * @param mediaType the media type to read, can be {@code null} if not specified.
	 * Typically the value of a {@code Content-Type} header.
	 * @return {@code true} if readable; {@code false} otherwise
	 */
	boolean canRead(Class<?> clazz, MediaType mediaType);

	/**
	 * Indicates whether the given class can be written by this converter.
	 * @param clazz the class to test for writability
	 * @param mediaType the media type to write, can be {@code null} if not specified.
	 * Typically the value of an {@code Accept} header.
	 * @return {@code true} if writable; {@code false} otherwise
	 */
	boolean canWrite(Class<?> clazz, MediaType mediaType);

	/**
	 * Return the list of {@link MediaType} objects supported by this converter.
	 * @return the list of supported media types
	 */
	List<MediaType> getSupportedMediaTypes();

	/**
	 * Read an object of the given type form the given input message, and returns it.
	 * @param clazz the type of object to return. This type must have previously been passed to the
	 * {@link #canRead canRead} method of this interface, which must have returned {@code true}.
	 * @param inputMessage the HTTP input message to read from
	 * @return the converted object
	 * @throws IOException in case of I/O errors
	 * @throws HttpMessageNotReadableException in case of conversion errors
	 */
	T read(Class<? extends T> clazz, HttpInputMessage inputMessage)
			throws IOException, HttpMessageNotReadableException;

	/**
	 * Write an given object to the given output message.
	 * @param t the object to write to the output message. The type of this object must have previously been
	 * passed to the {@link #canWrite canWrite} method of this interface, which must have returned {@code true}.
	 * @param contentType the content type to use when writing. May be {@code null} to indicate that the
	 * default content type of the converter must be used. If not {@code null}, this media type must have
	 * previously been passed to the {@link #canWrite canWrite} method of this interface, which must have
	 * returned {@code true}.
	 * @param outputMessage the message to write to
	 * @throws IOException in case of I/O errors
	 * @throws HttpMessageNotWritableException in case of conversion errors
	 */
	void write(T t, MediaType contentType, HttpOutputMessage outputMessage)
			throws IOException, HttpMessageNotWritableException;

}

 

    HttpMessageConverter<T>实现类

实现类功能说明
StringHttpMessageConverter

用途:将请求信息转为字符串

1)T为String类型

2)可读取所有媒体类型(*/*)的请求信息,可以通过设置supportedMediaTypes属性指定媒体类型

3)响应信息的媒体类型为text/plain(即Content-Type的值)

FormHttpMessageConverter

用途:将表单数据读取到MultiValueMap中

1)T为org.springframework.util.MultiValueMap<String,?>类型

2)支持读取application/x-www-form-urlencoded的媒体类型,但不支持读取multipart/form-data的媒体

3)可写application/x-www-form-urlencoded及multipart/form-data媒体类型的响应信息
XmlAwareFormHttpMessageConverter拓展与FormHttpMessageConverter,如果部分表单属性是Xml数据,可用改转换器读取
ResourceHttpMessageConverter

用途:读写org.srpingframework.core.io.Resource对象

1)T类型为org.srpingframework.core.io.Resource类型

2)可以读取所有媒体类型(*/*)的请求信息

3)如果类路径下提供了JAF(Java  Activation  Framework),则根据Resource的类型指定响应的媒体类型,否则响应媒体类型为application/octet-stream

BufferedImageHttpMessageConverter

用途:读写BufferedImage对象

1)T类型为BufferedImage类型

2)可以读取所有媒体类型

3)返回BufferedImage相应的媒体类型,也可以通过contentType显示指定

 ByteArrayHttpMessageConverter

 用途:读写二进制数据

1)T为byte[]类型

2)可以读取所有的媒体类型(*/*)的请求信息,可通过设置supportedMediaTypes属性指定媒体类型

3)响应媒体类型为application/octet-stream

 HttpMessageConverter 
 HttpMessageConverter 
 HttpMessageConverter 
 HttpMessageConverter 
 HttpMessageConverter 
 HttpMessageConverter 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
蛋白质是生物体中普遍存在的一类重要生物大分子,由天然氨基酸通过肽键连接而成。它具有复杂的分子结构和特定的生物功能,是表达生物遗传性状的一类主要物质。 蛋白质的结构可分为四级:一级结构是组成蛋白质多肽链的线性氨基酸序列;二级结构是依靠不同氨基酸之间的C=O和N-H基团间的氢键形成的稳定结构,主要为α螺旋和β折叠;三级结构是通过多个二级结构元素在三维空间的排列所形成的一个蛋白质分子的三维结构;四级结构用于描述由不同多肽链(亚基)间相互作用形成具有功能的蛋白质复合物分子。 蛋白质在生物体内具有多种功能,包括提供能量、维持电解质平衡、信息交流、构成人的身体以及免疫等。例如,蛋白质分解可以为人体提供能量,每克蛋白质能产生4千卡的热能;血液里的蛋白质能帮助维持体内的酸碱平衡和血液的渗透压;蛋白质是组成人体器官组织的重要物质,可以修复受损的器官功能,以及维持细胞的生长和更新;蛋白质也是构成多种生理活性的物质,如免疫球蛋白,具有维持机体正常免疫功能的作用。 蛋白质的合成是指生物按照从脱氧核糖核酸(DNA)转录得到的信使核糖核酸(mRNA)上的遗传信息合成蛋白质的过程。这个过程包括氨基酸的活化、多肽链合成的起始、肽链的延长、肽链的终止和释放以及蛋白质合成后的加工修饰等步骤。 蛋白质降解是指食物中的蛋白质经过蛋白质降解酶的作用降解为多肽和氨基酸然后被人体吸收的过程。这个过程在细胞的生理活动中发挥着极其重要的作用,例如将蛋白质降解后成为小分子的氨基酸,并被循环利用;处理错误折叠的蛋白质以及多余组分,使之降解,以防机体产生错误应答。 总的来说,蛋白质是生物体内不可或缺的一类重要物质,对于维持生物体的正常生理功能具有至关重要的作用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值