1.简单说明。

  MyBatis 可以使用简单的XML 或注解用于配置和原始映射,将接口和 Java 的 POJO( Plain Old Java Objects,普通的Java 对象)映射成数据库中的记录。

  每一个MyBatis项目中都以一个对象sqlSessionFactory为核心,它可以通过sqlSessionFactoryBuilder来获得,它产生了一个个的sqlSession。

2.关于项目中的使用做详尽说明。

  什么是Mapper对象?根据Mybatis的官方手册,应用程序除了要初始并启动Mybatis之外,还需要定义一些接口,接口里定义访问数据库的方法,存放接口的包路径下需要放置同名的XML配置文件。每个mapper元素对应一个mapper配置文件

3.Mybatis中参数传递的四种方式讲解

  http://edu.51cto.com/index.php?do=lesson&id=69884

4.使用mybatis generator自动生成映射文件详解

  http://www.cnblogs.com/mikelij/p/3841716.html  跟这篇一模一样。

5.项目实例分析

 <?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="org.iMybatis.abc.dao.UserDao">
<cache type="PERPETUAL" eviction="LRU" flushInterval="60000"
size="512" readOnly="true" />
<resultMap id="userResultMap" type="UserDto">
<id property="userid" column="userid" />
<result property="username" column="username" />
<result property="password" column="password" />
</resultMap>
<sql id="userColumns"> userid,username,password </sql>
<select id="queryUsers" parameterType="UserDto" resultType="UserDto"
useCache="false">
select <include refid="userColumns" />
from t_user t where t.username = #{username}
</select>
<insert id="insertUser" parameterType="UserDto"
useGeneratedKeys="true" keyProperty="userid">
insert into t_user (userid,username,password)
values (#{userid},#{username},#{password})
</insert>
<update id="updateUser" parameterType="UserDto">
update t_user set
username= #{username},
password = #{password},
where userid = #{userid}
</update>
<delete id="deleteUser" parameterType="UserDto">
delete from t_user where userid = #{userid}
</delete>
</mapper>

一段热乎乎的mapper的 XML 的配置文件

  看上面代码,Mapper元素只有一个属性namespace,它有两个作用:一是用于区分不同的mapper(在不同的mapper文件里,子元素的id可以相同,mybatis通过namespace和子元素的id联合区分),二是与接口关联(应用程序通过接口访问mybatis时,mybatis通过接口的完整名称查找对应的mapper配置,因此namespace的命名务必小心一定要某接口同名)。此外,mapper配置文件还有几个顶级子元素(它们须按照顺序定义):cache -配置本定命名空间的缓存。resultMap –结果映射,用来描述如何从数据库结果集映射到你想要的对象。接下来详解一下resultMap。

<resultMap id="userResultMap" type="User">
<id property=" userid " column="userid" />
<result property="username" column="username" />
<result property="password" column="password" />
</resultMap>

resultMap 配置

  resultMap提供了从数据库表列名到java对象属性的映射管理,示例只是提供了最简单的情况。在mapper配置文件中可以配置多个resultMap,不同的resultMap用id加以区分。type属性标记java类型(别名)。子元素中的property指带java中的属性,column指带数据库表的列名。

  Example类,用于构造复杂的筛选条件,详细分析如下:

上面的sql语句,创建了表'order_detail',以及各个字段。

package redcliff.cobara.entity;

import java.math.BigDecimal;

public class CobaraOrderDetail {
private Long id;
private Integer cityId;
private Integer orderId;
private String name;
private Byte type;
private BigDecimal cost;
private Integer shardx;
private Integer shardy;
private Integer shardz; public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
} public Integer getCityId() {
return cityId;
}
public void setCityId(Integer cityId) {
this.cityId = cityId;
} public Integer getOrderId() {
return orderId;
}
public void setOrderId(Integer orderId) {
this.orderId = orderId;
} public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
} public Byte getType() {
return type;
}
public void setType(Byte type) {
this.type = type;
} public BigDecimal getCost() {
return cost;
}
public void setCost(BigDecimal cost) {
this.cost = cost;
} public Integer getShardx() {
return shardx;
}
public void setShardx(Integer shardx) {
this.shardx = shardx;
} public Integer getShardy() {
return shardy;
}
public void setShardy(Integer shardy) {
this.shardy = shardy;
} public Integer getShardz() {
return shardz;
}
public void setShardz(Integer shardz) {
this.shardz = shardz;
}
}

