mybatis Plus 多表联合查询
2019-12-26 16:04:04来源:博客园 阅读 ()
mybatis Plus 多表联合查询
//实体类package com.sk.skkill.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
@TableName("orders")
@Data
public class Order implements Serializable
{
public static final long serialVersionUID =1L;
private String id;
private String orderName;
private Date createTime;
private Date updateTime;
private String userID;
@TableField(exist = false)
private List<Users> listUsers;
public Order(){
}
public Order(String id, String orderName) {
this.id = id;
this.orderName = orderName;
}
}
//dao层
package com.sk.skkill.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sk.skkill.entity.Order;
import com.sun.javafx.collections.MappingChange;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;
public interface OrderMapper extends BaseMapper<Order>
{
List<Order> selectOrder();
int addOrder(Order order);
//多表联合查询 按条件orderID
@Select("select t1.*,t2.user_name,t2.nick_name from orders t1 LEFT JOIN users t2 ON t1.user_id =t2.id WHERE t1.user_id= #{id}")
List<Map<String,Object>> orderUserList(Page<Map<String,Object>> page,String id);
}
//service层
package com.sk.skkill.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sk.skkill.entity.Order;
import java.util.List;
import java.util.Map;
public interface OrderService extends IService<Order>
{
List<Order> selectOrder();
int addOrder(Order order);
// List<Map<String,Object>> orderUserList(Page<Map<String,Object>> page, String id);
Page<Map<String,Object>> selectListPage(int current,int number,String id);
}
//serviceImpl层
package com.sk.skkill.service.impl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sk.skkill.entity.Order;
import com.sk.skkill.mapper.OrderMapper;
import com.sk.skkill.service.OrderService;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService
{
@Override
public List<Order> selectOrder() {
return baseMapper.selectList(null);
}
@Override
public int addOrder(Order order) {
return baseMapper.insert(order);
}
@Override
public Page<Map<String, Object>> selectListPage(int current, int number,String id) {
//新建分页
Page<Map<String,Object>> page =new Page<Map<String,Object>>(current,number);
//返回结果
return page.setRecords(this.baseMapper.orderUserList(page,id));
}
}
//controller层
package com.sk.skkill.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sk.skkill.entity.Order;
import com.sk.skkill.service.impl.OrderServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("order")
public class OrderController
{
@Autowired
private OrderServiceImpl service;
@RequestMapping("selectOrder")
public List<Order> selectOrder()
{
return service.selectOrder();
}
@RequestMapping("addOrder")
public int addOrder(Order order){
order=new Order("FGGG","蒙牛MILK");
return service.addOrder(order);
}
@RequestMapping("selectListPage")
public List<Map<String,Object>> selectListPage(String id)
{
Page<Map<String, Object>> page = service.selectListPage(1, 2,id);
return page.getRecords();
}
}
原文链接:https://www.cnblogs.com/LQ970811/p/12100296.html
如有疑问请与原作者联系
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- MyBatis中的$和#,用不好,准备走人! 2020-06-11
- SpringBoot 2.3 整合最新版 ShardingJdbc + Druid + MyBatis 2020-06-11
- 天哪!手动编写mybatis雏形竟然这么简单 2020-06-06
- MyBatis整合双数据源 2020-06-04
- MyBatis缓存特性详解 2020-06-03
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash