Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用@ModelAttribute测试SpringWeb控制器的POST方法_Java_Spring_Testing - Fatal编程技术网

Java 如何使用@ModelAttribute测试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

我想知道如何测试SpringWeb控制器的POST方法

以下是我的方法:

@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;
}