스프링

 

Spring에서 FullCalendar(풀 캘린더)로 Google(구글) 캘린더 DB 연동하기

 

CalendarController

 

package com.gudi.calendar.controller;


import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.gudi.board.controller.BoardController;
import com.gudi.calendar.dto.CalendarDTO;
import com.gudi.calendar.service.CalendarService;

@Controller
public class CalendarController {
	
	private Logger logger = LoggerFactory.getLogger(BoardController.class);
	
	@Autowired
	private CalendarService calendarService;

	
	@RequestMapping("/calendar2")
	public String calendar2(HttpServletRequest request, Model model) throws Exception {
		return "navbar/calendar2";
	}

	@RequestMapping("/calendar3")
	public String calendar3(HttpServletRequest request, Model model) throws Exception {
		return "navbar/calendar3";
	}

	@RequestMapping("/calendar4")
	public String calendar4(HttpServletRequest request, Model model) throws Exception {
		return "navbar/calendar4";
	}

	@RequestMapping(value = "/selectEventList2")
	@ResponseBody
	public List<CalendarDTO> selectEventList(CalendarDTO param) {
		// return calendarService.selectEventList(param);
	/*	System.out.println("곰돌이");
		List<CalendarDTO> list = new ArrayList<CalendarDTO>();
		for (int i = 0; i < 2; i++) {
			CalendarDTO dto = new CalendarDTO();
			dto.setEnddate("2021-09-25");
			dto.setStartdate("2021-09-25");
			dto.setSubject("곰돌이");
			list.add(dto);
		}
*/
		return null;
	}

	
	@RequestMapping("/calendar")
	public String calendar(HttpServletRequest request, Model model) throws Exception {
		return "navbar/calendar";
	}

	
	@ResponseBody
	@RequestMapping(value = "/addSchedule", method = RequestMethod.POST)
	public int addSchedule(CalendarDTO calendarDTO) throws Exception {
		return calendarService.addSchedule(calendarDTO);
	}

	
	@ResponseBody
	@RequestMapping(value = "/selectEventList")
	public List<CalendarDTO>  selectEventList(@RequestParam Map<String, Object> map) throws Exception {
		return calendarService.selectEventList(map);		
	}

	
	@ResponseBody
	@RequestMapping(value = "/getEvent")
	public CalendarDTO  getEvent(@RequestParam  Map<String, Object> map) throws Exception {
		return calendarService.getEvent(map);		
	}

	
	@ResponseBody
	@RequestMapping(value = "/deleteSch", method = RequestMethod.POST)
	public int deleteSch(CalendarDTO calendarDTO) throws Exception {
		return calendarService.deleteSch(calendarDTO);
	}
	
	@ResponseBody
	@RequestMapping(value = "/updateSch", method = RequestMethod.POST)
	public int updateSch(CalendarDTO calendarDTO) throws Exception {
		return calendarService.updateSch(calendarDTO);
	}
	
	
}

 

CalendarService

 

package com.gudi.calendar.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gudi.calendar.dao.CalendarDAO;
import com.gudi.calendar.dto.CalendarDTO;

@Service
public class CalendarService {

	@Autowired
	private CalendarDAO calendarDAO;
	
	public List<CalendarDTO> showSchedule() throws Exception {
		return calendarDAO.showSchedule();
	}
	
	public int addSchedule(CalendarDTO dto) throws Exception{
		return calendarDAO.addSchedule(dto);
	}

	public List<CalendarDTO> selectEventList(Map<String, Object> map) throws Exception{
		return calendarDAO.selectEventList(map);
	}

	public CalendarDTO getEvent(Map<String, Object> map) throws Exception{
		return calendarDAO.getEvent(map);
	}

	public int deleteSch(CalendarDTO calendarDTO) throws Exception{
		return calendarDAO.deleteSch(calendarDTO);
	}

	public int updateSch(CalendarDTO calendarDTO) throws Exception{
		return calendarDAO.updateSch(calendarDTO);
	}
	
	
}

 

CalendarDTO

public class CalendarDTO {
	
	private int scheduleId;
	private String scheduleName;
	private String startDate;
	private String endDate;
	
	private String id;
	private String title;
	private String start;
	private String end;
	private String color="#039be5";
	

}

 

 

CalendarDAO

 

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.gudi.calendar.dto.CalendarDTO;

@Repository
public interface CalendarDAO {

	public List<CalendarDTO> showSchedule() throws Exception;

	public int addSchedule(CalendarDTO dto) throws Exception;

