我是使用 Mybatis3 开发 Web 应用程序的新手。我有 DAO Impl 类和相关的 Mapper.xml 。我想为 DAO 编写 Junit 案例。如果有人能够帮助我,我将非常感激。
这是我所拥有的:
客户映射器.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="customer">
<insert id="newCustomer" parameterType="com.yell.hibu.domain.Customer">
INSERT INTO CUSTOMER(CUSTOMER_ID, NAME, EMAIL_ID,GRAPHIC_NAME,MOBILE,DOB,LANGUAGE,CITY,COUNTRY) values(#{customerID},#{customerName},#{emailID},#{userFileFileName},#{mobileNo},#{dob},#{language},#{city},#{country})
</insert>
<select id="selectCustomer" resultMap="customer">
SELECT * FROM CUSTOMER WHERE CUSTOMER_ID = #{customerID};
</select>
<resultMap type="com.yell.hibu.domain.Customer" id="customer">
<result property="customerID" column="CUSTOMER_ID" />
<result property="customerName" column="NAME" />
<result property="emailID" column="EMAIL_ID" />
<result property="userFileFileName" column="GRAPHIC_NAME" />
<result property="mobileNo" column="MOBILE" />
<result property="dob" column="DOB" />
<result property="language" column="LANGUAGE" />
<result property="city" column="CITY" />
<result property="country" column="COUNTRY" />
</resultMap>
</mapper>
DAOImpl.java
package com.yell.hibu.dao;
import org.apache.log4j.Logger;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import com.yell.hibu.domain.Customer;
public class CustomerDaoImpl extends SqlSessionDaoSupport implements CustomerDao{
private final Logger logger= Logger.getLogger(this.getClass());
public void insertCustomer(Customer customer) {
logger.info("Entered into CustomerDaoImpl :: insertCustomer()");
getSqlSession().insert("customer.newCustomer", customer);
logger.info("leaving from CustomerDaoImpl :: insertCustomer()");
}
}