mybatis——example文件形式——多表联查
来源:互联网 发布:淘宝客服是不是店主 编辑:程序博客网 时间:2024/04/30 22:25
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;
}
}
------------------------------------------------------------------------------------结束--------------------------------------------------------
- mybatis——example文件形式——多表联查
- Flex——example
- MyBatis association的两种形式——MyBatis学习笔记之四
- 进程间通讯——内存映射/文件映射形式
- AndEngine中引用布局文件example.lvl——实现场景的加载
- RabbitMQ Python——Asynchronous publisher example
- CUDA By Example——Julia实例
- 【Mybatis】——mybatis缓存
- mybatis利用example文件进行异表字段模糊查询
- 简介如何使用MyBatis generator生成的Example文件
- 整理的opencv2.4.5—sample—adaptiveskindetector.cpp文件更简洁形式
- Spring(一)Spring IOC容器配置详解——基于xml文件形式
- Spring(一)Spring IOC容器配置详解——基于xml文件形式
- oracle-日常小计——oracle cmd 命令行形式导入 sql文件
- 关于objective—c如何让JPG文件转化成PDF形式
- 安卓开发:以Base64字符串形式上传文件——从Android选择文件并上传
- 基于Swift的iOS应用程序开发:以Base64字符串形式上传文件——从iOS选择文件并上传
- ACE封装——简化常见形式
- HTML5-视频播放器
- 蓝桥杯基础练习:十进制转十六进制
- Error:Could not install Gradle distribution from 'https://services.gradle.org/distributions/gradle-2
- ajax请求,和普通的http url请求,有什么不一样?
- Android Studio 调试技巧
- mybatis——example文件形式——多表联查
- ANGULARJS DIRECTIVE FOR SHOWING CONTENT IN A NEW WINDOW
- 自学SpringBoot之Spring插件拦路虎
- mysql中varchar(10)中定义的长度到底是字符长度还是字节长度
- Java--局部内部类在访问他所在方法中的局部变量必须用final修饰
- Superset安装部署
- Android AIDL
- 判断为空的几种方式
- 一个艰难的过程:在Mac上安装python-opencv