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

时间:2025-03-23 07:13:09

mybatis——example文件形式——多表联查
并且每个表中都有同样的id不能识别问题解决
方法名称:orderListByStatus
文件中写法
<select  resultMap="BaseResultMap1"
parameterType="">
SELECT
d.*, ,
,
,
,
,

FROM
t_jifen_order_detail d,
t_jifen_order_goods g,
t_jifen_goods_detail gd
<if test="_parameter != null">
<include ref />
</if>
AND
 = 
AND
 = 
ORDER BY
 DESC
limit #{page}, #{rows}
</select>

BaseResultMap1

<resultMap  type=""
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>


private String goodscode;
private String goodsname;
private Integer goodsnum;
private String imgpath;
private String imgaccesspath;    
private BigDecimal goodsjifen;
setter getter 方法

取一个别名

<sql > 
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="">
<trim prefix="(" suffix=")" prefixOverrides="and">
<foreach collection="" item="criterion">
<choose>
<when test="">
and d.${}
</when>
<when test="">
and d.${} #{}
</when>
<when test="">
and d.${} #{}
and
#{}
</when>
<when test="">
and d.${}
<foreach collection="" item="listItem"
open="(" close=")" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>

别名的名称与
<if test="_parameter != null">
<include ref />
</if>
一致
中得方法
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) {
(111);
OrderDetailExample example = new OrderDetailExample();
 criteria = example
.createCriteria();
if ((())) {
(());
}
// (());
(());
((pageNum - 1) * pageSize);
(pageSize);
List<OrderDetailPo> pages = (example);
int count = (example);
// 创建一个返回值对象
EUDataGridResult result = new EUDataGridResult();
(pages);
(count);
return result;
}
controller中得方法:

@RequestMapping("orderListByStatus")
@ResponseBody
public LBResult orderListByStatus(OrderDetailPo order, HttpServletRequest request,
HttpServletResponse response, Integer pageNum, Integer pageSize) {

// EUDataGridResult result =
// (page, rows, order);
// return result;

EUDataGridResult
// List<Order>
result = (order, pageNum, pageSize);
(result + "-====================");
if ((result)) {
return (400, "成功", result);
} else {
return (404, "失败");
}
}

EUDataGridResult为封装的对象
public class EUDataGridResult {
private long total;
private List<?> rows;
public long getTotal() {
return total;
}
public void setTotal(long total) {
 = total;
}
public List<?> getRows() {
return rows;
}
public void setRows(List<?> rows) {
 = rows;
}
}