ibatis与hibernate结合使用(应用篇一)

13年前
 
1、实体类:
import javax.persistence.Column;  import javax.persistence.Entity;  import javax.persistence.GeneratedValue;  import javax.persistence.GenerationType;  import javax.persistence.Id;  import javax.persistence.Table;    @Entity  @Table(name = "sys_log")  public class Log {   @Id   @GeneratedValue(strategy = GenerationType.IDENTITY)   private Integer id;// 日志id     @Column   private String ip;// ip     @Column   private String content;// 操作内容     @Column   private Integer type;// 类型 0-登陆日志 1-操作日志     @Column   private String createTime;// 执行时间     public Log() {   }     public Integer getId() {    return id;   }     public void setId(Integer id) {    this.id = id;   }     public String getIp() {    return ip;   }     public void setIp(String ip) {    this.ip = ip;   }     public String getContent() {    return content;   }     public void setContent(String content) {    this.content = content;   }     public Integer getType() {    return type;   }     public void setType(Integer type) {    this.type = type;   }     public String getCreateTime() {    return createTime;   }     public void setCreateTime(String createTime) {    this.createTime = createTime;   }    }  


2、dao基类:
 
import java.io.Serializable;  import javax.annotation.Resource;  import com.ibatis.sqlmap.client.SqlMapClient;    /**   * @Description: 所有的DAO的实现类都必须继承该类。   * @author:admin   * @version:1.0   * @copyright:×××××××版权所有   *   * @param <E>   * @param <PK>   */  public abstract class BaseDao<E,PK extends Serializable> {     @Resource(name = "sqlMapClient")   protected  SqlMapClient sqlMapClient ;      protected BaseDao(){}     public SqlMapClient getSqlMapClient() {    return sqlMapClient;   }     public void setSqlMapClient(SqlMapClient sqlMapClient) {    this.sqlMapClient = sqlMapClient;   }        }  

 
3、dao接口
import com.nalike.system.model.Log;    public interface LogDao {     public void addLog(Log log) ;  }  

4、dao接口的实现类
import org.springframework.stereotype.Repository;    import com.nalike.core.dao.BaseDao;  import com.nalike.system.dao.LogDao;  import com.nalike.system.model.Log;      @Repository  public class LogDaoImpl extends BaseDao<Log,Integer> implements LogDao{      private final String ADD_LOG = "addLog" ;      public void addLog(Log log){    try {     sqlMapClient.insert(ADD_LOG, log) ;    } catch (Exception e) {     e.printStackTrace();    }   }      }