总结一下工作中用到的Mybatis业务逻辑
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.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业务逻辑的更多相关文章
- MyBatis知多少(6)表现层与业务逻辑层
表现层 表现层负责向最终用户展示应用程序的控制方式以及数据.它还要负责所有信息的布局和格式.今天,商业应用程序最流行的表现方式应该算是Web前端了,它使用HTML和JavaScript并通 过Web浏 ...
- 工作中用到的linux命令
都是工作中用到的,解决问题至上,不求甚解,怕再忘了,所以记录一下,勿喷. .log |,,,,|,| 先说一下这条命令: cat:打印文件内容 grep:查找,用到的有\s匹配空白字符 sed:刚用到 ...
- .NET Core实战项目之CMS 第十五章 各层联动工作实现增删改查业务
连着两天更新叙述性的文章大家可别以为我转行了!哈哈!今天就继续讲讲我们的.NET Core实战项目之CMS系统的教程吧!这个系列教程拖得太久了,所以今天我就以菜单部分的增删改查为例来讲述下我的项目分层 ...
- Liu Junqiao:工作中用到的命令以及问题汇总
工作中用到的命令以及问题汇总 2019-11-29 查看系统运行时间,这个问题是因为我们在阿里云上有个机器,在某一天发现这台机器上有的服务莫名奇妙的停了,然后排查时怀疑机器被重启过用如下如下命令查看了 ...
- 基于SpringMVC+Spring+MyBatis实现秒杀系统【业务逻辑】
前言 该篇主要实现秒杀业务层,秒杀业务逻辑里主要包括暴露秒杀接口地址.实现秒杀业务逻辑.同时声明了三个业务类:Exposer.SeckillExecution.SeckillResult. Expos ...
- 翻译:使用 ASP.NET MVC 4, EF, Knockoutjs and Bootstrap 设计和开发站点 - 6 - 业务逻辑
Part 3: 设计逻辑层:核心开发 如前所述,我们的解决方案如下所示: 下面我们讨论整个应用的结构,根据应用中不同组件的逻辑相关性,分离到不同的层中,层与层之间的通讯通过或者不通过限制.分层属于架构 ...
- 9.1.3 .net framework通过业务逻辑层自动生成WebApi的做法
首先需要说明的是这是.net framework的一个组件,而不是针对.net core的.目前工作比较忙,因此.net core的转换正在编写过程中,有了实现会第一时间贴出来. 接下来进入正题.对于 ...
- 从零开始,搭建博客系统MVC5+EF6搭建框架(1),EF Code frist、实现泛型数据仓储以及业务逻辑
前言 从上篇30岁找份程序员的工作(伪程序员的独白),文章开始,我说过我要用我自学的技术,来搭建一个博客系统,也希望大家给点意见,另外我很感谢博客园的各位朋友们,对我那篇算是自我阶段总结文章 ...
- ASP.NET MVC+EF框架+EasyUI实现权限管理系列(4)-业务逻辑层的封装
原文:ASP.NET MVC+EF框架+EasyUI实现权限管理系列(4)-业务逻辑层的封装 ASP.NET MVC+EF框架+EasyUI实现权限管系列 (开篇) (1):框架搭建 (2) ...
随机推荐
- javascript里阻止事件冒泡
如下图所示,灰色块包含红色块,假设我们为灰色和红色块各绑定一个单击弹框事件,当我们点击红色块时,不希望触发灰色块的弹框事件,这就需要阻止冒泡事件了. IE里阻止冒泡事件使用cancelBubble属性 ...
- SpringMVC与mybatis整合
一.逆向工程生成基础信息 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generator ...
- C#打开新页面
最常用的页面跳转(原窗口被替代):Response.Redirect("XXX.aspx"); 利用url地址打开本地网页或互联网:Respose.Write("< ...
- 如何制作自己的yum源
在 /etc/yum.repos.d下创建一个以.repo结尾的文件如aaa.repo,其内容如下(一定要以repo结尾) [aaa] name=aaa baseurl=http://mirror ...
- web前端攻击详解
前端攻击成因 在web网页的脚本中,有些部分的显示内容会依据外界输入值而发生变化,而如果这些声称html的程序中存在问题,就会滋生名为跨站脚本的安全隐患 XSS跨站脚本攻击: 英文全称cross-si ...
- SSIS 数据输出列因为字符截断而失败
在数据源组件中,如果存在字符串类型的数据列,那么可能会存在,因为字符类型的长度不匹配,导致字符数据被截断的问题. SSIS报错信息:“Text was truncated or one or more ...
- Shader LOD
设置:单个设置Shader.maximumLOD.全局设置Shader.globalMaximumLOD.QualitySettings里面的Maximum LODLevel 原理:小于指定值的sha ...
- WPF自定义控件与样式(5)-Calendar/DatePicker日期控件自定义样式及扩展
一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: 日历控 ...
- Android属性动画之第一重修炼总结
经过这两天对ObjectAnimator属性动画的学习,基本对Android提供的属性动画有了一定的认识,现在就为大家以一个类似扇形打开的效果做总结. 效果图: 下面就让我们用刚刚学到的属性动画效果, ...
- Spring集成MyBatis完整示例
该文详细的通过Spring IOC.MyBatis.Servlet.Maven及Spring整合MyBatis的等技术完成一个简单的图书管理功能,实现图书列表.删除.多删除.编辑.新增功能.梳理前面学 ...