Python 官方文档:入门教程 => 点击学习
目录SpringBoot打印POST请求原始入参body体1、首先定义过滤器配置2、实现1中的过滤器Post接收不到body里的参数(对象参数)检查注解检查实体检查Content-T
package com.choice.o2o.device.common.config;
import com.choice.o2o.device.common.filter.LogFilter;
import org.springframework.boot.WEB.servlet.FilterReGIStrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FilterConfig {
@Bean
public FilterRegistrationBean registFilter() {
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setFilter(new LogFilter());
registration.addUrlPatterns("
private String getRequestBody(ContentCachingRequestWrapper request) {
ContentCachingRequestWrapper wrapper = WebUtils.getNativeRequest(request, ContentCachingRequestWrapper.class);
if (wrapper != null) {
byte[] buf = wrapper.getContentAsByteArray();
if (buf.length > 0) {
String payload;
try {
payload = new String(buf, 0, buf.length, wrapper.getCharacterEncoding());
} catch (UnsupportedEncodingException e) {
payload = "[unknown]";
}
return payload.replaceAll("\\n", "");
}
}
return "";
}
private String getResponseBody(ContentCachingResponseWrapper response) {
ContentCachingResponseWrapper wrapper = WebUtils.getNativeResponse(response,
ContentCachingResponseWrapper.class);
if (wrapper != null) {
byte[] buf = wrapper.getContentAsByteArray();
if (buf.length > 0) {
String payload;
try {
payload = new String(buf, 0, buf.length, wrapper.getCharacterEncoding());
} catch (UnsupportedEncodingException e) {
payload = "[unknown]";
}
return payload;
}
}
return "";
}
public static String getRequestParams(httpservletRequest request) {
StringBuilder sb = new StringBuilder();
Enumeration<String> enu = request.getParameterNames();
//获取请求参数
while (enu.hasMoreElements()) {
String name = enu.nextElement();
sb.append(name + SPLIT_STRING_M).append(request.getParameter(name));
if (enu.hasMoreElements()) {
sb.append(SPLIT_STRING_DOT);
}
}
return sb.toString();
}
}
@ResponseBody
@RequestBody
接收实体类,set、get方法是否正确
是否是application/JSON
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。
--结束END--
本文标题: SpringBoot打印POST请求原始入参body体方式
本文链接: https://www.lsjlt.com/news/135405.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0