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 | 29 | 30 |
Tags
- SQLite
- swift
- webflux
- Spring
- spring boot
- javadoc
- jquery
- Apache
- JavaFX
- Eclipse
- Linux
- maven
- build tool
- 외국인 노동자
- php
- bootstrap
- Python
- node.js
- Ajax
- pdo
- angularjs
- RSocket
- Java
- SQL
- 일본
- 개발자 이야기
- WebClient
- xml
- gradle
- mybatis
- Today
- 123
- Total
- 3,697,220
슬기로운 개발자 생활
[MyBatis] 변경 UPDATE 본문
반응형
변경전 DB 테이블
test_table
id | value |
---|---|
1 | hoge |
2 | fuga |
3 | piyo |
소스코드
TestTable.java
package sample.mybatis;
public class TestTable {
private int id;
private String value;
public TestTable(int id, String value) {
this.id = id;
this.value = value;
}
}
sample_mapper.xml
<?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="sample.mybatis">
<update id="updateTest">
update test_table
set value = #{value}
where id = #{id}
</update>
</mapper>
Main.java
package sample.mybatis;
import java.io.InputStream;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
public class Main {
public static void main(String[] args) throws Exception {
try (InputStream in = Main.class.getResourceAsStream("/mybatis-config.xml")) {
SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(in);
try (SqlSession session = factory.openSession()) {
TestTable table = new TestTable(1, "update");
session.insert("sample.mybatis.updateTest", table);
session.commit();
}
}
}
}
실행 결과
[DEBUG] s.m.updateTest - ==> Preparing: update test_table set value = ? where id = ?
[DEBUG] s.m.updateTest - ==> Parameters: update(String), 1(Integer)
[DEBUG] s.m.updateTest - <== Updates: 1
test_table
id | value |
---|---|
1 | update |
2 | fuga |
3 | piyo |
설명
- <update> 태그로 UPDATE을 정의할 수 있다.
반응형
'IT 개발 > MyBatis' 카테고리의 다른 글
[MyBatis] 배치(batch) 갱신 (0) | 2017.12.31 |
---|---|
[MyBatis] 삭제 DELETE (0) | 2017.12.31 |
[MyBatis] 등록 INSERT (1) | 2017.12.31 |
[MyBatis] 검색 결과를 임의의 Java 오브젝트에 매핑 (0) | 2017.12.31 |
[MyBatis] 검색 SELECT (0) | 2017.12.31 |
- Tag
- mybatis
0 Comments