Skip to content

Commit 731df64

Browse files
committed
added the Using MyBatis API chapter
1 parent a3ddbf0 commit 731df64

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/docbkx/index.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@
4747
<xi:include href="bootstrap.xml" />
4848
<xi:include href="templates_support.xml" />
4949
<xi:include href="mappers.xml" />
50+
<xi:include href="using_api.xml" />
5051

5152
</book>

src/docbkx/using_api.xml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
3+
<!--
4+
Copyright 2010 The myBatis Team
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
19+
<!--
20+
version: $Id$
21+
-->
22+
<chapter id="using_api">
23+
<title>Using MyBatis API</title>
24+
25+
<section id="using_api.main">
26+
<title>Using MyBatis API</title>
27+
<para>
28+
You can also use directly MyBatis API. In this case you won't have any MyBatis-Spring Dependency and you
29+
simply use a injected <literal>SqlSessionFactory</literal> on your DAOs:
30+
<programlisting language="java"><![CDATA[public class UserMapperSqlSessionImpl implements UserMapper {
31+
32+
private SqlSessionFactory sqlSessionFactory;
33+
34+
public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
35+
this.sqlSessionFactory = sqlSessionFactory;
36+
}
37+
38+
public User getUser(String userId) {
39+
SqlSession session = sqlSessionFactory.openSession();
40+
User user = (User) session.selectOne("sample.UserMapper.getUser", userId);
41+
session.close();
42+
return user;
43+
}
44+
45+
}]]></programlisting>
46+
This scenario also supports transaction but ther will be no exception translation.
47+
</para>
48+
</section>
49+
50+
</chapter>

0 commit comments

Comments
 (0)