Java 如何使用@ModelAttribute测试SpringWeb控制器的POST方法
我想知道如何测试SpringWeb控制器的POST方法 以下是我的方法:Java 如何使用@ModelAttribute测试SpringWeb控制器的POST方法,java,spring,testing,Java,Spring,Testing,我想知道如何测试SpringWeb控制器的POST方法 以下是我的方法: @PostMapping public String create(@ModelAttribute(name = "event")EventRequestModel eventRequestModel, HttpServletRequest request) throws EventCategoryNotFoundException, ParticipantNotFoundExcepti
@PostMapping
public String create(@ModelAttribute(name = "event")EventRequestModel eventRequestModel, HttpServletRequest request)
throws EventCategoryNotFoundException, ParticipantNotFoundException {
LOGGER.info("create(" + eventRequestModel + ")");
EventModel eventModel = eventManagerService.create(eventRequestModel);
LOGGER.info("create(...) = " + eventModel);
return "redirect:" + EVENTS_URL;
}
下面是我的EventRequestModel类:
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class EventRequestModel {
private Long id;
private String name;
private String hostId;
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm")
private LocalDateTime dateTime;
private String url;
private int durationInMinutes;
private String categoryId;
}