spring-boot - Pass userID in @PrePersist (@PreUpdate) method using Spring Boot and JWT
问题描述
I'm using JWT for authentication in my application and I need to pass the userID to the method @PrePersist in the @Entity classes. How can I do it?
This is my @RestController where pass the JwtToken:
@PostMapping(value = "/car")
public ResponseEntity<GenericResponse<String>> addCar(
@RequestHeader(value = "Authorization") String token,
@RequestParam(value = "plate") String plate) {
// some stuff
}
And this is the PrePersist method in Entity classes:
@PrePersist
public void onPrePersist() {
creationtime = Timestamp.from(Instant.now());
//TODO creationuser = userID from token
}
Can I get the token info in Entity? What's the best way to do it?
解决方案
推荐阅读
- android - FCM 未收到通知消息
- json - 来自 JSON 字符串的 Sh Script JSON 值
- validation - Golang 验证器无效的内存地址或 nil 指针取消引用
- r - 如何让 geom_errorbar 在 ggplot2 的条形图上正确“闪避”?
- python - Scapy:使用 get_trace() 方法索引 traceroute 结果返回 TypeError
- javascript - 安全地将 Javascript 变量传递给 PHP
- python - 如何使用 tf.reshape()?
- java - 如何在arcore android应用程序中将一个3d模型覆盖在另一个上
- dart - 包:flutter/src/widgets/overlay.dart':断言失败:第 133 行 pos 12:'_overlay != null':
- gdb - 为什么使用 GDB 在 CodeBlocks 中添加和删除断点时会抛出 SIGTRAP 和 SIGILL?