当前位置: 首页 > news >正文

做家政服务类网站的要求深圳市建设网

做家政服务类网站的要求,深圳市建设网,免费换友情链接,做移动网站优化排名首页Spring boot 集成mybatis-plus 背景 Spring boot集成mybatis后#xff0c;我们可以使用mybatis来操作数据。然后#xff0c;我们还是需要写许多重复的代码和sql语句#xff0c;比如增删改查。这时候#xff0c;我们就可以使用 mybatis-plus了#xff0c;它可以极大解放我…Spring boot 集成mybatis-plus 背景 Spring boot集成mybatis后我们可以使用mybatis来操作数据。然后我们还是需要写许多重复的代码和sql语句比如增删改查。这时候我们就可以使用 mybatis-plus了它可以极大解放我们的生产力。 一、mybatis-plus介绍 mybatis-plus是对mybatis的功能增强并且只做增强不做改动也就是说你完全可以把mybatis-plus当作mybatis来做。 二maven依赖 本次案例使用了8.0.11的mysql采用了druid连接池同时使用lombok最后集成mybati-plus的依赖。 !--mysql--dependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactIdversion8.0.11/version/dependency!--druid--dependencygroupIdcom.alibaba/groupIdartifactIddruid/artifactIdversion1.2.4/version/dependencydependencygroupIdcom.baomidou/groupIdartifactIdmybatis-plus-boot-starter/artifactIdversion3.5.6/version/dependency!--lombok--dependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdoptionaltrue/optional/dependency三、yml配置 yml中 配置了数据源和mybatis-plus的参数 spring:datasource:type: com.alibaba.druid.pool.DruidDataSourcedriver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://127.0.0.1:3306/aaa?characterEncodingutf8useSSLfalseserverTimezoneUTCrewriteBatchedStatementstrueusername: rootpassword: 123456web:resources:static-locations: classpath:/static/,file:${photo.file.dir} #暴露哪些资源可以通过项目名访问# 对于thymeleaf模板引 无效jackson:date-format: yyyy-MM-dd HH:mm:ss #时间戳统一转换为指定格式time-zone: GMT8 # 时区修改为东8区# mybatis-plus配置 mybatis-plus:configuration:map-underscore-to-camel-case: truelog-impl: org.apache.ibatis.logging.stdout.StdOutImplmapper-locations: classpath:mapper/*.xmltype-aliases-package: org.example.entity四、项目结构 项目结构是非常简单的典型的maven项目。 五、集成分页插件 mybatis-plus集成分页插件是相当简单的只需要添加下面的配置类就可以了。 Configuration MapperScan(org.example.mapper) public class MybatisPlusConfig {/*** 添加分页插件*/Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor() {MybatisPlusInterceptor interceptor new MybatisPlusInterceptor();interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); // 如果配置多个插件, 切记分页最后添加// 如果有多数据源可以不配具体类型, 否则都建议配上具体的 DbTypereturn interceptor;} }六、测试 我写了一个DailyReportMapper里面有用到mybatis-plus的BaseMapper也有用到mybatis的原有方式。像注解方式和xml写sql的方式是mybatis原有功能有了mybatis-plus其实不需要写一行sql直接通过mapper就可以操作了。 Mapper public interface DailyReportMapper extends BaseMapperDailyReport {Select(insert into daily_report(emp_total,device_total,device_used_num,birthday_emp_num,create_time) values(#{empTotal},#{deviceTotal},#{deviceUsedNum},#{birthdayEmpNum},NOW()))void save(DailyReport dailyReport);ListDailyReport lists(IPageDailyReport page); } 为了测试方便我就不写service了直接在DemoController中调用。 Controller RequestMapping(demo) Slf4j public class DemoController {Autowiredprivate DailyReportMapper dailyReportMapper;RequestMapping(demo)ResponseBodypublic String demo(){ IPageDailyReport page new Page(1,10);LambdaQueryWrapperDailyReport wrapper new LambdaQueryWrapper();wrapper.eq(DailyReport::getId,111);dailyReportMapper.selectList(page,wrapper);ListDailyReport lists dailyReportMapper.lists(page);return demo;} }页面访问url之后日志打印如下 DBC Connection [com.mysql.cj.jdbc.ConnectionImpl2ca78468] will not be managed by SpringPreparing: SELECT COUNT(*) AS total FROM daily_reportParameters: Columns: totalRow: 2Total: 1Preparing: select * from daily_report LIMIT ?Parameters: 10(Long)Columns: id, emp_total, device_total, device_used_num, birthday_emp_num, create_timeRow: 1, 4, 9, 4, 0, 2024-05-29 17:03:03Row: 2, 4, 9, 4, 0, 2024-05-30 19:38:00Total: 2可以看到sql正常执行分页插件也正常运行。 总结 spring boot 集成mybatis-plus是相当简单的集成之后操作数据库更是得心应手。
http://www.dnsts.com.cn/news/58124.html

相关文章:

  • 深圳哪里有网站建设开发一个软件的步骤
  • 网站优化需求表休闲小零食网站开发方案
  • 导购网站如何做免费推广什么是企业网站建设
  • 做电脑游戏破解的网站珠海做网站
  • 定制做网站投资项目网
  • 国外网站推广平台有哪些公司免费咨询图片
  • 哪个网站查公司信息比较准什么网站可以学做西餐
  • 如何修改网站title网站不备案可以访问吗
  • asp网站会员注册不了响应式网站欣赏
  • 做网站的公司怎么做业务智能模板网站建设
  • 仙桃做网站的公司seo基础知识考试
  • 南宁建设网站app和网站趋势
  • 天津市建设与管理网站做商务网站要多少钱
  • 网站后台建设怎么进入网站seo分析案例
  • 网站负责人备案采集照具体要求鞋帽网站欣赏
  • 网站推广的主要途径阳江最新通知今天
  • html5 视频网站 模板ui模板网站
  • 网站摇奖活动怎么做网站充值怎么做的
  • 长沙网站制作哪里好书本翻页 网站模板
  • 自学网站推荐晋城市建设局 网站
  • 福州网站排名提升做外贸门户网站
  • 公司网站制作多少钱动漫设计与制作专业学校
  • 无锡手机网站建设服务中国建设部官方网站绿色建筑
  • 网站建设资讯站杭州网站seo优化
  • 网站维护做啥的重庆有哪些做网站公司好
  • 网站建设详细教程视频wordpress 邮件设置
  • excel做注册网站网站域名使用费多少
  • 深圳市建设工程交易中心网站济南网站建设外包公司哪家好
  • wordpress页面属性模板网站seo与网站没关
  • 企业服务app济南官网seo技术厂家