java 11을 → 1.8로 바꿔줘서 오류해결 :

preference - java complier → 1.8

먼저 MySQL 세팅

create user 'springblog'@'%' identified by 'bitc5600';
GRANT ALL PRIVILEGES ON *.* TO 'springblog'@'%';
create database springblog;
use springblog;
CREATE TABLE user(
   id int auto_increment primary key,
    username varchar(100) unique not null,
    password varchar(100) not null,
    email varchar(100),
    profile varchar(200),
    role varchar(20),
    createDate timestamp
) engine=InnoDB default charset=utf8;

CREATE TABLE post(
   id int auto_increment primary key,
    title varchar(100) not null,
    content longtext,
    userId int,
    createDate timestamp,
    foreign key (userId) references user (id) on delete set null
) engine=InnoDB default charset=utf8;

CREATE TABLE comment(
   id int auto_increment primary key,
    userId int,
    postId int,
    content varchar(300) not null,
    createDate timestamp,
    foreign key (userId) references user (id) on delete set null,
    foreign key (postId) references post (id) on delete cascade
) engine=InnoDB default charset=utf8;

그리고 application.yml을 설정 안해주면 오류생김 : 오류해결 모두 해결!

// application.yml

server:
  port: 8080
  servlet:
   context-path: /
   
spring:
  mvc:
    view:
      prefix: /WEB-INF/
      suffix: .jsp
      
  datasource:
    url: jdbc:mysql://localhost:3306/springblog?serverTimezone=Asia/Seoul
    username: springblog
    password: bitc5600
    driver-class-name: com.mysql.cj.jdbc.Driver

config 생성

package com.cos.baseball2.config;

import javax.sql.DataSource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

@Configuration
@MapperScan(basePackages = "com.cos.springblog.repository")
public class DataAccessConfig {

    @Bean
    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {

        SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();

        sessionFactory.setDataSource(dataSource);
        sessionFactory.setMapperLocations(
        		new PathMatchingResourcePatternResolver().getResources("classpath:mapper/*.xml"));
        return sessionFactory.getObject();
    }

    @Bean
    public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
        return new SqlSessionTemplate(sqlSessionFactory);
    }
}