亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

mybatis Plus 實現多表聯合查詢的方法

發布時間:2020-10-30 22:38:12 來源:億速云 閱讀:3972 作者:Leah 欄目:開發技術

本篇文章為大家展示了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();
  }
}

上述內容就是mybatis Plus 實現多表聯合查詢的方法,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業資訊頻道。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

鹰潭市| 道真| 沾化县| 平顶山市| 赣州市| 美姑县| 宜州市| 北碚区| 建平县| 平邑县| 延川县| 阿鲁科尔沁旗| 昌平区| 双峰县| 大足县| 榆中县| 巴中市| 琼结县| 丁青县| 延边| 安平县| 嵊州市| 蒙阴县| 怀宁县| 克东县| 灵石县| 永仁县| 婺源县| 闻喜县| 沅陵县| 灌云县| 历史| 弋阳县| 紫云| 漯河市| 新疆| 兰州市| 沂水县| 洱源县| 盐山县| 周宁县|