redcliff.cobara.entity.CobaraOrderDetail.java

上面的entitiy包下的CobaraOrderDetail.java文件定义了实体类,是数据库的各个字段在Java web项目中一模一样的写照。当然了它是mybatis的generator生成器自动生成的。注意到,结构public class CobaraOrderDetail;里面的变量定义为private类型,方法定义为public类型

package redcliff.cobara.entity;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List; public class CobaraOrderDetailExample { protected String orderByClause;
protected boolean distinct;
protected List<Criteria> oredCriteria; public CobaraOrderDetailExample() {
oredCriteria = new ArrayList<Criteria>();
} public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
} public String getOrderByClause() {
return orderByClause;
} public void setDistinct(boolean distinct) {
this.distinct = distinct;
} public boolean isDistinct() {
return distinct;
} public List<Criteria> getOredCriteria() {
return oredCriteria;
} public void or(Criteria criteria) {
oredCriteria.add(criteria);
} public Criteria or() {
Criteria criteria = createCriteriaInternal();
oredCriteria.add(criteria);
return criteria;
} public Criteria createCriteria() {
Criteria criteria = createCriteriaInternal();
if (oredCriteria.size() == 0) {
oredCriteria.add(criteria);
}
return criteria;
} protected Criteria createCriteriaInternal() {
Criteria criteria = new Criteria();
return criteria;
} public void clear() {
oredCriteria.clear();
orderByClause = null;
distinct = false;
} protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList<Criterion>();
} public boolean isValid() {
return criteria.size() > 0;
} public List<Criterion> getAllCriteria() {
return criteria;
} public List<Criterion> getCriteria() {
return criteria;
} protected void addCriterion(String condition) {
if (condition == null) {
throw new RuntimeException("Value for condition cannot be null");
}
criteria.add(new Criterion(condition));
} protected void addCriterion(String condition, Object value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value));
} protected void addCriterion(String condition, Object value1, Object value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value1, value2));
} public Criteria andIdIsNull() {
addCriterion("id is null");
return (Criteria) this;
} public Criteria andIdIsNotNull() {
addCriterion("id is not null");
return (Criteria) this;
} public Criteria andIdEqualTo(Long value) {
addCriterion("id =", value, "id");
return (Criteria) this;
} public Criteria andIdNotEqualTo(Long value) {
addCriterion("id <>", value, "id");
return (Criteria) this;
} public Criteria andIdGreaterThan(Long value) {
addCriterion("id >", value, "id");
return (Criteria) this;
} public Criteria andIdGreaterThanOrEqualTo(Long value) {
addCriterion("id >=", value, "id");
return (Criteria) this;
} public Criteria andIdLessThan(Long value) {
addCriterion("id <", value, "id");
return (Criteria) this;
} public Criteria andIdLessThanOrEqualTo(Long value) {
addCriterion("id <=", value, "id");
return (Criteria) this;
} public Criteria andIdIn(List<Long> values) {
addCriterion("id in", values, "id");
return (Criteria) this;
} public Criteria andIdNotIn(List<Long> values) {
addCriterion("id not in", values, "id");
return (Criteria) this;
} public Criteria andIdBetween(Long value1, Long value2) {
addCriterion("id between", value1, value2, "id");
return (Criteria) this;
} public Criteria andIdNotBetween(Long value1, Long value2) {
addCriterion("id not between", value1, value2, "id");
return (Criteria) this;
} public Criteria andCityIdIsNull() {
addCriterion("city_id is null");
return (Criteria) this;
} public Criteria andCityIdIsNotNull() {
addCriterion("city_id is not null");
return (Criteria) this;
} public Criteria andCityIdEqualTo(Integer value) {
addCriterion("city_id =", value, "cityId");
return (Criteria) this;
} public Criteria andCityIdNotEqualTo(Integer value) {
addCriterion("city_id <>", value, "cityId");
return (Criteria) this;
} public Criteria andCityIdGreaterThan(Integer value) {
addCriterion("city_id >", value, "cityId");
return (Criteria) this;
} public Criteria andCityIdGreaterThanOrEqualTo(Integer value) {
addCriterion("city_id >=", value, "cityId");
return (Criteria) this;
} public Criteria andCityIdLessThan(Integer value) {
addCriterion("city_id <", value, "cityId");
return (Criteria) this;
} public Criteria andCityIdLessThanOrEqualTo(Integer value) {
addCriterion("city_id <=", value, "cityId");
return (Criteria) this;
} public Criteria andCityIdIn(List<Integer> values) {
addCriterion("city_id in", values, "cityId");
return (Criteria) this;
} public Criteria andCityIdNotIn(List<Integer> values) {
addCriterion("city_id not in", values, "cityId");
return (Criteria) this;
} public Criteria andCityIdBetween(Integer value1, Integer value2) {
addCriterion("city_id between", value1, value2, "cityId");
return (Criteria) this;
} public Criteria andCityIdNotBetween(Integer value1, Integer value2) {
addCriterion("city_id not between", value1, value2, "cityId");
return (Criteria) this;
} public Criteria andOrderIdIsNull() {
addCriterion("order_id is null");
return (Criteria) this;
} public Criteria andOrderIdIsNotNull() {
addCriterion("order_id is not null");
return (Criteria) this;
} public Criteria andOrderIdEqualTo(Integer value) {
addCriterion("order_id =", value, "orderId");
return (Criteria) this;
} public Criteria andOrderIdNotEqualTo(Integer value) {
addCriterion("order_id <>", value, "orderId");
return (Criteria) this;
} public Criteria andOrderIdGreaterThan(Integer value) {
addCriterion("order_id >", value, "orderId");
return (Criteria) this;
} public Criteria andOrderIdGreaterThanOrEqualTo(Integer value) {
addCriterion("order_id >=", value, "orderId");
return (Criteria) this;
} public Criteria andOrderIdLessThan(Integer value) {
addCriterion("order_id <", value, "orderId");
return (Criteria) this;
} public Criteria andOrderIdLessThanOrEqualTo(Integer value) {
addCriterion("order_id <=", value, "orderId");
return (Criteria) this;
} public Criteria andOrderIdIn(List<Integer> values) {
addCriterion("order_id in", values, "orderId");
return (Criteria) this;
} public Criteria andOrderIdNotIn(List<Integer> values) {
addCriterion("order_id not in", values, "orderId");
return (Criteria) this;
} public Criteria andOrderIdBetween(Integer value1, Integer value2) {
addCriterion("order_id between", value1, value2, "orderId");
return (Criteria) this;
} public Criteria andOrderIdNotBetween(Integer value1, Integer value2) {
addCriterion("order_id not between", value1, value2, "orderId");
return (Criteria) this;
} public Criteria andNameIsNull() {
addCriterion("name is null");
return (Criteria) this;
} public Criteria andNameIsNotNull() {
addCriterion("name is not null");
return (Criteria) this;
} public Criteria andNameEqualTo(String value) {
addCriterion("name =", value, "name");
return (Criteria) this;
} public Criteria andNameNotEqualTo(String value) {
addCriterion("name <>", value, "name");
return (Criteria) this;
} public Criteria andNameGreaterThan(String value) {
addCriterion("name >", value, "name");
return (Criteria) this;
} public Criteria andNameGreaterThanOrEqualTo(String value) {
addCriterion("name >=", value, "name");
return (Criteria) this;
} public Criteria andNameLessThan(String value) {
addCriterion("name <", value, "name");
return (Criteria) this;
} public Criteria andNameLessThanOrEqualTo(String value) {
addCriterion("name <=", value, "name");
return (Criteria) this;
} public Criteria andNameLike(String value) {
addCriterion("name like", value, "name");
return (Criteria) this;
} public Criteria andNameNotLike(String value) {
addCriterion("name not like", value, "name");
return (Criteria) this;
} public Criteria andNameIn(List<String> values) {
addCriterion("name in", values, "name");
return (Criteria) this;
} public Criteria andNameNotIn(List<String> values) {
addCriterion("name not in", values, "name");
return (Criteria) this;
} public Criteria andNameBetween(String value1, String value2) {
addCriterion("name between", value1, value2, "name");
return (Criteria) this;
} public Criteria andNameNotBetween(String value1, String value2) {
addCriterion("name not between", value1, value2, "name");
return (Criteria) this;
} public Criteria andTypeIsNull() {
addCriterion("type is null");
return (Criteria) this;
} public Criteria andTypeIsNotNull() {
addCriterion("type is not null");
return (Criteria) this;
} public Criteria andTypeEqualTo(Byte value) {
addCriterion("type =", value, "type");
return (Criteria) this;
} public Criteria andTypeNotEqualTo(Byte value) {
addCriterion("type <>", value, "type");
return (Criteria) this;
} public Criteria andTypeGreaterThan(Byte value) {
addCriterion("type >", value, "type");
return (Criteria) this;
} public Criteria andTypeGreaterThanOrEqualTo(Byte value) {
addCriterion("type >=", value, "type");
return (Criteria) this;
} public Criteria andTypeLessThan(Byte value) {
addCriterion("type <", value, "type");
return (Criteria) this;
} public Criteria andTypeLessThanOrEqualTo(Byte value) {
addCriterion("type <=", value, "type");
return (Criteria) this;
} public Criteria andTypeIn(List<Byte> values) {
addCriterion("type in", values, "type");
return (Criteria) this;
} public Criteria andTypeNotIn(List<Byte> values) {
addCriterion("type not in", values, "type");
return (Criteria) this;
} public Criteria andTypeBetween(Byte value1, Byte value2) {
addCriterion("type between", value1, value2, "type");
return (Criteria) this;
} public Criteria andTypeNotBetween(Byte value1, Byte value2) {
addCriterion("type not between", value1, value2, "type");
return (Criteria) this;
} public Criteria andCostIsNull() {
addCriterion("cost is null");
return (Criteria) this;
} public Criteria andCostIsNotNull() {
addCriterion("cost is not null");
return (Criteria) this;
} public Criteria andCostEqualTo(BigDecimal value) {
addCriterion("cost =", value, "cost");
return (Criteria) this;
} public Criteria andCostNotEqualTo(BigDecimal value) {
addCriterion("cost <>", value, "cost");
return (Criteria) this;
} public Criteria andCostGreaterThan(BigDecimal value) {
addCriterion("cost >", value, "cost");
return (Criteria) this;
} public Criteria andCostGreaterThanOrEqualTo(BigDecimal value) {
addCriterion("cost >=", value, "cost");
return (Criteria) this;
} public Criteria andCostLessThan(BigDecimal value) {
addCriterion("cost <", value, "cost");
return (Criteria) this;
} public Criteria andCostLessThanOrEqualTo(BigDecimal value) {
addCriterion("cost <=", value, "cost");
return (Criteria) this;
} public Criteria andCostIn(List<BigDecimal> values) {
addCriterion("cost in", values, "cost");
return (Criteria) this;
} public Criteria andCostNotIn(List<BigDecimal> values) {
addCriterion("cost not in", values, "cost");
return (Criteria) this;
} public Criteria andCostBetween(BigDecimal value1, BigDecimal value2) {
addCriterion("cost between", value1, value2, "cost");
return (Criteria) this;
} public Criteria andCostNotBetween(BigDecimal value1, BigDecimal value2) {
addCriterion("cost not between", value1, value2, "cost");
return (Criteria) this;
} public Criteria andShardxIsNull() {
addCriterion("shardx is null");
return (Criteria) this;
} public Criteria andShardxIsNotNull() {
addCriterion("shardx is not null");
return (Criteria) this;
} public Criteria andShardxEqualTo(Integer value) {
addCriterion("shardx =", value, "shardx");
return (Criteria) this;
} public Criteria andShardxNotEqualTo(Integer value) {
addCriterion("shardx <>", value, "shardx");
return (Criteria) this;
} public Criteria andShardxGreaterThan(Integer value) {
addCriterion("shardx >", value, "shardx");
return (Criteria) this;
} public Criteria andShardxGreaterThanOrEqualTo(Integer value) {
addCriterion("shardx >=", value, "shardx");
return (Criteria) this;
} public Criteria andShardxLessThan(Integer value) {
addCriterion("shardx <", value, "shardx");
return (Criteria) this;
} public Criteria andShardxLessThanOrEqualTo(Integer value) {
addCriterion("shardx <=", value, "shardx");
return (Criteria) this;
} public Criteria andShardxIn(List<Integer> values) {
addCriterion("shardx in", values, "shardx");
return (Criteria) this;
} public Criteria andShardxNotIn(List<Integer> values) {
addCriterion("shardx not in", values, "shardx");
return (Criteria) this;
} public Criteria andShardxBetween(Integer value1, Integer value2) {
addCriterion("shardx between", value1, value2, "shardx");
return (Criteria) this;
} public Criteria andShardxNotBetween(Integer value1, Integer value2) {
addCriterion("shardx not between", value1, value2, "shardx");
return (Criteria) this;
} public Criteria andShardyIsNull() {
addCriterion("shardy is null");
return (Criteria) this;
} public Criteria andShardyIsNotNull() {
addCriterion("shardy is not null");
return (Criteria) this;
} public Criteria andShardyEqualTo(Integer value) {
addCriterion("shardy =", value, "shardy");
return (Criteria) this;
} public Criteria andShardyNotEqualTo(Integer value) {
addCriterion("shardy <>", value, "shardy");
return (Criteria) this;
} public Criteria andShardyGreaterThan(Integer value) {
addCriterion("shardy >", value, "shardy");
return (Criteria) this;
} public Criteria andShardyGreaterThanOrEqualTo(Integer value) {
addCriterion("shardy >=", value, "shardy");
return (Criteria) this;
} public Criteria andShardyLessThan(Integer value) {
addCriterion("shardy <", value, "shardy");
return (Criteria) this;
} public Criteria andShardyLessThanOrEqualTo(Integer value) {
addCriterion("shardy <=", value, "shardy");
return (Criteria) this;
} public Criteria andShardyIn(List<Integer> values) {
addCriterion("shardy in", values, "shardy");
return (Criteria) this;
} public Criteria andShardyNotIn(List<Integer> values) {
addCriterion("shardy not in", values, "shardy");
return (Criteria) this;
} public Criteria andShardyBetween(Integer value1, Integer value2) {
addCriterion("shardy between", value1, value2, "shardy");
return (Criteria) this;
} public Criteria andShardyNotBetween(Integer value1, Integer value2) {
addCriterion("shardy not between", value1, value2, "shardy");
return (Criteria) this;
} public Criteria andShardzIsNull() {
addCriterion("shardz is null");
return (Criteria) this;
} public Criteria andShardzIsNotNull() {
addCriterion("shardz is not null");
return (Criteria) this;
} public Criteria andShardzEqualTo(Integer value) {
addCriterion("shardz =", value, "shardz");
return (Criteria) this;
} public Criteria andShardzNotEqualTo(Integer value) {
addCriterion("shardz <>", value, "shardz");
return (Criteria) this;
} public Criteria andShardzGreaterThan(Integer value) {
addCriterion("shardz >", value, "shardz");
return (Criteria) this;
} public Criteria andShardzGreaterThanOrEqualTo(Integer value) {
addCriterion("shardz >=", value, "shardz");
return (Criteria) this;
} public Criteria andShardzLessThan(Integer value) {
addCriterion("shardz <", value, "shardz");
return (Criteria) this;
} public Criteria andShardzLessThanOrEqualTo(Integer value) {
addCriterion("shardz <=", value, "shardz");
return (Criteria) this;
} public Criteria andShardzIn(List<Integer> values) {
addCriterion("shardz in", values, "shardz");
return (Criteria) this;
} public Criteria andShardzNotIn(List<Integer> values) {
addCriterion("shardz not in", values, "shardz");
return (Criteria) this;
} public Criteria andShardzBetween(Integer value1, Integer value2) {
addCriterion("shardz between", value1, value2, "shardz");
return (Criteria) this;
} public Criteria andShardzNotBetween(Integer value1, Integer value2) {
addCriterion("shardz not between", value1, value2, "shardz");
return (Criteria) this;
}
} public static class Criteria extends GeneratedCriteria { protected Criteria() {
super();
}
} public static class Criterion { private String condition;
private Object value;
private Object secondValue;
private boolean noValue;
private boolean singleValue;
private boolean betweenValue;
private boolean listValue;
private String typeHandler; public String getCondition() {
return condition;
} public Object getValue() {
return value;
} public Object getSecondValue() {
return secondValue;
} public boolean isNoValue() {
return noValue;
} public boolean isSingleValue() {
return singleValue;
} public boolean isBetweenValue() {
return betweenValue;
} public boolean isListValue() {
return listValue;
} public String getTypeHandler() {
return typeHandler;
} protected Criterion(String condition) {
super();
this.condition = condition;
this.typeHandler = null;
this.noValue = true;
} protected Criterion(String condition, Object value, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.typeHandler = typeHandler;
if (value instanceof List<?>) {
this.listValue = true;
} else {
this.singleValue = true;
}
} protected Criterion(String condition, Object value) {
this(condition, value, null);
} protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.secondValue = secondValue;
this.typeHandler = typeHandler;
this.betweenValue = true;
} protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
}
}

