Spring/Spring icia 44일차

IntelliJ와 MySQL 연동

swkn 2023. 4. 25. 18:45
create user user_springframework identified by "1234";
create database db_springframework;
grant all privileges on db_springframework.* to user_springframework;

root-context 복붙

<property name="url" value="jdbc:mysql://localhost:3306/db_springframework?useSSL=false&amp;serverTimezone=Asia/Seoul" />
<property name="username" value="user_springframework"/>
<property name="password" value="1234"/> 

데이터베이스 이름 수정

이름 value 수정

비밀번호  value 수정

 

 

<!-- 현재 프로젝트 패키지 경로 맞는지 확인 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value ="classpath:/mybatis-config.xml" />
<property name="mapperLocations" value="classpath:/mapper/*.xml" />
</bean>

에러 해결을 위해 resources에 mybatis-config.xml 파일 생성 후 배포파일에서 복붙

mapper 폴더 만든후에 book-mapper.xml 생성후 배포파일에서 복붙

 

create user user_springframework identified by "1234";
create database db_springframework;
grant all privileges on db_springframework.* to user_springframework;

계정 만든후에 데이터베이스 만들고 권한을 부여한다

-- book 정보를 저장할 테이블 생성
-- DTO를 참고하여 만들어보기
-- id는 auto_increament 적용
drop table if exists book_table;
create table book_table (
	id bigint auto_increment primary key,
    bookName varchar(200) not null,
    bookPublisher varchar(200),
    bookAuthor varchar(200),
    bookPrice int
    );
    
insert into book_table (bookName,bookPublisher,bookAuthor,bookPrice)
	value ("모든삶은 흐른다","FIKA","로랑스드빌레르",15120);
insert into book_table (bookName,bookPublisher,bookAuthor,bookPrice)
	value ("나는 행복할수 있는가","미디어숲","장재형",16020);
    
select * from book_table;