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

揭阳seo网站管理三合一网站建设 万网

揭阳seo网站管理,三合一网站建设 万网,深圳微网站建设公司哪家好,wordpress 无法播放音乐框架介绍 MyBatis-Flex 是一个优雅的 MyBatis 增强框架#xff0c;它非常轻量、同时拥有极高的性能与灵活性。 MyBatis-Flex 官方文档 说明 本文参照官方文档的【快速开始】 章节#xff0c;编写 Spring Boot 项目的代码示例。 快速开始 创建数据库表 直接参照官网示…框架介绍 MyBatis-Flex 是一个优雅的 MyBatis 增强框架它非常轻量、同时拥有极高的性能与灵活性。 MyBatis-Flex 官方文档 说明 本文参照官方文档的【快速开始】 章节编写 Spring Boot 项目的代码示例。 快速开始 创建数据库表 直接参照官网示例SQL如下 CREATE TABLE IF NOT EXISTS tb_account (id INTEGER PRIMARY KEY auto_increment,user_name VARCHAR(100),age INTEGER,birthday DATETIME );INSERT INTO tb_account(id, user_name, age, birthday) VALUES (1, 张三, 18, 2020-01-11),(2, 李四, 19, 2021-03-21);依赖 MyBatis-Flex 核心依赖 dependencygroupIdcom.mybatis-flex/groupIdartifactIdmybatis-flex-spring-boot-starter/artifactIdversion1.7.3/version/dependency!-- 数据库连接池依赖必须添加否则会报错 --dependencygroupIdcom.alibaba/groupIdartifactIddruid-spring-boot-starter/artifactIdversion1.2.20/version/dependency驱动依赖MySQL dependencygroupIdcom.mysql/groupIdartifactIdmysql-connector-j/artifactIdscoperuntime/scope/dependency其余依赖比如 Lombokspring-boot-starter-webspring-boot-starter-test此处省略。 数据源配置 application.yml 中添加数据源配置。 spring:datasource:url: jdbc:mysql://localhost:3306/mybatis-flexusername: rootpassword: passwordtype: com.alibaba.druid.pool.DruidDataSourceAPT 配置 MyBatis-Flex APT 配置 MyBatis-Flex 使用了 APTAnnotation Processing Tool技术在项目编译的时候会自动根据 Entity 类定义的字段帮你生成 “ACCOUNT” 类以及 Entity 对应的 Mapper 类 通过开发工具构建项目如下图或者执行 maven 编译命令: mvn clean package 都可以自动生成。这个原理和 lombok 一致。 要对 MyBatis-Flex 的 APT 细节选项进行配置你需要在项目的 根目录 pom.xml 所在的目录下创建名为 mybatis-flex.config 的文件。 配置文件mybatis-flex.config # 开启 Mapper 自动生成 processor.mapper.generateEnable true # 开启 Mapper 注解 processor.mapper.annotation true配置文件图片示例 实体类和Mapper 实体类 这里使用了 Lombok 来简化代码。 package com.example.db.mybatisflex.entity;import com.mybatisflex.annotation.Id; import com.mybatisflex.annotation.KeyType; import com.mybatisflex.annotation.Table; import java.io.Serializable; import java.time.LocalDateTime; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor;/*** 账户 实体类。** author 宋冠巡* since 2023-10-29*/ Data Builder NoArgsConstructor AllArgsConstructor Table(value tb_account) public class Account implements Serializable {Id(keyType KeyType.Auto)private Integer id;private String userName;private Integer age;private LocalDateTime birthday;} Mapper Mapper 使用APT技术编译之后自动生成示例如下 测试 package com.example;import com.example.db.mybatisflex.entity.Account; import com.example.db.mybatisflex.mapper.AccountMapper; import com.mybatisflex.core.query.QueryWrapper; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest;import static com.example.db.mybatisflex.entity.table.AccountTableDef.ACCOUNT;Slf4j SpringBootTest class MybatisFlexDemoApplicationTests {private final AccountMapper accountMapper;Autowiredpublic MybatisFlexDemoApplicationTests(AccountMapper accountMapper) {this.accountMapper accountMapper;}Testvoid contextLoads() {QueryWrapper queryWrapper QueryWrapper.create().select().where(ACCOUNT.AGE.eq(18));Account account accountMapper.selectOneByQuery(queryWrapper);log.info(accounts {}, account);}} 控制台输出 accounts Account(id1, userName张三, age18, birthday2020-01-11T00:00)代码生成器 使用 代码生成器 根据数据库逆向生成 实体类 和 Service。 生成的位置生成器类 所在目录作为根目录。 依赖 !-- 代码生成器 --dependencygroupIdcom.mybatis-flex/groupIdartifactIdmybatis-flex-codegen/artifactIdversion1.7.3/version/dependency!-- 加入代码生成器后只有加入 processor 依赖才能正常使用 APT。--dependencygroupIdcom.mybatis-flex/groupIdartifactIdmybatis-flex-processor/artifactIdversion1.7.3/versionscopeprovided/scope/dependency代码生成器 - 代码 package com.example.db.mybatisflex;import com.alibaba.druid.pool.DruidDataSource; import com.mybatisflex.codegen.Generator; import com.mybatisflex.codegen.config.GlobalConfig;public class Codegen {public static void main(String[] args) {// 配置数据源DruidDataSource dataSource new DruidDataSource();dataSource.setUrl(jdbc:mysql://localhost:3306/mybatis-flex);dataSource.setUsername(root);dataSource.setPassword(password);// 创建配置内容GlobalConfig globalConfig createGlobalConfigUseStyle1();// 通过 datasource 和 globalConfig 创建代码生成器Generator generator new Generator(dataSource, globalConfig);// 生成代码generator.generate();}public static GlobalConfig createGlobalConfigUseStyle1() {// 创建配置内容GlobalConfig globalConfig new GlobalConfig();// 设置作者globalConfig.setAuthor(宋冠巡);// 设置根包globalConfig.setBasePackage(com.example.db.mybatisflex);// 设置表前缀和只生成哪些表globalConfig.setTablePrefix(tb_);globalConfig.setGenerateTable(tb_account);// 设置生成 entity 并启用 LombokglobalConfig.setEntityGenerateEnable(true);globalConfig.setEntityWithLombok(true);// 设置生成 mapper 如果使用 APT 生成 mapper则可以不用由代码生成器来生成。// globalConfig.setMapperGenerateEnable(true);// 设置生成 serviceglobalConfig.setServiceGenerateEnable(true);globalConfig.setServiceImplGenerateEnable(true);return globalConfig;}}生成效果 SQL 日志打印 内置方案 package com.example.db.config;import com.mybatisflex.core.audit.AuditManager; import com.mybatisflex.core.audit.ConsoleMessageCollector; import com.mybatisflex.core.audit.MessageCollector; import org.springframework.context.annotation.Configuration;Configuration public class MyBatisFlexConfiguration {public MyBatisFlexConfiguration() {// 开启审计功能AuditManager.setAuditEnable(true);// 设置 SQL 审计收集器MessageCollector collector new ConsoleMessageCollector();AuditManager.setMessageCollector(collector);}}MyBatis 自带方案 application.yml 中添加配置。 mybatis-flex:configuration:# 打印SQL日志log-impl: org.apache.ibatis.logging.stdout.StdOutImplMapper 链式操作 package com.example;import com.example.db.mybatisflex.entity.Account; import com.example.db.mybatisflex.mapper.AccountMapper; import com.mybatisflex.core.query.QueryChain; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest;import java.util.List;import static com.example.db.mybatisflex.entity.table.AccountTableDef.ACCOUNT;Slf4j SpringBootTest class ChainTest {private final AccountMapper accountMapper;Autowiredpublic ChainTest(AccountMapper accountMapper) {this.accountMapper accountMapper;}Testvoid testChain() {ListAccount accounts QueryChain.of(accountMapper).select(ACCOUNT.ALL_COLUMNS).from(ACCOUNT).where(ACCOUNT.AGE.ge(18)).list();log.info(accounts {}, accounts);}} Service 链式操作 package com.example;import com.example.db.mybatisflex.entity.Account; import com.example.db.mybatisflex.service.AccountService; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest;import java.util.List;import static com.example.db.mybatisflex.entity.table.AccountTableDef.ACCOUNT;/*** 测试 Service*/ Slf4j SpringBootTest class ServiceTest {private final AccountService accountService;Autowiredpublic ServiceTest(AccountService accountService) {this.accountService accountService;}/*** 测试 Service 的 链式操作*/Testvoid testServiceQueryChain() {ListAccount accounts accountService.queryChain().select(ACCOUNT.ALL_COLUMNS).from(ACCOUNT).where(ACCOUNT.AGE.ge(18)).list();log.info(accounts {}, accounts);} }
http://www.dnsts.com.cn/news/103051.html

