MybtisPlus快速开发(从controller到mapper)

创建新项目

在这里插入图片描述

写好配置文件

server:port: 8905#配置MP控制台打印日志
mybatis-plus:configuration:log-impl: org.apache.ibatis.logging.stdout.StdOutImplspring:datasource:type: com.zaxxer.hikari.HikariDataSourcedriver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://localhost:3307/shequ-acl?characterEncoding=utf-8&useSSL=falseusername: rootpassword: rootjackson:date-format: yyyy-MM-dd HH:mm:sstime-zone: GMT+8

使用mybatisX插件快速生成一张表的相关类

在这里插入图片描述

在这里插入图片描述

而后将生成好的文件夹剪切进创建好的目录中:

在这里插入图片描述

引入依赖:

        <!--   -web依赖引入以后才会有@RestController注解     --><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.4.1</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><!--Lombok引入--><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency>

启动类上加扫描注解:

@SpringBootApplication
@MapperScan("com.mybatistest.mybatistest.mapper")
public class MybatistestApplication {public static void main(String[] args) {SpringApplication.run(MybatistestApplication.class, args);}}

写好Controller层

@RestController
@RequestMapping("mybatisPlus/test")
public class PermissionController {@AutowiredPermissionService permissionService;@AutowiredPermissionServiceSecond permissionServiceSecond;@GetMapping("/slectByNameSecond")public List<Permission> slectByNameSecond(@RequestParam String name){return permissionServiceSecond.slectByNameSecond(name);}@GetMapping("/slectByName")public List<Permission> queryByName(@RequestParam String name){return permissionService.queryByName(name);}
}

Mapper层

如果要在Service层注入mapper的话需要在mapper接口上加上@Repository注解

public interface PermissionMapper extends BaseMapper<Permission> {}
@Repository
public interface PermissionMapperSecond extends BaseMapper<Permission> {}

Service层

方式1:实现类不做继承

public interface PermissionService extends IService<Permission> {List<Permission> queryByName(String name);
}@Service
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permission>implements PermissionService{@Overridepublic List<Permission> queryByName(String name) {Permission permission = new Permission();permission.setName(name);QueryWrapper<Permission> queryWrapper = new QueryWrapper<Permission>(permission);List<Permission> permissions = baseMapper.selectList(queryWrapper);return permissions;}
}

方式二:实现类继承ServiceImpl<xxMapper, xxEntity>

public interface PermissionServiceSecond extends IService<Permission> {List<Permission> slectByNameSecond(String name);
}@Service
public class PermissionServiceSecondImpl implements PermissionServiceSecond {@AutowiredPermissionMapperSecond permissionMapperSecond;@Overridepublic List<Permission> slectByNameSecond(String name) {Permission permission = new Permission();permission.setName(name);QueryWrapper<Permission> queryWrapper = new QueryWrapper<Permission>(permission);List<Permission> permissions = permissionMapperSecond.selectList(queryWrapper);return permissions;}@Overridepublic boolean saveBatch(Collection<Permission> entityList, int batchSize) {return false;}@Overridepublic boolean saveOrUpdateBatch(Collection<Permission> entityList, int batchSize) {return false;}@Overridepublic boolean updateBatchById(Collection<Permission> entityList, int batchSize) {return false;}@Overridepublic boolean saveOrUpdate(Permission entity) {return false;}@Overridepublic Permission getOne(Wrapper<Permission> queryWrapper, boolean throwEx) {return null;}@Overridepublic Map<String, Object> getMap(Wrapper<Permission> queryWrapper) {return null;}@Overridepublic <V> V getObj(Wrapper<Permission> queryWrapper, Function<? super Object, V> mapper) {return null;}@Overridepublic BaseMapper<Permission> getBaseMapper() {return null;}@Overridepublic Class<Permission> getEntityClass() {return null;}
}

执行结果

