首页

springboot mybatisplus代码demo示例

标签:mybatisplus     发布时间:2022-10-22   
  • 云盘下载(需积分:8):
  • [提取码:kn52]

一、示例说明

该项目基于的springbootbaomidoumybatis-plus完整示例项目 - 包含maven配置且可运行,项目主要文件说明如下图所示

springboot mybatisplus代码demo示例

二、接口示例说明

package com.example.controller;@b@@b@import com.baomidou.mybatisplus.core.metadata.IPage;@b@import com.example.entity.User;@b@import com.example.service.UserService;@b@import org.springframework.beans.factory.annotation.Autowired;@b@import org.springframework.web.bind.annotation.*; @b@@b@@RestController@b@public class UserController {@b@@b@   @Autowired@b@   UserService userService;@b@   @b@   @RequestMapping(value="/getCount",method=RequestMethod.GET)@b@   public int getCount(){@b@      return userService.userCount();@b@   }@b@@b@@b@   @RequestMapping(value="/getPage",method=RequestMethod.GET)@b@   public IPage<User> getPage(String name,String age){@b@      return userService.getPage(name,age);@b@   }@b@@b@@b@   @RequestMapping(value="/delete/{id}",method=RequestMethod.GET)@b@   public void delete(@PathVariable String id){@b@      userService.delete(id);@b@   }@b@@b@   @RequestMapping(value="/update",method=RequestMethod.GET)@b@   public void update(@RequestBody User  user){@b@      userService.update(user);@b@   }@b@@b@@b@   @RequestMapping(value="/user/{id}",method=RequestMethod.GET)@b@   public User getDetail(@PathVariable String id){@b@      return userService.getByUniqueId(id);@b@   }@b@@b@ @b@}

1)查详情接口 - http://localhost:8866/user/0

springboot mybatisplus代码demo示例

2)分页查询  - http://localhost:8866/getPage?name=xwood

springboot mybatisplus代码demo示例

3)删除 - http://localhost:8866/delete/2

4)修改 - http://localhost:8866/update?id=2&name=1234

三、启动测试日志

