最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

mybatis-plus使用問題小結(jié)

 更新時間:2022年03月01日 11:37:19   作者:別動我的貓  
這篇文章主要介紹了mybatis-plus使用問題匯總,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

一、多表聯(lián)合分頁查詢

1.多表聯(lián)合查詢結(jié)果集建議使用VO類,當(dāng)然也可以使用resultMap

package com.cjhx.tzld.entity.vo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.cjhx.tzld.entity.TContent;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@Data
@ApiModel(value="TContentVo", description="內(nèi)容池多表聯(lián)合數(shù)據(jù)對象")
public class TContentVo extends TContent {
    @ApiModelProperty(value = "編號")
    private Integer cid;
    @ApiModelProperty(value = "內(nèi)容標(biāo)題")
    private String title;
    @ApiModelProperty(value = "作者Id")
    @TableField("authorId")
    private Integer authorId;
    @ApiModelProperty(value = "時間")
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") //返回時間類型
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") //接收時間類型
    private Date time;
    @ApiModelProperty(value = "內(nèi)容")
    private String content;
    @ApiModelProperty(value = "作者姓名")
    private String author;
    @ApiModelProperty(value = "話題")
    private String topic;
    @ApiModelProperty(value = "模塊編號")
    private int moduleNum;
    @ApiModelProperty(value = "模塊")
    private String module;
    public TContentVo() {
    }
    public TContentVo(Integer cid, String title, Date time, String content, String author, String topic, int moduleNum) {
        this.cid = cid;
        this.title = title;
        this.time = time;
        this.content = content;
        this.author = author;
        this.topic = topic;
        this.moduleNum = moduleNum;
}

2.controller

package com.cjhx.tzld.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjhx.tzld.common.Result;
import com.cjhx.tzld.entity.TContent;
import com.cjhx.tzld.entity.TContentRelationFund;
import com.cjhx.tzld.entity.TTopicPk;
import com.cjhx.tzld.entity.vo.TContentVo;
import com.cjhx.tzld.service.TContentService;
import io.swagger.annotations.*;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
/**
 * @since 2022-02-28
 */
@RestController
@RequestMapping("/content")
@Api("內(nèi)容池模塊")
public class ContentController {
    @Resource
    private TContentService contentService;
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cid",value = "cid",dataType = "int",defaultValue = "0",required = false),
            @ApiImplicitParam(name = "title",value = "標(biāo)題",dataType = "String",defaultValue = "",required = false),
            @ApiImplicitParam(name = "author",value = "作者姓名",dataType = "String",defaultValue = "",required = false),
            @ApiImplicitParam(name = "time",value = "發(fā)布時間",dataType = "Date",defaultValue = "",required = false),
            @ApiImplicitParam(name = "content",value = "內(nèi)容",dataType = "String",defaultValue = "",required = false),
            @ApiImplicitParam(name = "topic",value = "話題",dataType = "String",defaultValue = "",required = false),
            @ApiImplicitParam(name = "moduleNum",value = "投放模塊 1熱點速遞 2基會直達(dá)",dataType = "int",defaultValue = "",required = false),
            @ApiImplicitParam(name = "pageIndex",value = "頁碼",dataType = "int",defaultValue = "1",required = false),
            @ApiImplicitParam(name = "pageSize",value = "每頁數(shù)量",dataType = "int",defaultValue = "10",required = false)
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "OK",response = TContent.class)
    @ApiOperation(value="分頁獲取內(nèi)容接口(Web端)", notes="支持多條件查詢",httpMethod = "GET")
    @RequestMapping(value = "/getContentPage",method = RequestMethod.GET)
    public Result getContentPage(@RequestParam(defaultValue = "0",required = false) int cid,
                                 @RequestParam(defaultValue = "",required = false) String title,
                                 @RequestParam(defaultValue = "",required = false) String author,
                                 @RequestParam(required = false) Date time,
                                 @RequestParam(defaultValue = "",required = false) String content,
                                 @RequestParam(defaultValue = "",required = false) String topic,
                                 @RequestParam(defaultValue = "0",required = false) int moduleNum,
                                 @RequestParam(defaultValue = "1",required = false) int pageIndex,
                                 @RequestParam(defaultValue = "10",required = false)  int pageSize) throws Exception{
        try {
            IPage<TContentVo> byPage = contentService.findByPage(new Page<TContentVo>(pageIndex, pageSize),new TContentVo(cid, title, time, content, author,  topic, moduleNum));
            return Result.success(byPage);
        }catch (Exception e){
            return Result.serviceFail(e.getMessage());
        }
    }
}