redcliff.cobara.entity.CobaraOrderDetailExample.java

上面的entity包下的CobaraOrderDetailExample.java文件同样也是用于映射的。只不过它用于构造复杂的筛选条件。注意到,里面的变量定义为protected类型,方法定义为public类型;结构public class CobaraOrderDetailExample。两个Java类独立存在,不相互依存。

package redcliff.cobara.mapper;

import com.dianwoba.redcliff.cobara.entity.CobaraOrderDetail;
import com.dianwoba.redcliff.cobara.entity.CobaraOrderDetailExample;
import java.util.List;
import org.apache.ibatis.annotations.Param; public interface CobaraOrderDetailMapper { int countByExample(CobaraOrderDetailExample example); int deleteByExample(CobaraOrderDetailExample example); int deleteByPrimaryKey(Long id); int insert(CobaraOrderDetail record); int insertSelective(CobaraOrderDetail record); List<CobaraOrderDetail> selectByExample(CobaraOrderDetailExample example); CobaraOrderDetail selectByPrimaryKey(Long id); int updateByExampleSelective(@Param("record") CobaraOrderDetail record, @Param("example") CobaraOrderDetailExample example); int updateByExample(@Param("record") CobaraOrderDetail record, @Param("example") CobaraOrderDetailExample example); int updateByPrimaryKeySelective(CobaraOrderDetail record); int updateByPrimaryKey(CobaraOrderDetail record);
}