D:\apps\jdk\jdk1.8.0_221\bin\java.exe -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:50286,suspend=y,server=n -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -javaagent:C:\Users\Think\AppData\Local\JetBrains\IntelliJIdea2020.1\captureAgent\debugger-agent.jar -Dfile.encoding=UTF-8 -classpath "D:\apps\jdk\jdk1.8.0_221\jre\lib\charsets.jar;D:\apps\jdk\jdk1.8.0_221\jre\lib\deploy.jar;D:\apps\jdk\jdk1.8.0_221\jre\lib\ext\access-bridge-64.jar;D:\apps\jdk\jdk1.8.0_221\jre\lib\ext\cldrdata.jar;D:\apps\jdk\jdk1.8.0_221\jre\lib\ext\dnsns.jar;D:\apps\jdk\jdk1.8.0_221\jre\lib\ext\jaccess.jar;D:\apps\jdk\jdk1.8.0_221\jre\lib\ext\jfxrt.jar;D:\apps\jdk\jdk1.8.0_221\jre\lib\ext\localedata.jar;D:\apps\jdk\jdk1.8.0_221\jre\lib\ext\nashorn.jar;D:\apps\jdk\jdk1.8.0_221\jre\lib\ext\sunec.jar;D:\apps\jdk\jdk1.8.0_221\jre\lib\ext\sunjce_provider.jar;D:\apps\jdk\jdk1.8.0_221\jre\lib\ext\sunmscapi.jar;D:\apps\jdk\jdk1.8.0_221\jre\lib\ext\sunpkcs11.jar;D:\apps\jdk\jdk1.8.0_221\jre\lib\ext\zipfs.jar;D:\apps\jdk\jdk1.8.0_221\jre\lib\javaws.jar;D:\apps\jdk\jdk1.8.0_221\jre\lib\jce.jar;D:\apps\jdk\jdk1.8.0_221\jre\lib\jfr.jar;D:\apps\jdk\jdk1.8.0_221\jre\lib\jfxswt.jar;D:\apps\jdk\jdk1.8.0_221\jre\lib\jsse.jar;D:\apps\jdk\jdk1.8.0_221\jre\lib\management-agent.jar;D:\apps\jdk\jdk1.8.0_221\jre\lib\plugin.jar;D:\apps\jdk\jdk1.8.0_221\jre\lib\resources.jar;D:\apps\jdk\jdk1.8.0_221\jre\lib\rt.jar;E:\maven-ws\springboot-mybatisplus-demo3\target\classes;E:\Repository\Jar\org\springframework\boot\spring-boot-starter-web\2.3.4.RELEASE\spring-boot-starter-web-2.3.4.RELEASE.jar;E:\Repository\Jar\org\springframework\boot\spring-boot-starter\2.3.4.RELEASE\spring-boot-starter-2.3.4.RELEASE.jar;E:\Repository\Jar\org\springframework\boot\spring-boot-starter-logging\2.3.4.RELEASE\spring-boot-starter-logging-2.3.4.RELEASE.jar;E:\Repository\Jar\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;E:\Repository\Jar\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;E:\Repository\Jar\org\apache\logging\log4j\log4j-to-slf4j\2.13.3\log4j-to-slf4j-2.13.3.jar;E:\Repository\Jar\org\apache\logging\log4j\log4j-api\2.13.3\log4j-api-2.13.3.jar;E:\Repository\Jar\org\slf4j\jul-to-slf4j\1.7.30\jul-to-slf4j-1.7.30.jar;E:\Repository\Jar\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;E:\Repository\Jar\org\yaml\snakeyaml\1.26\snakeyaml-1.26.jar;E:\Repository\Jar\org\springframework\boot\spring-boot-starter-json\2.3.4.RELEASE\spring-boot-starter-json-2.3.4.RELEASE.jar;E:\Repository\Jar\com\fasterxml\jackson\core\jackson-databind\2.11.2\jackson-databind-2.11.2.jar;E:\Repository\Jar\com\fasterxml\jackson\core\jackson-annotations\2.11.2\jackson-annotations-2.11.2.jar;E:\Repository\Jar\com\fasterxml\jackson\core\jackson-core\2.11.2\jackson-core-2.11.2.jar;E:\Repository\Jar\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.11.2\jackson-datatype-jdk8-2.11.2.jar;E:\Repository\Jar\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.11.2\jackson-datatype-jsr310-2.11.2.jar;E:\Repository\Jar\com\fasterxml\jackson\module\jackson-module-parameter-names\2.11.2\jackson-module-parameter-names-2.11.2.jar;E:\Repository\Jar\org\springframework\boot\spring-boot-starter-tomcat\2.3.4.RELEASE\spring-boot-starter-tomcat-2.3.4.RELEASE.jar;E:\Repository\Jar\org\apache\tomcat\embed\tomcat-embed-core\9.0.38\tomcat-embed-core-9.0.38.jar;E:\Repository\Jar\org\glassfish\jakarta.el\3.0.3\jakarta.el-3.0.3.jar;E:\Repository\Jar\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.38\tomcat-embed-websocket-9.0.38.jar;E:\Repository\Jar\org\springframework\spring-web\5.2.9.RELEASE\spring-web-5.2.9.RELEASE.jar;E:\Repository\Jar\org\springframework\spring-beans\5.2.9.RELEASE\spring-beans-5.2.9.RELEASE.jar;E:\Repository\Jar\org\springframework\spring-webmvc\5.2.9.RELEASE\spring-webmvc-5.2.9.RELEASE.jar;E:\Repository\Jar\org\springframework\spring-aop\5.2.9.RELEASE\spring-aop-5.2.9.RELEASE.jar;E:\Repository\Jar\org\springframework\spring-context\5.2.9.RELEASE\spring-context-5.2.9.RELEASE.jar;E:\Repository\Jar\org\springframework\spring-expression\5.2.9.RELEASE\spring-expression-5.2.9.RELEASE.jar;E:\Repository\Jar\org\springframework\boot\spring-boot-devtools\2.3.4.RELEASE\spring-boot-devtools-2.3.4.RELEASE.jar;E:\Repository\Jar\org\springframework\boot\spring-boot\2.3.4.RELEASE\spring-boot-2.3.4.RELEASE.jar;E:\Repository\Jar\org\springframework\boot\spring-boot-autoconfigure\2.3.4.RELEASE\spring-boot-autoconfigure-2.3.4.RELEASE.jar;E:\Repository\Jar\org\projectlombok\lombok\1.18.12\lombok-1.18.12.jar;E:\Repository\Jar\org\slf4j\slf4j-api\1.7.30\slf4j-api-1.7.30.jar;E:\Repository\Jar\org\springframework\spring-core\5.2.9.RELEASE\spring-core-5.2.9.RELEASE.jar;E:\Repository\Jar\org\springframework\spring-jcl\5.2.9.RELEASE\spring-jcl-5.2.9.RELEASE.jar;E:\Repository\Jar\mysql\mysql-connector-java\8.0.21\mysql-connector-java-8.0.21.jar;E:\Repository\Jar\com\oracle\ojdbc6\11.2.0.3\ojdbc6-11.2.0.3.jar;E:\Repository\Jar\org\springframework\boot\spring-boot-starter-jdbc\2.3.4.RELEASE\spring-boot-starter-jdbc-2.3.4.RELEASE.jar;E:\Repository\Jar\com\zaxxer\HikariCP\3.4.5\HikariCP-3.4.5.jar;E:\Repository\Jar\org\springframework\spring-jdbc\5.2.9.RELEASE\spring-jdbc-5.2.9.RELEASE.jar;E:\Repository\Jar\org\springframework\spring-tx\5.2.9.RELEASE\spring-tx-5.2.9.RELEASE.jar;E:\Repository\Jar\org\springframework\boot\spring-boot-configuration-processor\2.3.4.RELEASE\spring-boot-configuration-processor-2.3.4.RELEASE.jar;E:\Repository\Jar\com\baomidou\mybatis-plus-boot-starter\3.4.0\mybatis-plus-boot-starter-3.4.0.jar;E:\Repository\Jar\com\baomidou\mybatis-plus\3.4.0\mybatis-plus-3.4.0.jar;E:\Repository\Jar\com\baomidou\mybatis-plus-generator\3.4.0\mybatis-plus-generator-3.4.0.jar;E:\Repository\Jar\com\baomidou\mybatis-plus-extension\3.4.0\mybatis-plus-extension-3.4.0.jar;E:\Repository\Jar\com\baomidou\mybatis-plus-core\3.4.0\mybatis-plus-core-3.4.0.jar;E:\Repository\Jar\com\baomidou\mybatis-plus-annotation\3.4.0\mybatis-plus-annotation-3.4.0.jar;E:\Repository\Jar\com\github\jsqlparser\jsqlparser\3.2\jsqlparser-3.2.jar;E:\Repository\Jar\org\mybatis\mybatis\3.5.5\mybatis-3.5.5.jar;E:\Repository\Jar\org\mybatis\mybatis-spring\2.0.5\mybatis-spring-2.0.5.jar;E:\Repository\Jar\org\springframework\boot\spring-boot-starter-freemarker\2.3.4.RELEASE\spring-boot-starter-freemarker-2.3.4.RELEASE.jar;E:\Repository\Jar\org\freemarker\freemarker\2.3.30\freemarker-2.3.30.jar;E:\Repository\Jar\org\springframework\spring-context-support\5.2.9.RELEASE\spring-context-support-5.2.9.RELEASE.jar;D:\tool\JetBrains\IntelliJ IDEA 2020.1\lib\idea_rt.jar" com.example.MybatisPlusApplication@b@Connected to the target VM, address: '127.0.0.1:50286', transport: 'socket'@b@@b@  .   ____          _            __ _ _@b@ /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \@b@( ( )\___ | '_ | '_| | '_ \/ _' | \ \ \ \@b@ \\/  ___)| |_)| | | | | || (_| |  ) ) ) )@b@  '  |____| .__|_| |_|_| |_\__, | / / / /@b@ =========|_|==============|___/=/_/_/_/@b@ :: Spring Boot ::        (v2.3.4.RELEASE)@b@@b@2022-10-22 20:44:36.587  INFO 27100 --- [  restartedMain] com.example.MybatisPlusApplication       : Starting MybatisPlusApplication on DESKTOP-SIJ47KQ with PID 27100 (E:\maven-ws\springboot-mybatisplus-demo3\target\classes started by Think in E:\maven-ws\springboot-mybatisplus-demo3)@b@2022-10-22 20:44:36.600  INFO 27100 --- [  restartedMain] com.example.MybatisPlusApplication       : No active profile set, falling back to default profiles: default@b@2022-10-22 20:44:36.967  INFO 27100 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable@b@2022-10-22 20:44:36.970  INFO 27100 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'@b@2022-10-22 20:44:38.583  WARN 27100 --- [  restartedMain] o.m.s.mapper.ClassPathMapperScanner      : Skipping MapperFactoryBean with name 'userMapper' and 'com.example.mapper.UserMapper' mapperInterface. Bean already defined with the same name!@b@2022-10-22 20:44:38.584  WARN 27100 --- [  restartedMain] o.m.s.mapper.ClassPathMapperScanner      : No MyBatis mapper was found in '[com.example.mapper]' package. Please check your configuration.@b@2022-10-22 20:44:39.602  INFO 27100 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8866 (http)@b@2022-10-22 20:44:39.620  INFO 27100 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]@b@2022-10-22 20:44:39.621  INFO 27100 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.38]@b@2022-10-22 20:44:39.835  INFO 27100 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext@b@2022-10-22 20:44:39.835  INFO 27100 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2864 ms@b@Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.@b@Registered plugin: 'AbstractSqlParserHandler(sqlParserList=null, sqlParserFilter=null)'@b@Property 'mapperLocations' was not specified.@b@ _ _   |_  _ _|_. ___ _ |    _ @b@| | |\/|_)(_| | |_\  |_)||_|_\ @b@     /               |         @b@                        3.4.0 @b@2022-10-22 20:44:43.553  INFO 27100 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'@b@2022-10-22 20:44:44.257  INFO 27100 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729@b@2022-10-22 20:44:44.352  INFO 27100 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8866 (http) with context path ''@b@2022-10-22 20:44:44.376  INFO 27100 --- [  restartedMain] com.example.MybatisPlusApplication       : Started MybatisPlusApplication in 9.643 seconds (JVM running for 13.803)@b@2022-10-22 20:45:55.211  INFO 27100 --- [nio-8866-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'@b@2022-10-22 20:45:55.211  INFO 27100 --- [nio-8866-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'@b@2022-10-22 20:45:55.226  INFO 27100 --- [nio-8866-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 15 ms@b@Creating a new SqlSession@b@SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4708a8e5] was not registered for synchronization because synchronization is not active@b@2022-10-22 20:45:55.475  INFO 27100 --- [nio-8866-exec-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...@b@2022-10-22 20:45:55.810  INFO 27100 --- [nio-8866-exec-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.@b@JDBC Connection [HikariProxyConnection@790970631 wrapping com.mysql.cj.jdbc.ConnectionImpl@7571dfb] will not be managed by Spring@b@JsqlParserCountOptimize sql=SELECT  id,name,age,email  FROM user @b@ @b@ WHERE (name = ?)@b@==>  Preparing: SELECT COUNT(1) FROM user WHERE (name = ?)@b@==> Parameters: xwood(String)@b@<==    Columns: COUNT(1)@b@<==        Row: 1@b@==>  Preparing: SELECT id,name,age,email FROM user WHERE (name = ?) LIMIT ?@b@==> Parameters: xwood(String), 10(Long)@b@<==    Columns: id, name, age, email@b@<==        Row: 0, xwood, 22, abc@xwood.net@b@<==      Total: 1@b@Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4708a8e5]@b@Creating a new SqlSession@b@SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@73d0c273] was not registered for synchronization because synchronization is not active@b@JDBC Connection [HikariProxyConnection@2098668153 wrapping com.mysql.cj.jdbc.ConnectionImpl@7571dfb] will not be managed by Spring@b@JsqlParserCountOptimize sql=SELECT  id,name,age,email  FROM user @b@ @b@ WHERE (name = ?)@b@==>  Preparing: SELECT COUNT(1) FROM user WHERE (name = ?)@b@==> Parameters: xwood(String)@b@<==    Columns: COUNT(1)@b@<==        Row: 1@b@==>  Preparing: SELECT id,name,age,email FROM user WHERE (name = ?) LIMIT ?@b@==> Parameters: xwood(String), 10(Long)@b@<==    Columns: id, name, age, email@b@<==        Row: 0, xwood, 22, abc@xwood.net@b@<==      Total: 1@b@Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@73d0c273]@b@Creating a new SqlSession@b@SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4c635a26] was not registered for synchronization because synchronization is not active@b@JDBC Connection [HikariProxyConnection@2080847414 wrapping com.mysql.cj.jdbc.ConnectionImpl@7571dfb] will not be managed by Spring@b@==>  Preparing: DELETE FROM user WHERE id=?@b@==> Parameters: 2(String)@b@<==    Updates: 1@b@Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4c635a26]@b@Creating a new SqlSession@b@SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@46b8c326] was not registered for synchronization because synchronization is not active@b@JDBC Connection [HikariProxyConnection@1216296321 wrapping com.mysql.cj.jdbc.ConnectionImpl@4c40a856] will not be managed by Spring@b@JsqlParserCountOptimize sql=SELECT  id,name,age,email  FROM user @b@ @b@ WHERE (name = ?)@b@==>  Preparing: SELECT COUNT(1) FROM user WHERE (name = ?)@b@==> Parameters: xwood(String)@b@<==    Columns: COUNT(1)@b@<==        Row: 1@b@==>  Preparing: SELECT id,name,age,email FROM user WHERE (name = ?) LIMIT ?@b@==> Parameters: xwood(String), 10(Long)@b@<==    Columns: id, name, age, email@b@<==        Row: 0, xwood, 22, abc@xwood.net@b@<==      Total: 1@b@Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@46b8c326]
  • ◆ 相关内容
<<推荐下载>>
  • (1) 阿里巴巴Java开发手册8种不同版本
  • (2) Web前端开发视频教程
  • (3) 30+明星讲师PPT课件分享一线大厂架构实战经验
  • (4) java开发_架构篇_视频资源分享_v2208
  • (5) java开发_高级篇_视频资源分享_v2208
  • (6) java开发_进阶篇(中级)_视频资源分享_v2208
  • (7) java开发_入门篇_视频资源分享_v2208
  • (8) 微信小程序开发视频1+167源码+实战demo等下载
  • (9) easy-shopping电子商务java源码(附脚本和安装文档说明)下载
  • (10) java常用的72份知名实用的电子书下载
  • (11) java开发性能优化资料整理大全(8份电子文档+3份实战优化)下载
  • (12) 9个常用的算法设计资料和100以上视频课件内容下载
  • (13) vue开发必备常用手册16件下载
  • (14) 21种不同技术集群方案(es、flink、redis、nginx、zk、lvs、kafka、mysql、k8s等)参考资料下载
  • (15) 20种技术代码规范(js/java/dba/阿里/华为/oracle/mysql等)参考资料下载
  • (16) 微服务五套资料(0-1,架构设计,springcloud,nacos等)下载
  • (17) 架构师(28知识图谱+3套简历模板+6套架构实战文档等)完整资料整理下载
  • (18) 大数据18套实战基础知识+8套简历模板下载
  • (19) 并发编程全套(7套+阿里巴巴+亿级实战等)实战资料下载
  • (20) Kafka九套学习整理知识点全套(面试+笔记+代码api+命令+容备等)资料下载
  • (21) java全套9个不同方向类型的面试题(基础+核心+大厂+架构师+近万套题库等)下载
  • (22) JAVA开发常用API帮助文档大全(超52种以上技术资料,高手必备)下载
  • (23) springcloud超详细139件全套学习实战资料( 视频课件+源码demo+文档资料等)下载
  • 更多推荐>>
  • <<热门下载>>