如果使用@EnableWebMvc 注解,为什么@RequestBody 调用的Dto 必须用@NoArgsConstructor 注解?
If you are using @EnableWebMvc annotation, why must the Dto that @RequestBody calls be annotated with @NoArgsConstructor?
在项目中使用 @EnableWebMvc
时 @RequestBody
注释在 RestController
中使用的 Dto
必须具有 @NoArgsConstructor
的原因是什么?
如果项目没有@EnableWebMvc
,很容易用@Getter
注解自动映射,不用@NoArgsConstructor
.
如果您使用@EnableWebMvc,这意味着您赋予Spring做必要事情的责任。 @EnableWebMvc 确保 Spring 通过预定义注释 @NoArgsConstructor 从用户那里控制必要的无参数构造函数。
它还避免了开发人员必须编写的不必要的样板代码。
在项目中使用 @EnableWebMvc
时 @RequestBody
注释在 RestController
中使用的 Dto
必须具有 @NoArgsConstructor
的原因是什么?
如果项目没有@EnableWebMvc
,很容易用@Getter
注解自动映射,不用@NoArgsConstructor
.
如果您使用@EnableWebMvc,这意味着您赋予Spring做必要事情的责任。 @EnableWebMvc 确保 Spring 通过预定义注释 @NoArgsConstructor 从用户那里控制必要的无参数构造函数。
它还避免了开发人员必须编写的不必要的样板代码。