redcliff.cobara.mapper.CobaraOrderDetailMapper.java

上面的mapper包下的CobaraOrderDetailMapper.java类中,定义了基于类CobaraOrderDetailExample的CRUD方法。从结构public interface CobarOrderDetailExample上来看,当然是没有实现的。

package redcliff.cobara.mapper;

public interface CobaraOrderDetailMapperExt extends CobaraOrderDetailMapper {

}

redcliff.cobara.mapper.CobaraOrderDetailMapperExt.java

上面的mapper包下的CobaraOrderDetailMapperExt.java类中,是一个空的接口。从结构上来看public interface CobaraOrderDetailMapperExt  extends CobaraOrderDetailMapper。从名字上来看Ext是英文单词external的简写,'external'的本意是外部的,外面的简写。可见此类是用于扩展的。

redcliff.cobara.mapper.CobaraOrderDetailMapper.xml

上面的redcliff.cobara.mapper.CobaraOrderDetailMapperExt.xml映射文件定义了基本的CRUD四个方法。

<?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="redcliff.cobara.mapper.CobaraOrderDetailMapperExt" > </mapper>

redcliff.cobara.mapper.CobaraOrderDetailMapperExt.xml

上面的redcliff.cobara.mapper.CobaraOrderDetailMapperExt.xml映射文件,扩展了CRUD操作,因为从mapper标签的唯一属性namespace两个xml是完全一样的。