	public List<CalendarDTO> selectEventList(Map<String, Object> map) throws Exception;

	public CalendarDTO getEvent(Map<String, Object> map) throws Exception;

	public int deleteSch(CalendarDTO calendarDTO) throws Exception;

	public int updateSch(CalendarDTO calendarDTO) throws Exception;

	
}

 

calendar_mapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- mapper 에 대한 선언 문 -->
<!DOCTYPE mapper PUBLIC
	"-//mybatis.org//DTD Mapper 3.0//EN"
	"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.gudi.calendar.dao.CalendarDAO">	
	

    	<select id="selectEventList" resultType="com.gudi.calendar.dto.CalendarDTO">
 			SELECT SCHEDULEID AS  "id" , SCHEDULENAME title ,  STARTDATE as "start" ,ENDDATE AS "end"  FROM CALENDAR 
    	</select>
    	
    	 <insert id="addSchedule" parameterType="com.gudi.calendar.dto.CalendarDTO">
	    	INSERT INTO CALENDAR (SCHEDULEID, SCHEDULENAME, STARTDATE, ENDDATE) VALUES(CALENDAR_SEQ.NEXTVAL, #{scheduleName}, #{startDate}, #{endDate})
    	</insert>
	
		<select id="getEvent" resultType="com.gudi.calendar.dto.CalendarDTO">
		  SELECT SCHEDULEID AS  "id" , SCHEDULENAME title ,  STARTDATE as "start" ,ENDDATE AS "end"  FROM CALENDAR WHERE  SCHEDULEID =#{id} 
		</select>
    
    	<delete id="deleteSch">
    		DELETE FROM CALENDAR WHERE  SCHEDULEID =#{id} 
    	</delete>
    	
    	<update id="updateSch">
    		UPDATE CALENDAR SET SCHEDULENAME= #{scheduleName}, STARTDATE=#{startDate}, ENDDATE=#{endDate} WHERE SCHEDULEID=#{scheduleId}    		
    	</update>
    	
</mapper>

 

 

calendar.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="path" value="${pageContext.request.contextPath}" />

<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>드론</title>

<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css">
<link href="${path}/resources/css/bootstrap.css" rel="stylesheet">

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css">	
<link href="${path}/resources/css/common.css?var=3" rel="stylesheet">
<!-- <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> -->
<script type="text/javascript" src="//cdn.jsdelivr.net/jquery/1/jquery.min.js"></script>

<script src="${path}/resources/js/common.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">


<script type="text/javascript" src="//cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<!-- <link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/bootstrap/3/css/bootstrap.css" /> -->
<!-- Include Date Range Picker -->
<script type="text/javascript" src="//cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.css" />

<link href='${path}/resources/fullcalendar-5.9.0/lib/main.css' rel='stylesheet' />
<script src='${path}/resources/fullcalendar-5.9.0/lib/moment.min.js'></script>
<script src='${path}/resources/fullcalendar-5.9.0/lib/main.js'></script>
<script src='https://cdn.jsdelivr.net/npm/fullcalendar@5.9.0/locales-all.min.js'></script>
<link href="${path}/resources/css/calendar.css?v=1" rel="stylesheet">
</head>

<body>
	<c:if test="${sessionScope.loginId eq null}">
		<jsp:include page="../fixmenu/navbar.jsp" />
	</c:if>
	<c:if test="${sessionScope.loginId ne null}">
		<jsp:include page="../fixmenu/lognav.jsp" />
	</c:if>

<!-- 들어갈 내용 -->
<nav style="--bs-breadcrumb-divider: url(&#34;data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Cpath d='M2.5 0L1 1.5 3.5 4 1 6.5 2.5 8l4-4-4-4z' fill='currentColor'/%3E%3C/svg%3E&#34;);" aria-label="breadcrumb">
  <ol class="breadcrumb">
    <li class="breadcrumb-item fs-4"><a href="${path}/">Home</a></li>
    <li class="breadcrumb-item active fs-4" aria-current="page">Map</li>
  </ol>
</nav>

	<div id='wrap'>
		<!-- calendar 태그 -->
		<div id='calendar-wrap'>
			<h1 style="display:none"><input type="text" id="currentDatePage"></h1>
			<div id='calendar'></div>			
		</div>
	</div>

<%@ include file="calendar_modal.jsp" %>


</body>
</html>

 

 

 

 

 

 

 

 

 

 

 

about author

PHRASE

Level 1  라이트

댓글 ( 0)

댓글 남기기

작성