1.配置文件
<?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="com.mysql.jdbc.Driver" />
<property name="url"
value="jdbc:mysql://ip/database?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull" />
<property name="username" value="root" />
<property name="password" value="" />
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="" />
</mappers>
</configuration>
sqlSessionFactory = MyBatisUtil.getSqlSessionFactory();
public static void insert(Product product) {
SqlSession sqlSession = sqlSessionFactory.openSession();
ProductDao productDao = sqlSession.getMapper(ProductDao.class);
productDao.insert(product);
sqlSession.commit();
sqlSession.close();
}
<?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="com.shitu.dao.ProductDao">
<select id="selectAll" resultType="" parameterType="com.shitu.bean.Product">
</select>
</mapper>