ibatis使用方法

article/2025/9/13 8:48:09

转载。怕原地址丢失,备份。。



http://lyb520320.iteye.com/blog/586628

http://lyb520320.iteye.com/blog/586800


iBATIS3.0学习(一)使用iBATIS3.0完成增删改查

  • 博客分类:
  • iBATIS3
iBATIS Apache Spring SQL JDBC

 使用iBATIS3.0完成增删改查

    iBATIS3.0和以前的版本有一些改变,不过学过以前版本的再学习3.0应该不是太难,3.0要求JDK1.5支持,因为其中增加了注解和泛型,这些都是JDK1.5才有的。好了废话不多说,先来利用iBATIS3做下简单的增删改查吧。

    首先到Apache(http://www.apache.org/)网站下载iBATIS3的jar 包,我下载的是ibatis-3-core-3.0.0.227.zip,解压后吧那个jar文件(ibatis-3-core-3.0.0.227.jar)添加到工程就可以了,还有一个文件(ibatis-3-core-src-3.0.0.227.zip)是源代码,可以用来查看源代码的,使用eclipse可以用它来关联源代码。

    在MyEclipse新建一个Java Project,结构如下图

    在jdbc.properties文件是映射文件要使用的,其内容如下:

 

Properties代码   收藏代码
  1. driver=com.mysql.jdbc.Driver  
  2. url=jdbc\:mysql\://localhost\:3306/test  
  3. username=root  
  4. password=123456  

 SqlMapper.xml是iBATIS的配置文件,其代码如下:

Xml代码   收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE configuration  
  3. PUBLIC "-//ibatis.apache.org//DTD Config 3.0//EN"  
  4. "http://ibatis.apache.org/dtd/ibatis-3-config.dtd">  
  5. <configuration>  
  6.     <properties resource="jdbc.properties"/>  
  7.     <typeAliases>  
  8.         <typeAlias type="cn.ibatis3.test.Person" alias="Person"/>  
  9.     </typeAliases>  
  10.     <environments default="development">  
  11.         <environment id="development">  
  12.             <transactionManager type="JDBC"/>  
  13.             <dataSource type="POOLED">  
  14.                 <property name="driver" value="${driver}"/>  
  15.                 <property name="url" value="${url}"/>  
  16.                 <property name="username" value="${username}"/>  
  17.                 <property name="password" value="${password}"/>  
  18.             </dataSource>  
  19.         </environment>  
  20.     </environments>  
  21.     <mappers>  
  22.         <mapper resource="cn/ibatis3/test/person.xml"/>  
  23.     </mappers>  
  24. </configuration>  

 上面文件中的sql映射文件person.xml代码如下:

Xml代码   收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE mapper  
  3. PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"  
  4. "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">  
  5. <!--  -->  
  6.   
  7. <mapper namespace="cn.ibatis3.test.PersonMapper">  
  8.   
  9.     <select id="selectPerson" parameterType="java.lang.Integer"  
  10.         resultType="Person">  
  11.         select * from person where id = #{id}  
  12.     </select>  
  13.     <select id="selectAll" resultType="Person">  
  14.         select * from person  
  15.     </select>  
  16.     <select id="selectPersonsByName" resultType="Person" parameterType="String">  
  17.         select * from person where name like #{name}  
  18.     </select>  
  19.     <insert id="insertPerson" parameterType="Person">  
  20.         insert into person(name,birthday,sex)  
  21.         values(#{name},#{birthday},#{sex})  
  22.     </insert>  
  23.     <delete id="deletePerson" parameterType="Person">  
  24.         delete from person where id=#{id}  
  25.     </delete>  
  26.     <update id="updatePerson" parameterType="Person">  
  27.         update person set name=#{name},birthday=#{birthday},sex=#{sex}  
  28.         where id=#{id}  
  29.     </update>  
  30. </mapper>  

     注意:在iBATIS3中,属性parameterMap是不推荐使用的,在以后的版本可能会去掉这个属性。

     Person.java的代码如下:

Java代码   收藏代码
  1. package cn.ibatis3.test;  
  2.   
  3. import java.util.Date;  
  4.   
  5. public class Person {  
  6.     private int id = 0;  
  7.     private String name = "";  
  8.     private String sex = "male";  
  9.     private Date birthday = null;  
  10.   
  11.     public Person() {  
  12.   
  13.     }  
  14.   
  15.     //省略getter 和 setter 方法  
  16.       
  17.     @Override  
  18.     public String toString() {  
  19.         return "id=" + id + "\t" + "name=" + name + "\t" + "sex=" + sex + "\t"  
  20.                 + "birthday=" + new java.sql.Date(birthday.getTime()).toString();  
  21.     }  
  22.   
  23. }  
package cn.ibatis3.test;import java.util.Date;public class Person {private int id = 0;private String name = "";private String sex = "male";private Date birthday = null;public Person() {}//省略getter 和 setter 方法@Overridepublic String toString() {return "id=" + id + "\t" + "name=" + name + "\t" + "sex=" + sex + "\t"+ "birthday=" + new java.sql.Date(birthday.getTime()).toString();}}

    iBATIS官方推荐我们使用单例模式创建一个sessionFactory,我这里也提供一个sessionFactory.java,呵呵,仅供参考:

Java代码   收藏代码
  1. package cn.ibatis3.test;  
  2.   
  3. import java.io.IOException;  
  4. import java.io.Reader;  
  5.   
  6. import org.apache.ibatis.io.Resources;  
  7. import org.apache.ibatis.session.SqlSessionFactory;  
  8. import org.apache.ibatis.session.SqlSessionFactoryBuilder;  
  9.   
  10. public final class SessionFactory {  
  11.     private String resource="cn/ibatis3/test/SqlMapper.xml";  
  12.     private SqlSessionFactory sqlSessionFactory=null;  
  13.     private static SessionFactory sessionFactory=new SessionFactory();  
  14.       
  15.     private SessionFactory() {  
  16.         try {  
  17.             Reader reader=Resources.getResourceAsReader(resource);  
  18.             sqlSessionFactory=new SqlSessionFactoryBuilder().build(reader);  
  19.         } catch (IOException e) {  
  20.             System.out.println("#IOException happened in initialising the SessionFactory:"+e.getMessage());  
  21.             throw new ExceptionInInitializerError(e);  
  22.         }  
  23.     }  
  24.     public static SessionFactory getInstance() {  
  25.         return sessionFactory;  
  26.     }  
  27.     public SqlSessionFactory getSqlSessionFactory() {  
  28.         return sqlSessionFactory;  
  29.     }  
  30.   
  31. }  
package cn.ibatis3.test;import java.io.IOException;
import java.io.Reader;import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;public final class SessionFactory {private String resource="cn/ibatis3/test/SqlMapper.xml";private SqlSessionFactory sqlSessionFactory=null;private static SessionFactory sessionFactory=new SessionFactory();private SessionFactory() {try {Reader reader=Resources.getResourceAsReader(resource);sqlSessionFactory=new SqlSessionFactoryBuilder().build(reader);} catch (IOException e) {System.out.println("#IOException happened in initialising the SessionFactory:"+e.getMessage());throw new ExceptionInInitializerError(e);}}public static SessionFactory getInstance() {return sessionFactory;}public SqlSessionFactory getSqlSessionFactory() {return sqlSessionFactory;}}

 

    基于接口的编程(还有就是iBATIS3的注解也是在接口方法上的,关于注解以后有机会再讲,它也是iBATIS3的一个新特性),DAO层的接口PersonMapper.java代码如下:

Java代码   收藏代码
  1. package cn.ibatis3.test;  
  2.   
  3. import java.util.List;  
  4.   
  5. public interface PersonMapper {  
  6.     Person selectById(Integer id);  
  7.     List<Person> selectAll();  
  8.     List<Person> selectPersonsByName(String name);  
  9.     void insert(Person person);  
  10.     void delete(Person person);  
  11.     void update(Person person);  
  12.       
  13. }  
package cn.ibatis3.test;import java.util.List;public interface PersonMapper {Person selectById(Integer id);List<Person> selectAll();List<Person> selectPersonsByName(String name);void insert(Person person);void delete(Person person);void update(Person person);}

 接口的实现类PersonDao.java代码如下:

Java代码   收藏代码
  1. package cn.ibatis3.test;  
  2.   
  3. import java.util.ArrayList;  
  4. import java.util.List;  
  5.   
  6. import org.apache.ibatis.session.SqlSession;  
  7. import org.apache.ibatis.session.SqlSessionFactory;  
  8.   
  9. public class PersonDao implements PersonMapper {  
  10.     private SqlSessionFactory sessionFactory = SessionFactory.getInstance()  
  11.             .getSqlSessionFactory();  
  12.   
  13.     public Person selectById(Integer id) {  
  14.         Person person = new Person();  
  15.         SqlSession session = null;  
  16.         try {  
  17.             session = sessionFactory.openSession();  
  18.             person = (Person) session.selectOne(  
  19.                     "cn.ibatis3.test.PersonMapper.selectPerson", id);  
  20.         } finally {  
  21.             session.close();  
  22.         }  
  23.         return person;  
  24.     }  
  25.   
  26.     @SuppressWarnings("unchecked")  
  27.     public List<Person> selectAll() {  
  28.         List<Person> persons = new ArrayList<Person>();  
  29.         SqlSession session = null;  
  30.         try {  
  31.             session = sessionFactory.openSession();  
  32.             persons = session  
  33.                     .selectList("cn.ibatis3.test.PersonMapper.selectAll");  
  34.         } finally {  
  35.             session.close();  
  36.         }  
  37.   
  38.         return persons;  
  39.     }  
  40.   
  41.     public void delete(Person person) {  
  42.         SqlSession session = null;  
  43.         try {  
  44.             session = sessionFactory.openSession();  
  45.             session.delete("cn.ibatis3.test.PersonMapper.deletePerson", person);  
  46.             session.commit();  
  47.         } finally {  
  48.             session.close();  
  49.         }  
  50.   
  51.     }  
  52.   
  53.     public void insert(Person person) {  
  54.         SqlSession session = null;  
  55.         try {  
  56.             session = sessionFactory.openSession();  
  57.             session.insert("cn.ibatis3.test.PersonMapper.insertPerson", person);  
  58.             session.commit();  
  59.         } finally {  
  60.             session.close();  
  61.         }  
  62.   
  63.     }  
  64.   
  65.     public void update(Person person) {  
  66.         SqlSession session = null;  
  67.         try {  
  68.             session = sessionFactory.openSession();  
  69.             session.insert("cn.ibatis3.test.PersonMapper.updatePerson", person);  
  70.             session.commit();  
  71.         } finally {  
  72.             session.close();  
  73.         }  
  74.   
  75.     }  
  76.   
  77.     @SuppressWarnings("unchecked")  
  78.     public List<Person> selectPersonsByName(String name) {  
  79.         List<Person> persons = new ArrayList<Person>();  
  80.         SqlSession session = null;  
  81.         try {  
  82.             session = sessionFactory.openSession();  
  83.             System.out.println(name);  
  84.             persons = session.selectList(  
  85.                     "cn.ibatis3.test.PersonMapper.selectPersonsByName""%"  
  86.                             + name + "%");  
  87.             session.commit();  
  88.         } finally {  
  89.             session.close();  
  90.         }  
  91.   
  92.         return persons;  
  93.     }  
  94.   
  95. }  
package cn.ibatis3.test;import java.util.ArrayList;
import java.util.List;import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;public class PersonDao implements PersonMapper {private SqlSessionFactory sessionFactory = SessionFactory.getInstance().getSqlSessionFactory();public Person selectById(Integer id) {Person person = new Person();SqlSession session = null;try {session = sessionFactory.openSession();person = (Person) session.selectOne("cn.ibatis3.test.PersonMapper.selectPerson", id);} finally {session.close();}return person;}@SuppressWarnings("unchecked")public List<Person> selectAll() {List<Person> persons = new ArrayList<Person>();SqlSession session = null;try {session = sessionFactory.openSession();persons = session.selectList("cn.ibatis3.test.PersonMapper.selectAll");} finally {session.close();}return persons;}public void delete(Person person) {SqlSession session = null;try {session = sessionFactory.openSession();session.delete("cn.ibatis3.test.PersonMapper.deletePerson", person);session.commit();} finally {session.close();}}public void insert(Person person) {SqlSession session = null;try {session = sessionFactory.openSession();session.insert("cn.ibatis3.test.PersonMapper.insertPerson", person);session.commit();} finally {session.close();}}public void update(Person person) {SqlSession session = null;try {session = sessionFactory.openSession();session.insert("cn.ibatis3.test.PersonMapper.updatePerson", person);session.commit();} finally {session.close();}}@SuppressWarnings("unchecked")public List<Person> selectPersonsByName(String name) {List<Person> persons = new ArrayList<Person>();SqlSession session = null;try {session = sessionFactory.openSession();System.out.println(name);persons = session.selectList("cn.ibatis3.test.PersonMapper.selectPersonsByName", "%"+ name + "%");session.commit();} finally {session.close();}return persons;}}

 最后是表的创建:

Sql代码   收藏代码
  1. DROP TABLE IF EXISTS `test`.`person`;  
  2. CREATE TABLE  `test`.`person` (  
  3.   `id` int(10) unsigned NOT NULL auto_increment,  
  4.   `namevarchar(20) default NULL,  
  5.   `sex` varchar(8) default NULL,  
  6.   `birthday` datetime default NULL,  
  7.   PRIMARY KEY  (`id`)  
  8. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;  
DROP TABLE IF EXISTS `test`.`person`;
CREATE TABLE  `test`.`person` (`id` int(10) unsigned NOT NULL auto_increment,`name` varchar(20) default NULL,`sex` varchar(8) default NULL,`birthday` datetime default NULL,PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

 

 使用iBATIS3.0注解完成对数据库的简单操作

    iBATIS3.0也增加了一些简单的注解,iBATIS3的注解只能完成一些简单操作,要进行更复杂的操作,最好是在XML文件中配置。

    在数据库(本人使用的mysql)中建立一个person表:

Sql代码   收藏代码
  1. DROP TABLE IF EXISTS `test`.`person`;  
  2. CREATE TABLE  `test`.`person` (  
  3.   `id` int(10) unsigned NOT NULL auto_increment,  
  4.   `namevarchar(20) default NULL,  
  5.   `sex` varchar(8) default NULL,  
  6.   `birthday` datetime default NULL,  
  7.   PRIMARY KEY  (`id`)  
  8. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;  
DROP TABLE IF EXISTS `test`.`person`;
CREATE TABLE  `test`.`person` (`id` int(10) unsigned NOT NULL auto_increment,`name` varchar(20) default NULL,`sex` varchar(8) default NULL,`birthday` datetime default NULL,PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

 

    在MyEclipse新建一个Java Project,结构如下图



 

    在jdbc.properties文件是映射文件要使用的,其内容如下:

 

Properties代码   收藏代码
  1. driver=com.mysql.jdbc.Driver  
  2. url=jdbc\:mysql\://localhost\:3306/test  
  3. username=root  
  4. password=123456  

 SqlMapper.xml是iBATIS的配置文件,其代码如下:

Xml代码   收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE configuration  
  3. PUBLIC "-//ibatis.apache.org//DTD Config 3.0//EN"  
  4. "http://ibatis.apache.org/dtd/ibatis-3-config.dtd">  
  5. <configuration>  
  6.     <properties resource="jdbc.properties"/>  
  7.     <environments default="development">  
  8.         <environment id="development">  
  9.             <transactionManager type="JDBC"/>  
  10.             <dataSource type="POOLED">  
  11.                 <property name="driver" value="${driver}"/>  
  12.                 <property name="url" value="${url}"/>  
  13.                 <property name="username" value="${username}"/>  
  14.                 <property name="password" value="${password}"/>  
  15.             </dataSource>  
  16.         </environment>  
  17.     </environments>  
  18.     <mappers>  
  19.         <mapper resource="cn/ibatis3/test/annotation/person.xml"/>  
  20.     </mappers>  
  21. </configuration>  

 上面文件中的sql映射文件person.xml代码如下:

Xml代码   收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE mapper  
  3. PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"  
  4. "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">  
  5. <mapper namespace="cn.ibatis3.test.annotation.PersonMapper">  
  6.   
  7. </mapper>  

     注意:在iBATIS3中,命名空间(namespace)是必须的,如果不使用注解的话,名字可以自己定义。一旦使用了注解,这里必须是那个使用注解类或接口的全名。

     Person.java的代码请参考我的《iBATIS3学习(一)》。

    sessionFactory.java和我前面的《iBATIS3学习(一)》一样,只是注意将:

Java代码   收藏代码
  1. private String resource="cn/ibatis3/test/SqlMapper.xml";  
private String resource="cn/ibatis3/test/SqlMapper.xml";
Java代码   收藏代码
  1. 改为private String resource="cn/ibatis3/test/annotation/SqlMapper.xml";  
改为private String resource="cn/ibatis3/test/annotation/SqlMapper.xml";

 

    iBATIS3的注解可以定义在接口方法上的,也可以定义在类方法上,我这里定义在接口上,接口PersonMapper.java代码如下:

Java代码   收藏代码
  1. package cn.ibatis3.test.annotation;  
  2.   
  3. import java.util.List;  
  4.   
  5. import org.apache.ibatis.annotations.CacheNamespace;  
  6. import org.apache.ibatis.annotations.Delete;  
  7. import org.apache.ibatis.annotations.Insert;  
  8. import org.apache.ibatis.annotations.Options;  
  9. import org.apache.ibatis.annotations.Select;  
  10. import org.apache.ibatis.annotations.SelectProvider;  
  11. import org.apache.ibatis.annotations.Update;  
  12.   
  13. @CacheNamespace(readWrite = true)  
  14. public interface PersonMapper {  
  15.     @Select("select * from person where id = #{id}")  
  16.     @Options(useCache = true, flushCache = false)  
  17.     Person selectById(Integer id);  
  18.   
  19.     @SelectProvider(type=SqlProvider.class ,method="selectAllSql")  
  20.     List<Person> selectAll();  
  21.   
  22.     @Select("select * from person where name like #{name}")  
  23.     List<Person> selectPersonsByName(String name);  
  24.   
  25.     @Insert( { "insert into person(name,birthday,sex)",  
  26.             "values(#{name},#{birthday},#{sex})" })  
  27.     void insert(Person person);  
  28.   
  29.     @Delete("delete from person where id=#{id}")  
  30.     void delete(Person person);  
  31.   
  32.     @Update( {"update person set name=#{name},birthday=#{birthday},sex=#{sex}",  
  33.             "where id=#{id}" })  
  34.     void update(Person person);  
  35.   
  36. }  
package cn.ibatis3.test.annotation;import java.util.List;import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;@CacheNamespace(readWrite = true)
public interface PersonMapper {@Select("select * from person where id = #{id}")@Options(useCache = true, flushCache = false)Person selectById(Integer id);@SelectProvider(type=SqlProvider.class ,method="selectAllSql")List<Person> selectAll();@Select("select * from person where name like #{name}")List<Person> selectPersonsByName(String name);@Insert( { "insert into person(name,birthday,sex)","values(#{name},#{birthday},#{sex})" })void insert(Person person);@Delete("delete from person where id=#{id}")void delete(Person person);@Update( {"update person set name=#{name},birthday=#{birthday},sex=#{sex}","where id=#{id}" })void update(Person person);}

 上面的注解SelectProvider使用了一个类SqlProvider.java,其代码如下:

Java代码   收藏代码
  1. package cn.ibatis3.test.annotation;  
  2.   
  3. public class SqlProvider {  
  4.     // 动态的SQL语句,实际上应该使用iBATIS的动态SQL产生方法,这里仅仅是为了使用注解  
  5.     public String selectAllSql() {  
  6.         return "SELECT * FROM person p";  
  7.     }  
  8. }  
package cn.ibatis3.test.annotation;public class SqlProvider {// 动态的SQL语句,实际上应该使用iBATIS的动态SQL产生方法,这里仅仅是为了使用注解public String selectAllSql() {return "SELECT * FROM person p";}
}

 

 接口的实现类PersonDao.java代码如下:

Java代码   收藏代码
  1. package cn.ibatis3.test.annotation;  
  2.   
  3. import java.util.ArrayList;  
  4. import java.util.List;  
  5.   
  6. import org.apache.ibatis.session.SqlSession;  
  7. import org.apache.ibatis.session.SqlSessionFactory;  
  8.   
  9. public class PersonDao implements PersonMapper {  
  10.     private SqlSessionFactory sessionFactory = SessionFactory.getInstance()  
  11.             .getSqlSessionFactory();  
  12.   
  13.     public Person selectById(Integer id) {  
  14.         Person person = new Person();  
  15.         SqlSession session = null;  
  16.         try {  
  17.             session = sessionFactory.openSession();  
  18.             PersonMapper personMapper = session.getMapper(PersonMapper.class);  
  19.             person = personMapper.selectById(id);  
  20.         } finally {  
  21.             session.close();  
  22.         }  
  23.         return person;  
  24.     }  
  25.   
  26.     @SuppressWarnings("unchecked")  
  27.     public List<Person> selectAll() {  
  28.         List<Person> persons = new ArrayList<Person>();  
  29.         SqlSession session = null;  
  30.         try {  
  31.             session = sessionFactory.openSession();  
  32.             PersonMapper personMapper = session.getMapper(PersonMapper.class);  
  33.             persons = personMapper.selectAll();  
  34.         } finally {  
  35.             session.close();  
  36.         }  
  37.   
  38.         return persons;  
  39.     }  
  40.   
  41.     public void delete(Person person) {  
  42.         SqlSession session = null;  
  43.         try {  
  44.             session = sessionFactory.openSession();  
  45.             PersonMapper personMapper = session.getMapper(PersonMapper.class);  
  46.             personMapper.delete(person);  
  47.             session.commit();  
  48.         } finally {  
  49.             session.close();  
  50.         }  
  51.   
  52.     }  
  53.   
  54.     public void insert(Person person) {  
  55.         SqlSession session = null;  
  56.         try {  
  57.             session = sessionFactory.openSession();  
  58.             PersonMapper personMapper = session.getMapper(PersonMapper.class);  
  59.             personMapper.insert(person);  
  60.             session.commit();  
  61.         } finally {  
  62.             session.close();  
  63.         }  
  64.   
  65.     }  
  66.   
  67.     public void update(Person person) {  
  68.         SqlSession session = null;  
  69.         try {  
  70.             session = sessionFactory.openSession();  
  71.             PersonMapper personMapper = session.getMapper(PersonMapper.class);  
  72.             personMapper.update(person);  
  73.             session.commit();  
  74.         } finally {  
  75.             session.close();  
  76.         }  
  77.   
  78.     }  
  79.   
  80.     @SuppressWarnings("unchecked")  
  81.     public List<Person> selectPersonsByName(String name) {  
  82.         List<Person> persons = new ArrayList<Person>();  
  83.         SqlSession session = null;  
  84.         try {  
  85.             session = sessionFactory.openSession();  
  86.             PersonMapper personMapper = session.getMapper(PersonMapper.class);  
  87.             persons=personMapper.selectPersonsByName("%" + name + "%");  
  88.         } finally {  
  89.             session.close();  
  90.         }  
  91.   
  92.         return persons;  
  93.     }  
  94.   



http://chatgpt.dhexx.cn/article/1nJAC9fP.shtml

相关文章

IBatis使用浅析

ibatis 历史 Eight years ago in 2002, I created the iBATIS Data Mapper and introduced SQL Mapping as an approach to persistence layer development. Shortly thereafter, I donated the iBATIS name and code to the Apache Software Foundation. The ASF has been th…

IBatis的使用

IBatis的使用 1、IBatis是什么 回顾之前前端访问后端的整个流程&#xff1a; View ------ >Controller --------> Service ---------> DAO ------> 数据库 View :前端jsp/HTML Controller&#xff1a;Servlet/SpringMVC Service &#xff1a;Spring DAO&…

IBatis——初步总结

IBatis是持久层的框架&#xff0c;也就是我们说的Dao层框架&#xff0c;关注数据库操作以及和Java对象之间的关联&#xff0c;我们将这样的框架也称之为ORM&#xff08;Object/Relaction Mapping&#xff09;框架.而这里映射的主要是我们的表和实体&#xff08;bean&#xff09…

XMind导入Markdown(利用Typora导出opml)

安装Xmind XMind 是一款非常实用的商业思维导图软件 首先&#xff0c;安装Xmind并打开。通过"帮助"——>“关于Xmind”&#xff0c;可以获取到当前的版本号为 XMind 8 Update 9 在"文件"——>“导入”&#xff0c;可以看到Xmind支持的导入格式仅有…

推荐一款高效Cpp解析xml工具--RapidXml

解析效率比Xerces DOM 快50-100倍&#xff0c;tinyxml快30-60 &#xff0c;作者自己牛逼哄哄的说这是他所知道的最快的xml解析库了~~ 作者介绍说&#xff1a;" The table below compares speed of RapidXml to some other parsers, and to strlen() function executed on…

C++中rapidxml用法及例子

rapidxml是一个快速的xml库&#xff0c;比tinyxml快了50-100倍。本文给出创建、读取、写入xml的源码。 由于新浪博客不支持文本文件上传&#xff0c;在使用下面代码需要先下载 rapidxml&#xff0c;关于这个库的下载地址为&#xff1a; 官方网站&#xff1a; http://rapidxml.…

C++ Xml解析的效率比较(Qt/TinyXml2/RapidXml/PugiXml)

C Xml解析的效率比较&#xff08;Qt/TinyXml2/RapidXml/PugiXml&#xff09; C Xml解析的效率比较QtTinyXml2RapidXmlPugiXml 问题背景测试环境Qt - QDomDocumentTinyXml-2RapidXmlPugiXml总结 通常我们在一些软件的初始化或者保存配置时都会遇到对XML文件的操作&#xff0c;包…

SlimXml和TinyXml,RapidXml的性能对比

July 18th, 2010 zero Leave a comment Go to comments 前两天有朋友问&#xff0c;我的SlimXml有没有和RapidXml对比过效率&#xff1f;我是第一次听说这个库&#xff0c;更不用说对比效率了&#xff0c;于是上他们网站看了下。 好家伙&#xff0c;居然号称比TinyXml快30&…

RapidXml使用

vs2017 rapidxml-1.13 1 RapidXml使用 1.1 创建xml #include <iostream> #include "rapidxml/rapidxml.hpp" #include "rapidxml/rapidxml_utils.hpp" #include "rapidxml/rapidxml_print.hpp"using namespace rapidxml;void crateXml(…

使用rapidxml解析xml

rapidxml是一个由C模板实现的高效率xml解析库&#xff0c;号称解析速度比tinyxml快50倍&#xff08;忽悠&#xff09;&#xff0c;并作为boost::property的内置解析库&#xff1a; 其独立版本的官网&#xff1a;http://rapidxml.sourceforge.net/ 使用rapidxml的方法tinyxml极其…

RapidXml读取并修改XML文件

RapidXml读取并修改XML文件 RapidXml介绍RapidXml读取与修改xml文件 RapidXml介绍 RapidXml尝试创建最快的XML解析器&#xff0c;同时保留可用性&#xff0c;可移植性和合理的W3C兼容性。它是一个用现代C 编写的原位解析器&#xff0c;解析速度接近strlen在同一数据上执行的函数…

c++开源库rapidxml介绍与示例

官方地址&#xff1a;http://rapidxml.sourceforge.net/ 官方手册&#xff1a;http://rapidxml.sourceforge.net/manual.html 也可以在github上下载到别人上传的rapidxml:https://github.com/dwd/rapidxml 1.头文件 一般我们用到的头文件只有这三个 #include "rapidx…

Ubuntu 18.04 LDAP认证

将ubuntu配置为通过ldap认证&#xff0c;使其成为ldap client&#xff0c;系统版本ubuntu 18.04。 一 软件安装 apt-get install ldap-utils libpam-ldap libnss-ldap nslcd配置1 配置2 配置3 配置4 配置5 配置6 配置7 配置8 配置8 二 认证方式中添加Ldap #auth-client-conf…

LDAP认证服务器

1.要准备的环境与软件(这里测试环境是Centos6.0-64位系统) alfresco-community-4.2.c-installer-linux-x64.bin (注: alfresco是一个免费开源系统&#xff0c;可以自己去下载) apache-tomcat-7.0.42.tar db-4.5.20.tar jdk-6u45-linux-x64.bin openldap-stable-20100219.tar ph…

Jumpserver部署+Ldap认证

内容导航 &#xff08;一&#xff09;jumpserver快速部署1&#xff0c;部署内容2&#xff0c;附上安装脚本3&#xff0c;解决github无法连接4&#xff0c;修改配置 &#xff08;二&#xff09;使用jumpserver1&#xff0c;登录信息2&#xff0c;添加主机3&#xff0c;web终端登…

SVN使用LDAP认证

前言 SVN架构 用户访问SVN服务器分为两个部分&#xff1a;认证与授权。 SVN内置了有认证与授权机制&#xff0c;其认证是通过SVN仓库内的passwd文件提供&#xff0c;但它是明文、静态的&#xff0c;不方便且安全性低。 SVN还支持外部的认证&#xff0c;比如SASL&#xff0c;…

ldap 认证 java_Java实现LDAP认证(上)

Baidu脑残&#xff0c;把原来的空间改得不伦不类。所以把一些技术的东西挪到这里。 我找到两种方法&#xff0c;大同小异&#xff0c;第一种是通过Spring&#xff0c;适合已经采用Spring的项目。 一般来说用户名和密码都是保存在数据库中。现在有这个需求&#xff0c;用户名和密…

Harbor 整合ldap认证

前提&#xff1a; ldap服务器已经安装&#xff1a;OpenLDAP安装部署 harbor服务器已经安装&#xff1a;Harbro v1.8.0部署 一、ldap组织结构 1、登录信息 2、查看用户信息 二、harbor配置 1、使用默认密码登录&#xff0c;admin/Harbor12345 2、认证模式 3、测试ldap服务器…

ldap认证 java_Java实现LDAP认证(上) | 学步园

Baidu脑残&#xff0c;把原来的空间改得不伦不类。所以把一些技术的东西挪到这里。 我找到两种方法&#xff0c;大同小异&#xff0c;第一种是通过Spring&#xff0c;适合已经采用Spring的项目。 一般来说用户名和密码都是保存在数据库中。现在有这个需求&#xff0c;用户名和密…

Zabbix 整合ldap认证

前提&#xff1a; zabbix部署完成&#xff1a;CentOS7.3 64位&#xff0c;搭建Zabbix3.4 ldap部署完成&#xff1a;OpenLDAP安装部署 一、LDAP服务端 1、ldap登录信息 2、查看ldap组织架构 3、添加zabbix默认用户Admin 二、Zabbix网页端 1、使用zabbix默认管理员用户登录 …