Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- javaservlet
- JPA
- 스프링데이터흐름
- Hibernate
- jQuery값전달
- jQuery값전송
- 벌크연산
- jQueryUI
- 자바서블릿
- LIST
- JPQL
- joinfetch
- fetchjoin
- namedQuery
- 페치조인
- 엔티티직접사용
- JQuery
- jscalendar
- 제네릭
- 대량쿼리
- fullcalendar
- javascriptcalendar
- springflow
- paging
- 제너릭
- 페이징
- 프로젝트생성
- values()
- calendar
- Generic
Archives
- Today
- Total
가자공부하러!
Maria DB - DB 생성, 테이블 생성, Spring Boot 연동 본문
소스코드 : https://github.com/HyeongJunMin/springboot/tree/master/MariaDBExam
설치방법 : https://dotheright.tistory.com/102?category=790771
개발환경 : MariaDB(10.2.14), Connector(2.2.3)
참고페이지 : https://taetaetae.github.io/2019/04/21/spring-boot-mybatis-mysql-xml/
1. DB 생성
1. HeidiSQL
> DB 생성 : 좌측 빈곳에 오른클릭 -> 새로 생성 -> 데이터베이스 -> 이름입력 -> 확인
> 사용자 생성 : DB클릭(선택) -> 상단 사람모양 아이콘 클릭 -> 추가
> 생성한 사용자로 접속 : 좌측 세션관리자표시 클릭 -> 신규 -> 사용자/암호 입력
2. Spring Boot 연동
1. pom.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <!-- DB관련, boot mybatis랑 mysql-connector만 위에 있음 --> <!-- H2 for oracle db connection --> <!-- https://mvnrepository.com/artifact/com.h2database/h2 --> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>com.zaxxer</groupId> <artifactId>HikariCP</artifactId> </dependency> <!-- maria db 관련 디펜던시 --> <dependency> <groupId>org.mariadb.jdbc</groupId> <artifactId>mariadb-java-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> | cs |
2. application.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #Maria DB Exam Project server: port: 18088 #JSP config servlet: jsp: init-parameters: development: true #custume error page error: whitelabel: enabled: false #db config spring: mvc: view: prefix: /WEB-INF/views/ suffix: .jsp datasource: hikari: jdbc-url: jdbc:mysql://localhost:3306/bmarket?characterEncoding=UTF-8&serverTimezone=UTC pool-name: hikari-cp maximum-pool-size: 30 minimum-idle: 2 driver-class-name: com.mysql.cj.jdbc.Driver username: password: | cs |
3. MariaDBConfiguration.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | package com.mde.config; import javax.sql.DataSource; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.SqlSessionTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; @Configuration @PropertySource("classpath:/application.yml") public class MariaDBConfiguration { @Bean @ConfigurationProperties(prefix = "spring.datasource.hikari") public HikariConfig hikariConfig() { return new HikariConfig(); } @Bean public DataSource dataSource() { DataSource dataSource = new HikariDataSource(hikariConfig()); return dataSource; } @Autowired private ApplicationContext applicationContext; @Bean public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception { SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setDataSource(dataSource); sqlSessionFactoryBean.setMapperLocations(applicationContext.getResources("classpath:/mapper/**/*.xml")); return sqlSessionFactoryBean.getObject(); } @Bean public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) { return new SqlSessionTemplate(sqlSessionFactory); } } | cs |
4. TestMapper.xml
1 2 3 4 5 6 7 8 | <?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.mde.app.common.dao"> --> <mapper namespace="common"> <select id="getList" resultType="com.mde.app.common.model.TestDTO"> SELECT * FROM MEMBER_MHJ </select> </mapper> | cs |
5. 프로젝트 구조
3. 문제해결
'공부 > DB' 카테고리의 다른 글
H2 DB (0) | 2019.11.29 |
---|---|
Mac OS에서 Maria DB 활용 방법 - 설치, 실행, 계정생성, 접속 (0) | 2019.11.19 |
Maria DB 쿼리 모음(페이징, 날짜 등) (0) | 2019.09.26 |
2. Oracle DB - java 연동 예제(eclipse) (0) | 2019.05.31 |
1. DB설치, 개발환경 구축 (Oracle DB, Maria DB) (0) | 2019.05.29 |
Comments