mybatis——example文件形式——多表联查
并且每个表中都有同样的id不能识别问题解决
方法名称:orderListByStatus
mapper.xml文件中写法
<select id="orderListByStatus" resultMap="BaseResultMap1"
parameterType="com.integral.entity.OrderDetailExample">
SELECT
d.*, g.goodsname,
g.goodsnum,
g.goodscode,
g.imgaccesspath,
g.imgpath,
gd.goodsjifen
FROM
t_jifen_order_detail d,
t_jifen_order_goods g,
t_jifen_goods_detail gd
<if test="_parameter != null">
<include refid="Example_Where_Clause_R" />
</if>
AND
d.ordercode = g.ordercode
AND
g.goodscode = gd.goodscode
ORDER BY
d.createtime DESC
limit #{page}, #{rows}
</select>
BaseResultMap1
<resultMap id="BaseResultMap1" type="com.integral.po.OrderDetailPo"
extends="BaseResultMap">
<result column="goodsjifen" property="goodsjifen" jdbcType="DECIMAL" />
<result column="goodscode" property="goodscode" jdbcType="VARCHAR" />
<result column="goodsname" property="goodsname" jdbcType="VARCHAR" />
<result column="goodsnum" property="goodsnum" jdbcType="INTEGER" />
<result column="imgpath" property="imgpath" jdbcType="VARCHAR" />
<result column="imgaccesspath" property="imgaccesspath"
jdbcType="VARCHAR" />
</resultMap>
OrderDetailPo.java
private String goodscode;
private String goodsname;
private Integer goodsnum;
private String imgpath;
private String imgaccesspath;
private BigDecimal goodsjifen;
setter getter 方法
取一个别名
<sql id="Example_Where_Clause_R">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" suffix=")" prefixOverrides="and">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and d.${criterion.condition}
</when>
<when test="criterion.singleValue">
and d.${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and d.${criterion.condition} #{criterion.value}
and
#{criterion.secondValue}
</when>
<when test="criterion.listValue">
and d.${criterion.condition}
<foreach collection="criterion.value" item="listItem"
open="(" close=")" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
别名的名称与
<if test="_parameter != null">
<include refid="Example_Where_Clause_R" />
</if>
一致
mapper.java中得方法
List<OrderDetailPo> orderListByStatus(OrderDetailExample example);
service的方法:
EUDataGridResult
orderListByStatus(OrderDetailPo order,int page,int rows);
serviceImpl中得方法:
public// List<Order>
EUDataGridResult orderListByStatus(OrderDetailPo order, int pageNum,
int pageSize) {
System.out.println(111);
OrderDetailExample example = new OrderDetailExample();
com.integral.entity.OrderDetailExample.Criteria criteria = example
.createCriteria();
if (LBUtil.isNotEmpty(order.getOrderstatus())) {
criteria.andOrderstatusEqualTo(order.getOrderstatus());
}
// example.setUid(order.getUid());
criteria.andUidEqualTo(order.getUid());
example.setPage((pageNum - 1) * pageSize);
example.setRows(pageSize);
List<OrderDetailPo> pages = orderMapper.orderListByStatus(example);
int count = orderMapper.countByExample(example);
// 创建一个返回值对象
EUDataGridResult result = new EUDataGridResult();
result.setRows(pages);
result.setTotal(count);
return result;
}
controller中得方法:
@RequestMapping("orderListByStatus")
@ResponseBody
public LBResult orderListByStatus(OrderDetailPo order, HttpServletRequest request,
HttpServletResponse response, Integer pageNum, Integer pageSize) {
// EUDataGridResult result =
// orderService.orderListByStatus(page, rows, order);
// return result;
EUDataGridResult
// List<Order>
result = orderService.orderListByStatus(order, pageNum, pageSize);
System.err.println(result + "-====================");
if (LBUtil.isNotEmpty(result)) {
return LBResult.build(400, "成功", result);
} else {
return LBResult.build(404, "失败");
}
}
EUDataGridResult为封装的对象
public class EUDataGridResult {
private long total;
private List<?> rows;
public long getTotal() {
return total;
}
public void setTotal(long total) {
this.total = total;
}
public List<?> getRows() {
return rows;
}
public void setRows(List<?> rows) {
this.rows = rows;
}
}