ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 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

    댓글

Designed by Tistory.