相关文章:

  • 一般网站 要 加入 友情链接吗seo的含义
  • 怎么选择顺德网站建设搭建一个电商网站需要多少费用
  • 电子商务网站管理苏州网站建设相关技术
  • 个人建网站教程备案 网站 收录
  • 自助做网站中企动力有限公司官网
  • 北京网站制作公司招聘扶余手机网站开发
  • 杭州百度广州网站优化网站建设
  • 自己开发网站要多少钱友汇网网站建设管理后台设置
  • 网站开发维护公司怎么做外贸网站seo
  • 电脑做系统教学网站怎么申请建立一个公司网站
  • 商丘建网站广州工商注册核名查询系统
  • 大牌印花图案设计网站网站seo标题优化技巧
  • 最好的企业网站源码wordpress自动评论插件
  • 怎么建设自己的论坛网站电子商务公司介绍文案
  • 网站关键词的确定四站合一网站建设价格
  • 哈尔滨哪能买到黄页上海外包seo
  • 汕头seo网站优化刷东西网站建设
  • 商丘给企业做网站的公司网站移动端就是app吗
  • 台州网站搜索引擎优化关键词搜索量全网查询
  • 保山市住房和城乡建设厅网站网站建设一般多少
  • 泉州做网站公司公司网站建站收费
  • 做图模板网站有哪些内容男女明星直接做的视频网站
  • 镇平微网站建设网站建设现状
  • 无障碍网站建设标准做外贸雨伞到什么网站
  • 周口网站建设哪家好网站建设行业的前景分析
  • 网站建设入门教学做网站app需多少钱
  • 综合门户网站建设方案python搭建网站
  • 门户网站建设工作情况汇报seo技术教程博客
  • 山西手机响应式网站建设创业网站模板免费下载
  • 常德市 网站建设潍坊网站建设哪家好