以上的这些代码,用一句话描述就是:“entity.java建立了与数据库的映射,mapper.java中定义了CRUD的方法,mapper.xml中实现了方法”,那么他们是怎么联系起来的呢?mapper.java中的方法接收的参数是entityExample(半成品的sql语句)。mapper标签的namespace指示到了mapper.java类,意思是我对你的方法进行了实现。

附录,补充

学习资料参考地址

总结一下工作中用到的Mybatis业务逻辑的更多相关文章

  1. MyBatis知多少(6)表现层与业务逻辑层

    表现层 表现层负责向最终用户展示应用程序的控制方式以及数据.它还要负责所有信息的布局和格式.今天,商业应用程序最流行的表现方式应该算是Web前端了,它使用HTML和JavaScript并通 过Web浏 ...

  2. 工作中用到的linux命令

    都是工作中用到的,解决问题至上,不求甚解,怕再忘了,所以记录一下,勿喷. .log |,,,,|,| 先说一下这条命令: cat:打印文件内容 grep:查找,用到的有\s匹配空白字符 sed:刚用到 ...

  3. .NET Core实战项目之CMS 第十五章 各层联动工作实现增删改查业务

    连着两天更新叙述性的文章大家可别以为我转行了!哈哈!今天就继续讲讲我们的.NET Core实战项目之CMS系统的教程吧!这个系列教程拖得太久了,所以今天我就以菜单部分的增删改查为例来讲述下我的项目分层 ...

  4. Liu Junqiao:工作中用到的命令以及问题汇总

    工作中用到的命令以及问题汇总 2019-11-29 查看系统运行时间,这个问题是因为我们在阿里云上有个机器,在某一天发现这台机器上有的服务莫名奇妙的停了,然后排查时怀疑机器被重启过用如下如下命令查看了 ...

  5. 基于SpringMVC+Spring+MyBatis实现秒杀系统【业务逻辑】

    前言 该篇主要实现秒杀业务层,秒杀业务逻辑里主要包括暴露秒杀接口地址.实现秒杀业务逻辑.同时声明了三个业务类:Exposer.SeckillExecution.SeckillResult. Expos ...

  6. 翻译:使用 ASP.NET MVC 4, EF, Knockoutjs and Bootstrap 设计和开发站点 - 6 - 业务逻辑

    Part 3: 设计逻辑层:核心开发 如前所述,我们的解决方案如下所示: 下面我们讨论整个应用的结构,根据应用中不同组件的逻辑相关性,分离到不同的层中,层与层之间的通讯通过或者不通过限制.分层属于架构 ...

  7. 9.1.3 .net framework通过业务逻辑层自动生成WebApi的做法

    首先需要说明的是这是.net framework的一个组件,而不是针对.net core的.目前工作比较忙,因此.net core的转换正在编写过程中,有了实现会第一时间贴出来. 接下来进入正题.对于 ...

  8. 从零开始,搭建博客系统MVC5+EF6搭建框架(1),EF Code frist、实现泛型数据仓储以及业务逻辑

    前言      从上篇30岁找份程序员的工作(伪程序员的独白),文章开始,我说过我要用我自学的技术,来搭建一个博客系统,也希望大家给点意见,另外我很感谢博客园的各位朋友们,对我那篇算是自我阶段总结文章 ...

  9. ASP.NET MVC+EF框架+EasyUI实现权限管理系列(4)-业务逻辑层的封装

    原文:ASP.NET MVC+EF框架+EasyUI实现权限管理系列(4)-业务逻辑层的封装 ASP.NET MVC+EF框架+EasyUI实现权限管系列 (开篇)   (1):框架搭建    (2) ...

