mybatis——example文件形式——多表联查

21 篇文章 0 订阅

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;
}
}


  • 7
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

乐观的Terry

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值