[{"code": "btn.User.add","createTime": 1622455537000,"id": 7,"isDeleted": 0,"name": "添加","pid": 3,"type": 2,"updateTime": 1622507669000},{"code": "btn.Role.add","createTime": 1622455537000,"id": 12,"isDeleted": 0,"name": "添加","pid": 4,"type": 2,"updateTime": 1622507768000},{"code": "btn.Permission.add","createTime": 1622455537000,"id": 16,"isDeleted": 0,"name": "添加","pid": 5,"type": 2,"updateTime": 1622507859000},{"code": "btn.AttrGroup.add","createTime": 1624006384000,"id": 28,"isDeleted": 0,"name": "添加","pid": 27,"toCode": "AttrGroupAdd","type": 2,"updateTime": 1624006445000},{"createTime": 1624006770000,"id": 34,"isDeleted": 0,"name": "添加","pid": 33,"toCode": "SkuInfoAdd","type": 2,"updateTime": 1624006874000},{"code": "","createTime": 1624007141000,"id": 38,"isDeleted": 0,"name": "添加","pid": 37,"toCode": "ActivityInfoAdd","type": 2,"updateTime": 1624007173000},{"createTime": 1624007217000,"id": 41,"isDeleted": 0,"name": "添加","pid": 40,"toCode": "CouponInfoAdd","type": 2,"updateTime": 1624007242000}
]

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/185965.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

接手项目要做的事项

总结&#xff1a;在接手别人的项目时&#xff0c;至少应该自己整理并绘画四个图 1、产品脑图&#xff1a;帮助你理解产品的功能&#xff1b; 2、UML时序图&#xff1a;帮助你源代码的核心技术实现&#xff1b; 3、整体业务泳道图&#xff1a;帮助你从整体上熟悉业务的流程&a…

联想M7400W激光打印机加粉清零方法

基本参数 产品定位&#xff1a;多功能商用一体机 产品类型&#xff1a;黑白激光多功能一体机 涵盖功能&#xff1a;打印、复印、扫描 最大处理幅面&#xff1a;A4 耗材类型&#xff1a;鼓粉分离 耗材容量&#xff1a;硒鼓LD2451 12000页&#xff0c;墨粉LT2451 1500页、L…

Android 11.0 修改Android系统的通知自动成组的数量

场景: Android 系统对显示在通知列表中的同一个应用的通知进行分组管理,即相同的packageName中,当通知数量达到系统默认指定的数量时,会自动成一组. Android 11.0 中系统默认的自动成组数如下所示: 核心路径 : frameworks/base/core/res/res/values/config.xml<!-- 来自同…

LaTex语法实现多种矩阵

