onAuthenticationSuccess 拿到用户id
时间: 2023-08-15 20:13:56 浏览: 60
在Spring Security中,onAuthenticationSuccess方法的目的是在用户成功认证后执行一些自定义的逻辑。它接收两个参数:HttpServletRequest和HttpServletResponse。要拿到用户id,你可以通过HttpServletRequest获取已认证的Principal对象,然后从中获取用户id。
以下是一个示例代码:
```java
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
// 获取已认证的Principal对象
UserDetails userDetails = (UserDetails) authentication.getPrincipal();
// 从Principal对象中获取用户id
String userId = userDetails.getUsername();
// 执行你的自定义逻辑
// ...
}
```
请注意,具体的代码实现可能会因为你的项目配置和需求而有所不同。这只是一个简单的示例,你可以根据自己的需求进行调整和扩展。
相关问题
document.querySelector拿到ID
如果你想使用 `document.querySelector` 方法获取一个ID为 "example" 的元素,你可以使用下面的代码:
```javascript
const element = document.querySelector("#example");
```
其中,`#example` 是CSS选择器,表示匹配ID为 "example" 的元素。注意,CSS选择器中的ID前面要加上 `#` 符号。
LambdaQueryWrapper查询拿不到id
LambdaQueryWrapper查询拿不到id的原因可能是在查询条件中没有包含id字段。根据引用\[1\]中的代码示例,LambdaQueryWrapper的like方法用于拼接like查询条件,但是它只会拼接指定字段的like查询条件,而不会拼接其他字段的查询条件。所以如果想要查询id字段,需要在LambdaQueryWrapper中添加相应的条件。例如,可以使用eq方法来添加等于条件,如eq("id", idValue)。这样就可以在查询中包含id字段了。
#### 引用[.reference_title]
- *1* *2* [lambdaQueryWrapper模糊查询like方法](https://blog.csdn.net/qq_44764295/article/details/126536601)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)