mybatis-plus使用问题的示例分析
发表于:2025-11-07 作者:千家信息网编辑
千家信息网最后更新 2025年11月07日,这篇文章主要为大家展示了"mybatis-plus使用问题的示例分析",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"mybatis-plus使用问题的示例分
千家信息网最后更新 2025年11月07日mybatis-plus使用问题的示例分析
这篇文章主要为大家展示了"mybatis-plus使用问题的示例分析",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"mybatis-plus使用问题的示例分析"这篇文章吧。
一、多表联合分页查询
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 byPage = contentService.findByPage(new Page(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 */@Servicepublic class TContentServiceImpl extends ServiceImplimplements TContentService { @Resource private TContentMapper tContentMapper; @Override public IPage findByPage(Page 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{ IPage findByPage(Page page, @Param("contentVo") TContentVo contentVo);}
5.mapper.xml,注意入参contentVo
二、找不到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的
org.springframework.boot spring-boot-maven-plugin src/main/java **/*.xml
以上是"mybatis-plus使用问题的示例分析"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!
内容
时间
模块
示例
问题
分析
作者
篇文章
查询
联合
姓名
标题
类型
话题
学习
帮助
对象
建议
接口
数据
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
数据库什么是完全函数依赖
服务器的管理员密码忘了我
连续的xy保存在数据库
互联网科技下午茶
关于网络安全主题教育
无锡海航软件开发
exsi多台服务器集群
工行软件开发中心成都研发部地址
网络安全 信息安全两会
手机无法与谷歌服务器通信怎么办
h3c服务器与华为
天台库存软件开发定制价格
南京应用软件开发管理
网络安全售前待遇好的公司
有必要用独立服务器吗
互联网对文化和科技创新的影响
益阳软件开发招聘信息
学习软件开发学习哪种语言
服务器访问时间过长
申请服务器安全证书申请
中专软件开发好不好学
长宁区品牌软件开发质量保障
2020考研复试数据库
南邮网络技术与应用作业
花亦山心之月安卓服务器
呼和浩特市软件开发培训
软件开发可以用手机吗
北京网络技术咨询代理品牌
2017年全国网络安全周
江西软件开发活动方案