---
# System prepended metadata

title: springBoot modify servelet request before Controller handling
tags: [SPRINGBOOT]

---

# springBoot modify servelet request before Controller handling




ref: [link](https://stackoverflow.com/questions/50932518/how-to-modify-request-body-before-reaching-controller-in-spring-boot)

reminder
---
0. filter update the serveletRequest 

```java=
HttpServletRequest mod = (HttpServletRequest)servletRequest;
mod.setAttribute("trueName",userId );

//filterChain.doFilter(servletRequest, servletResponse);
        
filterChain.doFilter(mod, servletResponse);
```



1. controller method use

```java=

    @PostMapping("/getFuncAuth")
    public Map<String, Object> getFuncAuth(@RequestBody Map<String, Object> params,@RequestAttribute("trueName") String customAttribute) throws Exception {
        Map<String, Object> returnMap = new HashMap<>();
        
        params.put("user_id", customAttribute);
        
        returnMap.put("auth", service.getFuncAuth(params));
        return returnMap;
    }
```


###### tags: `SPRINGBOOT` 
