MyEclipse does not provide automatic generation, where mybatis packages and development documentation are provided http://download.csdn.net/detail/u010026901/7489319
Set up your own configuration file,
<?xml version= "1.0" encoding= "UTF-8"?> <!
DOCTYPE configuration Public
"-//mybatis.org//dtd Config 3.0//en"
"http://mybatis.org/dtd/ Mybatis-3-config.dtd ">
<configuration>
<environments default=" Development ">
< Environment id= "Development" >
<transactionmanager type= "JDBC" /> <datasource type=
"Pooled" ">
<property name=" Driver "value=" Oracle.jdbc.driver.OracleDriver "/> <property name=
" URL "value=" Jdbc:oracle:thin:@192.168.2.55:orcl " />
<property name=" username "value=" Ysk " >
<property name= "password" value= "123" />
</dataSource>
</environment>
</environments>
<mappers>
<!--The daoimpl,mybatis that fills out DAO interface mappings is not the mapping Pojo (VO) class, but the DAO class-- >
<mapper resource= "Com/kane/dao/newsdaoimpl.xml" />
</mappers>
</ Configuration>
Configure the linked Sqlsessionfactory class yourself, equivalent to a hibernate sessionfactory corresponding to a database
Package COM.KANE.DBC;
Import Java.io.InputStream;
Import org.apache.ibatis.io.Resources;
Import org.apache.ibatis.session.SqlSession;
Import Org.apache.ibatis.session.SqlSessionFactory;
Import Org.apache.ibatis.session.SqlSessionFactoryBuilder; public class Mybatissqlsessionfactory {//configuration file location and name private static String config_file_location = "Mybatis-co
Nf.xml ";
Used to implement connection pooling, this class is similar to a map collection.
private static final threadlocal<sqlsession> ThreadLocal = new threadlocal<sqlsession> ();
MyBatis class private static inputstream is used to read configuration files;
Used to establish a connection, this class is the connection pool, using a single case design mode private static Sqlsessionfactory sqlsessionfactory;
Alternate configuration file location private static String configfile = Config_file_location; Static block, which executes the first static {try {///load configuration file into memory with the. = = Resources.getresourceasstream (configfile),//build connection pool and the inside connection SQLSESSIONFAC
Tory = new Sqlsessionfactorybuilder (). Build (IS); catch (Exception e) {System.err.println ("%%%% Error creating SessionfactOry%%%% ");
E.printstacktrace (); The private Mybatissqlsessionfactory () {}/** * Gets the database connection object * * @return session * @throws Hibernateexc
Eption/public static sqlsession getsession () {//Get the connection from Threadlocal first.
sqlsession session = (sqlsession) threadlocal.get ();
Threadlocal.set (session);
return to session; /** * Connection Shutdown method * * @throws hibernateexception/public static void CloseSession () {sqlsession session = (SQL
session) Threadlocal.get ();
Empties the threadlocal to indicate that the current thread is no longer connected.
Threadlocal.set (NULL);
Connection back to Connection pool if (session!= null) {Session.close ();}} }
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/Java/