在DTO中我们可以将id用作String还是Long [英] In DTO Can we use id as String or Long
问题描述
我们通常使用DTO将对象从一种形式转移到另一种形式(例如JSON),所以我的疑问是:我可以将DTO id用作String,还是应该保留尽可能长的时间?
We use DTOs normally to transfer object from one to another form(say JSON), so my doubt is: can I use DTO id as String, or it should be left as long only?
我的模型无论如何都使用long作为id,并且我使用mapstruct将对象从模型映射到DTO,如果我将id用作String而不是稍后会在POST / GET中遇到任何问题?
My Model anyhow uses long for id, and I use mapstruct to map object from model to DTO, do I am gonna face any issues later either for POST/GET, if I use id as String, instead of long for DTO class?
推荐答案
不,你不能那样做。
您可以通过从Postman发送json进行测试,并在反向字符串逗号中放入一个长id,而spring会为此抱怨。
You can test it by sending json from Postman and put a long id in inverted string commas and spring will complain for that.
这篇关于在DTO中我们可以将id用作String还是Long的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!