随机推荐

  1. Atitit atiuse软件系列

    Atitit atiuse软件系列 1.1.  Atian inputmethod 输入法 方言与多语言多文字支持 (au)1 1.2. File searcher 文件搜索器,支持压缩文件与正则表达 ...

  2. SSH框架详解

    1.什么是ssh? SSH对应 struts spring hibernate struts 采用MVC模式,主要是作用于用户交互 spring 采用IOC和AOP~作用比较抽象,是用于项目的松耦合 ...

  3. C#教程(1) -- .Net与C#简介

    (1).Net .Net指.Net平台或者是.Net Framework框架. 如果你把.Net平台想象成一个厨房,那么.Net Framework框架就是其中的柴米油盐酱醋茶. 如果你把.Net平台 ...

  4. dubbox

    github源码: https://github.com/dangdangdotcom/dubbox maven中央仓: 无 获取分支 git clone -b dubbox-2.8.4 https: ...

  5. BOM之navigator、history、screen对象

    navigator对象 [定义] navigator已经成为识别客户端浏览器的事实标准.下表中列出存在于所有浏览器的属性和方法 [检测插件] 检测浏览器插件是一种最常见的检测例程. [1]对于非IE浏 ...

  6. 2014牡丹江网络赛ZOJPretty Poem(暴力枚举)

    /* 将给定的一个字符串分解成ABABA 或者 ABABCAB的形式! 思路:暴力枚举A, B, C串! */ 1 #include<iostream> #include<cstri ...

  7. java中final注意的问题

    public class Test{ public static void main(String[] args){ Person p = new Person(); } } /* 4.修饰的变量是一 ...

  8. 《BI那点儿事》数据挖掘初探

    什么是数据挖掘? 数据挖掘(Data Mining),又称信息发掘(Knowledge Discovery),是用自动或半自动化的方法在数据中找到潜在的,有价值的信息和规则. 数据挖掘技术来源于数据库 ...

  9. C/C++:提升_头文件的使用

    C/C++:提升_头文件的使用 ◇写在前面 学到现在,很多人编写程序时只会使用一个文件.这样在代码量较小的时候,更利于表达程序,但是随着代码量的逐步增加,程序的思维逻辑不是我们一下子就可以完全理清的, ...

  10. Nodejs学习笔记(三)——一张图看懂Nodejs建站

    前言:一条线,竖着放,如果做不到精进至深,那就旋转90°,至少也图个幅度宽广. 通俗解释上面的胡言乱语:还没学会爬,就学起走了?! 继上篇<Nodejs学习笔记(二)——Eclipse中运行调试 ...