Spring 에 MySQL, MyBaits 연동하기

 

- pom.xml에 MyBatis, MySQL, jdbc 라이브러리 추가 


    <!-- mybatis -->

<dependency>

<groupId>org.mybatis</groupId>

<artifactId>mybatis</artifactId>

<version>3.4.1</version>

</dependency>


<dependency>

<groupId>org.mybatis</groupId>

<artifactId>mybatis-spring</artifactId>

<version>1.3.0</version>

</dependency>

<!-- MySQL -->

<dependency>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

<version>6.0.5</version> 

   </dependency>

   

   <!-- spring jdbc -->

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-jdbc</artifactId>

<version>${org.springframework-version}</version>

</dependency>


<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-test</artifactId>

<version>${org.springframework-version}</version>

</dependency>


- root-context.xml namespace check



- root-context.xml 빈생성






하고 mybatis.comfig.xml 만들고 mapper만들고 dao연결 DB테스트 완료 

이제코딩 

이어서 ~ 



- MySQL monitor (Client) 


mysql -hlocalhost -uroot -p

실행 h서버주소 u관리자아이디 p비밀번호입력받아라

하나의 서버에 여러개의 데이터베이스가 존재할 수 있다. (보통 앱 하나당 데이터베이스 하나) 


- CUI 로 제어


Microsoft Windows [Version 10.0.15063]

(c) 2017 Microsoft Corporation. All rights reserved.


▶ C:\Users\USER>cd C:\Bitnami\wampstack-5.6.30-5\mysql\bin                  


▶ C:\Bitnami\wampstack-5.6.30-5\mysql\bin>mysql -hlocalhost -uroot -p      

Enter password: ******

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.6.36 MySQL Community Server (GPL)


Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


▶ mysql> show databases;                                                                      // 

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test               |

+--------------------+

4 rows in set (0.06 sec)


▶ mysql> CREATE DATABASE opentutorials CHARACTER SET utf8 COLLATE utf8_general_ci;

Query OK, 1 row affected (0.01 sec)


mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| opentutorials      |

| performance_schema |

| test               |

+--------------------+

5 rows in set (0.00 sec)


▶ mysql> use opentutorials;

Database changed

mysql>  CREATE TABLE `topic` (

    -> `id` int(11) NOT NULL AUTO_INCREMENT,

    ->   `title` varchar(100) NOT NULL,

    ->   `description` text NOT NULL,

    ->   `author` varchar(30) NOT NULL,

    ->   `created` datetime NOT NULL,

    ->   PRIMARY KEY (id)

    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Query OK, 0 rows affected (0.11 sec)


mysql> show tables;

+-------------------------+

| Tables_in_opentutorials |

+-------------------------+

| topic                   |

+-------------------------+

1 row in set (0.00 sec)





아아아. 생활코딩은 php로 연동하는구나 !!!! 난 jsp Java로 해야하니 여기서부턴 혼자해보자 ~~




- MySQL Client Tool로 workbench를 사용해봐야 겠다. MySql Monitor으로 user, database, table세팅. workbench 접속.


- Spring MySQL 연동 ( http://blog.naver.com/wlsgud2229/221008864277 참고)

  maven으로 mysql-connector-java-6.5.0.jar 생성했는데 driver오류 발생한다. 

  내일 xml, 에서 바로연결하는 걸로 해보거나 maven 다시 확인해보자 





기본 페이지 처리는 했으니 데이터베이스가 필요하다. 이번엔 생활코딩의 도움을 받아 MySQL을 사용해봐야겠다. 


( 생활코딩 영상 캡쳐 https://opentutorials.org/course/1688/9386 ) 



- Server 와 MySQL 그리고 CGI(Common Gateway Interface)

  웹브라우저 - 웹서버 - PHP - MySQL : 데이터 베이스도 클라이언트와 서버의 관계를 갖고 있다. (그래서 Oracle Client를 그렇게 설치했구나..) 

                                                  (Client) (Server)

  (http://blog.naver.com/wonwoo9276/220979297783 참고) 

  db Client는 db Server와 다른 컴퓨터에 존재해도 상관없다(그렇게써왓지)


- 웹서버 설치(https://opentutorials.org/course/1688/9337) :

   bitnami (MySQL, PHP, Apache) 

 

- localhost/index.html  

  localhost 는 웹브라우저가 설치되어있는 컴퓨터의 웹서버를 가르키는 주소. (웹서버주소!!)

  (내가 spring 테스트 할때 http://localhost:8081/ 는 포터블 아파치가 잡아준 거구나. 포트 8081쓰니까 ㅎ ) 


- Document Root[웹서버가 찾는문서의 최상위 디렉토리] : htdocs 변경가능



- 여개모 모각코를 2번 참여했다. 시작이라 그런지 내 속도가 매우 더디다. 시간에 대한 압박 없이, 스트레스 없이 개발해보고 싶어서 참여한 거긴 하지만 3개월 이라는 기간을 두고 부족하게 나마 완성 시켜보고 싶다. 때문에 평일에 남는 시간을 통해 부족한 부분을 채워야 겠다. 현재는 Spring Framework를 설치하고 프로젝트를 세팅하고 패키지를 나누고 페이지 처리를 진행중 이다


- @Inject

    private MemberService MemberService; 

아래의 한줄을 추가한 순간 MemberContoller의 빈을 찾을수 없다고 서버 에러가 뜬다. 스프링을 처음 접했을때 많이 봤던 에러 인데 또 뭐가 문제지 하는 것 보면 스프링 프레임워크의 의존성 주입 어노테이션 에 대한 개념이 부족한것 같다. 

: 하하하하하 ServiceImpl에 Service annotation이 빠져있었다. 


- memberJoin 페이지이동시에는 Url 이 http://localhost:8081/member/memberJoin 

  회원가입 버튼 클릭시에는 http://localhost:8081/member/member/memberJoin 로 member가 한번더 붙는다.

  get, post 만다를 뿐 같은 uri를 쓰는데 어디서 잘못된 것인가 

: "redirect:/member/memberJoin" 을 사용하여 처리 하였지만 왜 때문인가 ? 


- form submit 말고 jquery로 넘기려 cdn방식으로 라이브러리 를 연결하고 나서 코드를 보니 

 $(document).ready(function(){

 });

 는 안되고 축약형인

 $(function(){

 });

 이 형태로 해야 된다. 이유가 무엇일까. 문서가 준비 되었다는 함수인대 


-  html5 , java 한글인코딩 


- spring이 처음도 아닌대 이렇게 부족할수가 있나 싶었지만 그만큼 잊었던 부분을 다시 잘 채워 가야겠다  ~ 

+ Recent posts