矩阵 0 1 1 0 \begin{matrix} 0 & 1 \\ 1 & 0 \end{matrix} 01​10​ \begin{matrix}0 & 1 \\1 & 0 \end{matrix}小括号矩阵 ( 0 1 1 0 ) \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix} (01​10​) \begin{pmatrix}0 & 1 \\1 & 0 \end{pm…

腾讯面试笔试题2023.11.30

给定一个由整数组成的非空数组所表示的非负整数如[1,2,3]&#xff0c;在该数的基础上加一。 最高位数字存放在数组的首位&#xff0c; 数组中每个元素只存储单个数字。你可以假设除了整数 0 之外&#xff0c;这个整数不会以零开头。 &#xff08;要求只能操作数组&#xff0c;不…

webpack的plugin和loader的区别

Webpack 的 Plugin 和 Loader 是用来处理模块和资源的两个不同的概念。 Loader 是Webpack 的模块转换器&#xff0c;用于将某种特定格式的内容转换为Webpack 可以处理的模块。它可以在构建流程中将各种类型的文件&#xff08;如 CSS、图片、ES6、TypeScript 等&#xff09;转换…

每日一练2023.11.30——谁先倒【PTA】

题目链接&#xff1a;谁先倒 题目要求&#xff1a; 划拳是古老中国酒文化的一个有趣的组成部分。酒桌上两人划拳的方法为&#xff1a;每人口中喊出一个数字&#xff0c;同时用手比划出一个数字。如果谁比划出的数字正好等于两人喊出的数字之和&#xff0c;谁就输了&#xff0…

PyCharm安装教程(详细步骤)

一、软件简介 PyCharm是一款Python IDE&#xff0c;其带有一整套可以帮助用户在使用Python语言开发时提高其效率的工具&#xff0c;比如&#xff0c; 调试、语法高亮、Project管理、代码跳转、智能提示、自动完成、单元测试、版本控制等等。此外&#xff0c;该IDE提供了一些高…

在Linux上搭建JavaWeb项目运行环境

文章目录 安装JDK安装Tomcat安装数据库 安装JDK 安装Oracle官方的JDK比较麻烦&#xff0c;我们在此处选择安装开源社区维护的openjdk。他们俩的差别不大且兼容。 安装Tomcat 我们把本地下载好的 tomcat.zip 包拖到Linux页面上&#xff0c;让Linux也有一个zip包&#xff0c;再…

Springboot整合mybatis_plus报错办法

问题详情&#xff1a;java.lang.IllegalArgumentException: Invalid value type for attribute ‘factoryBeanObjectType’: 问题背景&#xff1a; springboot 3.2.0 mybatis_plus:3.5.4.1 解决方法1&#xff08;经验证&#xff09;&#xff1a; 导入mybatis-spring包即可 &…

Python 计算图像差分的三种方式(cv2,torchvision,numpy)

前言&#xff1a;最近在可视化图像残差时&#xff0c;发现几种不同的差分方法&#xff0c;下面分别给出每种差分方法的实现方式&#xff0c;并比较不同方法之间的差异。 目录 1️⃣ cv22️⃣ PIL & torchvision3️⃣ PIL & numpy 目标&#xff1a;对于给定的下述两张图…

MacOS + Android Studio 通过 USB 数据线真机调试

环境&#xff1a;Apple M1 MacOS Sonoma 14.1.1 软件&#xff1a;Android Studio Giraffe | 2022.3.1 Patch 3 设备&#xff1a;小米10 Android 13 一、创建测试项目 安卓 HelloWorld 项目: 安卓 HelloWorld 项目 二、数据线连接手机 1. 手机开启开发者模式 参考&#xff1…

代码随想录算法训练营第四十八天【动态规划part09】 | 198.打家劫舍、213.打家劫舍II、337.打家劫舍III

198.打家劫舍 题目链接&#xff1a; 力扣&#xff08;LeetCode&#xff09;官网 - 全球极客挚爱的技术成长平台 求解思路&#xff1a; 当前房屋偷与不偷取决于前一个房屋是否被偷了 动规五部曲 确定dp数组及其下标含义&#xff1a;考虑下标i&#xff08;包括i&#xff09…

Qt串口助手

QT5 串口助手 ​ 由于C课程作业的需要&#xff0c;用QT5写了个简陋的串口助手。只作为一个简单的案例以供参考&#xff0c;默认读者具有C基础和了解简单的Qt操作。 功能展示 【用QT写了个简单的串口助手】 准备工作 Qt自带有<QSerialPort> 库, 可以方便地配置和调用…

lv11 嵌入式开发 轮询与中断13

1 CPU与硬件的交互方式 轮询 CPU执行程序时不断地询问硬件是否需要其服务&#xff0c;若需要则给予其服务&#xff0c;若不需要一段时间后再次询问&#xff0c;周而复始 中断 CPU执行程序时若硬件需要其服务&#xff0c;对应的硬件给CPU发送中断信号&#xff0c;CPU接收到中…

常见预处理

预处理 ——# 预处理功能&#xff1a;宏定义、文件包含、条件编译。 预处理命令 #include&#xff08;文件包含命令&#xff09; #define&#xff08;宏定义命令&#xff09; #undef #if&#xff08;条件编译&#xff09; #ifdef #ifndef #elif #endif defined函数&#xff0…

python爬取robomaster论坛数据,作为后端数据

一. 内容简介 python爬取robomaster论坛数据&#xff0c;作为后端数据 二. 软件环境 2.1vsCode 2.2Anaconda version: conda 22.9.0 2.3代码 三.主要流程 3.1 接口分析 # 接口分析 # 全部数据 # https://bbs.robomaster.com/forum.php?modforumdisplay&fid63 2…

LeetCode343. Integer Break

文章目录 一、题目二、题解 一、题目 Given an integer n, break it into the sum of k positive integers, where k > 2, and maximize the product of those integers. Return the maximum product you can get. Example 1: Input: n 2 Output: 1 Explanation: 2 1 …

Ubuntu systemd-analyze命令(系统启动性能分析工具:分析系统启动时间,找出可能导致启动缓慢的原因)

文章目录 Ubuntu systemd-analyze命令剖析目录简介systemd与systemd-analyze工作原理 安装和使用命令参数详解用例与示例显示启动时间&#xff08;systemd-analyze time&#xff09;列出启动过程中各个服务的启动时间&#xff08;systemd-analyze blame&#xff09;显示系统启动…

Linux中office环境LibreOffice_7.6.2下载

阿里云盘&#xff1a;LibreOffice_7.6.2 使用&#xff1a;下载的文件为exe文件&#xff0c;双击exe文件即可获取到文件 LibreOffice_7.6.2安装&#xff1a; 解压&#xff1a;tar -zxvf LibreOffice_7.6.2_Linux_x86-64_rpm.tar.gz 移动到RPMS目录&#xff1a;cd LibreOffice_7…