<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
1.多表聯合查詢結果集建議使用VO類,當然也可以使用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="內容池多表聯合資料物件") public class TContentVo extends TContent { @ApiModelProperty(value = "編號") private Integer cid; @ApiModelProperty(value = "內容標題") 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 = "內容") 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("內容池模組") public class ContentController { @Resource private TContentService contentService; @ApiImplicitParams({ @ApiImplicitParam(name = "cid",value = "cid",dataType = "int",defaultValue = "0",required = false), @ApiImplicitParam(name = "title",value = "標題",dataType = "String",defaultValue = "",required = false), @ApiImplicitParam(name = "author",value = "作者姓名",dataType = "String",defaultValue = "",required = false), @ApiImplicitParam(name = "time",value = "釋出時間",dataType = "Date",defaultValue = "",required = false), @ApiImplicitParam(name = "content",value = "內容",dataType = "String",defaultValue = "",required = false), @ApiImplicitParam(name = "topic",value = "話題",dataType = "String",defaultValue = "",required = false), @ApiImplicitParam(name = "moduleNum",value = "投放模組 1熱點速遞 2基會直達",dataType = "int",defaultValue = "",required = false), @ApiImplicitParam(name = "pageIndex",value = "頁碼",dataType = "int",defaultValue = "1",required = false), @ApiImplicitParam(name = "pageSize",value = "每頁數量",dataType = "int",defaultValue = "10",required = false) }) @ApiResponses({ @ApiResponse(code = 200,message = "OK",response = TContent.class) @ApiOperation(value="分頁獲取內容介面(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,注意入參contentVo
<?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>
首先排除@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對應的xml檔案--> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> </resources> </build>
到此這篇關於mybatis-plus使用問題彙總的文章就介紹到這了,更多相關mybatis-plus使用內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45