spring-boot - 如何在 json 返回对象 spring boot 中包含 Embedded 属性
问题描述
我有一个带有以下实体的 Kotlin Spring Boot 应用程序:
import com.fasterxml.jackson.annotation.JsonIgnore
import javax.persistence.*
@Entity
@Table(name = "users")
class Users(
@Id
var username: String = "",
@JsonIgnore
var password: String = "",
@JsonIgnore
var enabled: Boolean = false,
@ElementCollection
@CollectionTable(name = "authorities", joinColumns = [JoinColumn(name = "username")])
@MapKeyColumn(name = "users")
private var authorities : MutableSet<Authorities> = mutableSetOf()
)
和
@Embeddable
class Authorities(
var authority: String
)
当我调用此端点时:
@GetMapping("/users")
fun getUserById(@RequestParam(value = "username") username : String) : ResponseEntity<Users>{
val optionalUser = usersService.getByUsername(username)
return if(optionalUser.isPresent) ResponseEntity.ok(optionalUser.get())
else ResponseEntity(HttpStatus.BAD_REQUEST)
}
它正确返回,如您在此 json 中所见:
{
"username": "test@gmail.com"
}
但它不会返回属于该用户的权限列表,我想让它返回。我的问题是:我该怎么做?
非常感谢你的帮助
解决方案
推荐阅读
- bash - 检索协同进程的输出和退出代码
- node.js - nodejs无法循环数组对象
- python - 如何使用python从excel列中检索一个url,然后用chrome和登录密码打开它?
- php - 如何在wordpress中通过简码显示不同类别的帖子数
- javascript - d3.js 错误对象为字符串
- swagger - 如何使用 swagger 3.x 从源注释生成 OAS yaml 文件?
- javascript - 如何将表单保存到 vb.net 中的图像文件?
- python-3.x - 为什么斐波那契计算停留在值 > 35
- javascript - 在javascript中为加载图像创建进度条
- reactjs - react-table 在数据中渲染组件