* Eclipse Spring 프로젝트 생성 및 초기 개발환경 구축하는 방법 참고
항목 | 내용 |
---|---|
Language | Java 11 |
Backend IDE | Eclipse 2023-12 |
Spring | 5.3.36 |
Tomcat | 9.0.105 |
DataBase | MySQL 8.0.33 (MyBatis 3.5.15) |
Build Tool | Maven 3.8.x (설정파일 : pom.xml) |
Frontend IDE | VSCode |
Vue.js | 3.16.4 |
CREATE DATABASE vue_calendar CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
USE vue_calendar;
DROP TABLE schedule;
CREATE TABLE schedule (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL
);
INSERT INTO schedule
(title)
VALUES
('제목1');
select
id as id,
title as title
from
schedule;
package com.calendarapp.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.calendarapp.service.ScheduleService;
import com.calendarapp.vo.Schedule;
@RestController
@RequestMapping("/api/schedules")
public class ScheduleController {
@Autowired
private ScheduleService scheduleService;
@GetMapping
public List<Schedule> getSchedules() {
return scheduleService.getSchedules();
}
}
package com.calendarapp.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.calendarapp.mapper.ScheduleMapper;
import com.calendarapp.vo.Schedule;
@Service
public class ScheduleService {
@Autowired
private ScheduleMapper scheduleMapper;
public List<Schedule> getSchedules() {
return scheduleMapper.getSchedules();
}
}
package com.calendarapp.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import com.calendarapp.vo.Schedule;
@Mapper
public interface ScheduleMapper {
List<Schedule> getSchedules();
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.calendarapp.mapper.ScheduleMapper">
<select id="getSchedules" resultType="com.calendarapp.vo.Schedule">
select
id as id,
title as title
from
schedule
</select>
</mapper>
package com.calendarapp.vo;
public class Schedule {
private int id;
private String title;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
* Spring + Vue.js 연동까지 구현해보기 :
https://velog.io/@ryuneng2/SpringVue.js-스프링-Vue.js-연동-및-DB-조회-간단-구현