Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.9k views
in Technique[技术] by (71.8m points)

nestjs如何在post接口中转换Boolean类型参数?

1.post表单提交格式是x-www-form-urlencoded,参数到了服务端都转成了字符串格式。在dto中使用@Type(() => Boolean),boolean类型传过来true或false都被当成了字符串处理,Boolean()转换出来的都是true。

2.现有的插件是class-transformer和nest内置的ParseBoolPipe。
但是ParseBoolPipe看了下demo,都是参数比较少的情况。如果是有数十个字段的大表单,就非常不方便。

现在好像只能在dto中使用class-transformer手写@Type 和@Transform来实现。有没有简单方便一点的方案?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...