-
day67 - Spring Framework(mvc)KIC/Spring 2021. 9. 23. 15:58반응형
[EventController.java]
package controller; import java.util.List; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import event.Event; import event.SearchOption; import service.EventService; import event.EventType; @Controller @RequestMapping("/event") public class EventController { private static final String REDIRECT_EVENT_LIST = "redirect:/event/list"; private EventService eventService; public EventController() { eventService = new EventService(); } @RequestMapping("/list") public String list (SearchOption option, Model model) { List<Event> eventList = eventService.getOpenedEventList (option); model.addAttribute("eventList", eventList); model.addAttribute("eventTypes", EventType.values()); return "event/list"; } @RequestMapping("/list2") public ModelAndView list2(SearchOption option) { List<Event> eventList = eventService.getOpenedEventList (option); ModelAndView modelView = new ModelAndView(); modelView.setViewName("event/list"); modelView.addObject("eventList", eventList); modelView.addObject("eventTypes", EventType.values()); return modelView; } }
[Event.java]
package event; public class Event { private Long id; private String name; private EventType type; public Long getId() { return id; } public String getName() { return name; } public EventType getType() { return type; } public static Event create(Long id, String name, EventType type) { Event result = new Event(); result.id = id; result.name = name; result.type = type; return result; } }
[EventType.java]
package event; public enum EventType { FLASHMOB, CIRCUS, CONFERENCE }
[SearchOption.java]
package event; import java.util.Collection; import java.util.Date; public class SearchOption { private Collection<EventType> types; private boolean allType; private Date from; private Date to; public Collection<EventType> getTypes() { return types; } public void setTypes(Collection<EventType> types) { this.types = types; } public boolean isAllType() { return allType || types == null; } public void setAllType(boolean allType) { this.allType = allType; } public Date getFrom() { return from; } public void setFrom(Date from) { this.from = from; } public Date getTo() { return to; } public void setTo(Date to) { this.to = to; } }
300x250'KIC > Spring' 카테고리의 다른 글
day69 - Spring Framework(spring boot 시작하기 STS4) (0) 2021.09.27 day68 - 스프링 팀 프로젝트 관리자 페이지 구현 (0) 2021.09.27 day66 - Spring Framework(mvc) (0) 2021.09.17 day65 - Spring Framework(스프링, Annotation) (0) 2021.09.15 day64 - Spring Framework(스프링, AOP) (0) 2021.09.14