3.service

package com.cjhx.tzld.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjhx.tzld.common.PageUtil;
import com.cjhx.tzld.entity.TContent;
import com.cjhx.tzld.entity.vo.TContentVo;
import com.cjhx.tzld.mapper.TContentMapper;
import com.cjhx.tzld.service.TContentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
/**
 * @since 2022-02-28
 */
@Service
public class TContentServiceImpl extends ServiceImpl<TContentMapper, TContent> implements TContentService {
    @Resource
    private TContentMapper tContentMapper;
    @Override
    public IPage<TContentVo> findByPage(Page<TContentVo> page, TContentVo contentVo) {
        return tContentMapper.findByPage(page,contentVo);
    }
}

4.mapper

package com.cjhx.tzld.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjhx.tzld.entity.TContent;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cjhx.tzld.entity.vo.TContentVo;
import org.apache.ibatis.annotations.Param;
/**
 * @since 2022-02-28
 */
public interface TContentMapper extends BaseMapper<TContent> {
    IPage<TContentVo> findByPage(Page<TContentVo> page, @Param("contentVo") TContentVo contentVo);
}

5.mapper.xml,注意入?yún)ontentVo

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cjhx.tzld.mapper.TContentMapper">

    <select id="findByPage" resultType="com.cjhx.tzld.entity.vo.TContentVo" parameterType="com.cjhx.tzld.entity.vo.TContentVo">
        SELECT t.`cid`,t.`authorId`,a.`name`,t.`title`,t.`time`,t.`content`,p.`topic`,h.`title` AS `module`
        FROM `t_content` t
        LEFT JOIN `t_author` a ON a.`aid`=t.`authorId`
        LEFT JOIN `t_topic_pk` p ON p.`cid` = t.`cid`
        LEFT JOIN `t_hot_express` h ON h.`cid` = t.`cid`
        UNION ALL
        SELECT t.`cid`,t.`authorId`,a.`name`,t.`title`,t.`time`,t.`content`,p.`topic`,f.`title` AS `module`
        LEFT JOIN `t_fund_point` f ON f.`cid` = t.`cid`
        <where>
            1=1
            <if test="contentVo.cid > 0"> and cid = #{contentVo.cid}</if>
            <if test="contentVo.title != null and contentVo.title != ''"> and t.title like concat('%', #{contentVo.title}, '%')</if>
            <if test="contentVo.author != null and contentVo.author != ''"> and a.author like concat('%', #{contentVo.author}, '%')</if>
            <if test="contentVo.time != null"> and t.time =${contentVo.time}</if>
            <if test="contentVo.content != null and contentVo.content != ''"> and t.content like concat('%', #{contentVo.content}, '%')</if>
            <if test="contentVo.topic != null and contentVo.topic != ''"> and p.topic like concat('%', #{contentVo.topic}, '%')</if>
            <if test="contentVo.moduleNum == 1"> and f.currentState = -1</if>
            <if test="contentVo.moduleNum == 2"> and h.currentState = -1</if>
        </where>
        order by time desc
    </select>
</mapper>

二、找不到mapper

首先排除@MapperScan("com.cjhx.tzld.mapper")已添加

1.首先配置文件掃描,mapper-locations:classpath:/com/cjhx/tzld/mapper/xml/*.xml

mybatis-plus:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  mapper-locations: classpath:/com/cjhx/tzld/mapper/xml/*.xml

2.在pom.xml的<build>添加xml資源

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <resources>
            <!--引入mapper對應(yīng)的xml文件-->
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>
    </build>

到此這篇關(guān)于mybatis-plus使用問題匯總的文章就介紹到這了,更多相關(guān)mybatis-plus使用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Springboot+Vue+shiro實現(xiàn)前后端分離、權(quán)限控制的示例代碼

    Springboot+Vue+shiro實現(xiàn)前后端分離、權(quán)限控制的示例代碼

    這篇文章主要介紹了Springboot+Vue+shiro實現(xiàn)前后端分離、權(quán)限控制的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • 基于Java代碼實現(xiàn)判斷春節(jié)、端午節(jié)、中秋節(jié)等法定節(jié)假日的方法

    基于Java代碼實現(xiàn)判斷春節(jié)、端午節(jié)、中秋節(jié)等法定節(jié)假日的方法

    這篇文章主要介紹了基于Java代碼實現(xiàn)判斷春節(jié)、端午節(jié)、中秋節(jié)等法定節(jié)假日的方法 的相關(guān)資料,需要的朋友可以參考下
    2016-01-01
  • 如何通過XML方式配置并實現(xiàn)Mybatis

    如何通過XML方式配置并實現(xiàn)Mybatis

    這篇文章主要介紹了如何通過XML方式配置并實現(xiàn)Mybatis,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-11-11
  • Spring?Boot項目完美大一統(tǒng)(結(jié)果異常日志統(tǒng)一)

    Spring?Boot項目完美大一統(tǒng)(結(jié)果異常日志統(tǒng)一)

    這篇文章主要為大家介紹了Spring?Boot項目完美大一統(tǒng)(結(jié)果異常日志統(tǒng)一)的實詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2024-01-01
  • 如何用java獲取指定日期是第幾周

    如何用java獲取指定日期是第幾周

    這篇文章主要給大家介紹了關(guān)于如何用java獲取指定日期是第幾周的相關(guān)資料,在開始之前我們需要先了解如何獲取當(dāng)前日期所在的年份以及第幾周,在Java中可以使用Calendar類來獲取這些信息,需要的朋友可以參考下
    2023-09-09
  • MyBatis驗證多級緩存及 Cache Aside 模式的應(yīng)用小結(jié)

    MyBatis驗證多級緩存及 Cache Aside 模式的應(yīng)用小結(jié)

    本文介紹了MyBatis的多級緩存機(jī)制,包括本地緩存和全局緩存,并通過Spock測試框架驗證了多級緩存的實現(xiàn),本文結(jié)合實例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧
    2024-12-12
  • JAVA?流程控制專項精講

    JAVA?流程控制專項精講

    不喜歡羅里吧嗦,講的很精簡易懂。從基礎(chǔ)開始講,后續(xù)會講到JAVA高級,中間會穿插面試題和項目實戰(zhàn),希望能給大家?guī)韼椭?/div> 2022-03-03
  • 一文搞懂Java頂層類之Object類的使用

    一文搞懂Java頂層類之Object類的使用

    java.lang.Object類是Java語言中的根類,即所有類的父類。它中描述的所有方法子類都可以使用。本文主要介紹了Object類中toString和equals方法的使用,感興趣的小伙伴可以了解一下
    2022-11-11
  • POI通過模板導(dǎo)出EXCEL文件的實例

    POI通過模板導(dǎo)出EXCEL文件的實例

    下面小編就為大家?guī)硪黄狿OI通過模板導(dǎo)出EXCEL文件的實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-08-08
  • 使用Spring?Cloud?Stream處理Java消息流的操作流程

    使用Spring?Cloud?Stream處理Java消息流的操作流程

    Spring?Cloud?Stream是一個用于構(gòu)建消息驅(qū)動微服務(wù)的框架,能夠與各種消息中間件集成,如RabbitMQ、Kafka等,今天我們來探討如何使用Spring?Cloud?Stream來處理Java消息流,需要的朋友可以參考下
    2024-08-08

最新評論

偏关县| 德昌县| 额济纳旗| 台州市| 微博| 元阳县| 当涂县| 定远县| 城固县| 乌恰县| 洛南县| 临西县| 吴堡县| 普陀区| 洱源县| 香港 | 绥棱县| 山阴县| 项城市| 北碚区| 长治市| 洪泽县| 松潘县| 玉屏| 青海省| 徐水县| 油尖旺区| 墨脱县| 四会市| 广元市| 海口市| 修水县| 弋阳县| 霍山县| 梧州市| 双城市| 西乌珠穆沁旗| 漯河市| 永修县| 逊克县| 扶绥县|