pooney
article thumbnail
Spring mybatis 값에 따른 쿼리 실행
Spring 2020. 5. 9. 18:11

mybatis를 통해 주어진 값에 따라 다르게 실행 할 수 있는 방법이 존재한다 대표적으로 , 이다 태그 사용 controller @Controller public class HomeController { @Inject SqlSession sqlSession; @RequestMapping(value = "pooney", method = RequestMethod.GET) public String pooney(@RequestParam String id) { System.out.println("id : "+ id); List list = sqlSession.selectList("list.selectlist" ,id); System.out.println(list); return "index"; } } xml w..

article thumbnail
Spring mybatis 단일파라미터 전송시 no getter 에러
Spring 2020. 5. 9. 17:00

흔히 조건절은 , 태그가 대표적으로 존재한다. 단일 파라미터를 던져서 값에 따라 다르게 실행 시키고 싶은데 이때 when절에서 변수명을 잘못하여 getter 에러를 발생시키는 실수가 발생한다. getter 에러 발생 controller @Controller public class HomeController { @Inject SqlSession sqlSession; @RequestMapping(value = "pooney", method = RequestMethod.GET) public String pooney(@RequestParam String id) { System.out.println("id : "+ id); List list = sqlSession.selectList("list.selectlist..

article thumbnail
Spring mybatis resultMap
Spring 2020. 5. 7. 03:30

resultMap 태그는 일반적으로 DTO클래스의 변수명과 DB 테이블의 필드명이 서로 일치 하지 않을 경우 사용한다 resultMap = (멤버변수 변수명 != DB테이블의 필드명) resultMap 사용법 controller @Controller public class HomeController { @Inject SqlSession sqlSession; @RequestMapping(value = "addlist", method = RequestMethod.GET) public String addlist() { System.out.println("addlist"); List list = sqlSession.selectList("list.selectlist"); System.out.println(list..

article thumbnail
Spring mybatis를 통해 객체 안에있는 객체에 값 넣기
Spring 2020. 5. 7. 03:14

객체 안에 있는 콜렉션이나 객체에 값을 넣어야하는 경우가 발생한다 이때 mybatis의 collection 태그를 이용하여 해결 할 수 있다. collection 태그 controller @Controller public class HomeController { @Inject SqlSession sqlSession; @RequestMapping(value = "addlist", method = RequestMethod.GET) public String addlist() { System.out.println("addlist"); List list = sqlSession.selectList("list.selectlist"); System.out.println(list); return "index"; } } ..

Spring Cannot create PoolableConnectionFactory 에러
Spring 2020. 5. 6. 02:26

아래 에러는 jdbc 사용 시 db연결이 제대로 이루어지 않았기 때문이다 그럼으로 인하여 커넥션 풀이 제대로 만들어 지지 않았기 때문이다. 이를 해결하기 위해서는 time zone 설정을 하면 해결 할 수 있다. ### Error querying database. Cause: java.sql.SQLException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.) ### The error may exist in memo/mapper/memo.xml ### The error may involve memo.list ### Th..

article thumbnail
mysql 3개 테이블 조인
SQL 2020. 5. 6. 00:58

3개의 테이블 조인은 일반적인 inner join 과 outer join을 이용 할 수 있다 inner join inner join은 같은 컬럼 값을 가질 경우 조인이 가능하다 그렇지 않은 경우 조인 되지 않는다. test1 test2 test3 inner join SELECT * FROM test1 INNER JOIN test2 ON test1.b = test2.b INNER JOIN test3 ON test2.b = test3.b inner join 수행 결과 outter join outter join은 left join 과 right join 두가지 방법이 존재한다 left , right는 어느 테이블을 기준으로 조인을 할 것 인지를 정하는 것으로 left의 경우 왼쪽기준 right의 경우 오른쪽 ..

Spring Mapped Statements collection does not contain value for 에러
Spring 2020. 5. 5. 02:57

아래 와 같은 Mybatis에러는 보통 mapper의 id값을 잘못 입력했을 경우 발생하는 에러로 id값을 다시한번 확인하여 제대로 입력이 되었는 지 확인 해야한다. ### Error updating database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for team.insertteamapply ### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for team.insertteamapply]을(를) 발생시켰습니다. java.lang.IllegalA..

Spring mybatis 쿼리 리턴 유형
Spring 2020. 5. 5. 02:49

select select한 결과를 리턴한다 insert 1 or 여러개 를 insert 한경우 1을 리턴한다 update update 한 개수 만큼 값을 리턴한다 만약 존재 하지 않으면 0을 리턴 delete delete 한 개수 만큼 값을 리턴한다 만약 존재 하지 않으면 0을 리턴한다