zoukankan      html  css  js  c++  java
  • Springboot读取Request参数的坑

    【后端拿参数相关】
    默认配置时,
    getInputStream()和getReader()一起使用会报错
    使用两遍getInputStream(),第二遍会为空
     
    当存在@RequestBody等注解时,springMVC已读取过一遍流,默认单独使用getInputStream()或getReader()都为空。
     
    解决:写filter继承HttpServletRequestWrapper,缓存InputStream,覆盖getInputStream()和getReader()方法,使用ByteArrayInputStream is = new ByteArrayInputStream(body.getBytes());读取InputStream。
     
    注意:springboot中,过滤器只需@Component即可生效,另外可在FilterRegistrationBean中配置路径和优先级。
     
    对于拦截器,必须在InterceptorRegistry中调用addInterceptor方法。(路径可链式添加)
     
    【关于流】
    只能读一遍,类似管子。
    只承担传输职责,而与处理和存储无关。
    对于byte流而言,进行重复读取易于实现,但指针不重置,应是为了与InputStream接口定义保持一致。
  • 相关阅读:
    HDU5120
    POJ 1062
    POJ 1086
    BestCoder 1st Anniversary (HDU 5311)
    HDU 5284
    Dylans loves sequence(hdu5273)
    day65 作业
    第三次小组分享 猴子补丁
    day59 csrf auth
    day58 cookie session 中间件
  • 原文地址:https://www.cnblogs.com/feixuefubing/p/9381731.html
Copyright © 2011-2022 走看看