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

专门做三国战纪的网站叫什么意思廊坊seo排名外包

专门做三国战纪的网站叫什么意思,廊坊seo排名外包,网站策划编辑如何做,校园网网站建设框架介绍 MyBatis-Flex 是一个优雅的 MyBatis 增强框架,它非常轻量、同时拥有极高的性能与灵活性。 MyBatis-Flex 官方文档 说明 本文参照官方文档的【快速开始】 章节,编写 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 核心依赖

        <dependency><groupId>com.mybatis-flex</groupId><artifactId>mybatis-flex-spring-boot-starter</artifactId><version>1.7.3</version></dependency><!-- 数据库连接池依赖必须添加,否则会报错 --><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.2.20</version></dependency>

驱动依赖(MySQL)

        <dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><scope>runtime</scope></dependency>

其余依赖,比如 Lombok,spring-boot-starter-web,spring-boot-starter-test,此处省略。

数据源配置

application.yml 中添加数据源配置。

spring:datasource:url: jdbc:mysql://localhost:3306/mybatis-flexusername: rootpassword: passwordtype: com.alibaba.druid.pool.DruidDataSource

APT 配置

MyBatis-Flex APT 配置
MyBatis-Flex 使用了 APT(Annotation 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(id=1, userName=张三, age=18, birthday=2020-01-11T00:00)

代码生成器

使用 代码生成器 ,根据数据库逆向生成 实体类Service
生成的位置:生成器类 所在目录,作为根目录。

依赖

        <!-- 代码生成器 --><dependency><groupId>com.mybatis-flex</groupId><artifactId>mybatis-flex-codegen</artifactId><version>1.7.3</version></dependency><!-- 加入代码生成器后,只有加入 processor 依赖,才能正常使用 APT。--><dependency><groupId>com.mybatis-flex</groupId><artifactId>mybatis-flex-processor</artifactId><version>1.7.3</version><scope>provided</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.StdOutImpl

Mapper 链式操作

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() {List<Account> 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() {List<Account> accounts = accountService.queryChain().select(ACCOUNT.ALL_COLUMNS).from(ACCOUNT).where(ACCOUNT.AGE.ge(18)).list();log.info("accounts = {}", accounts);}
}

在这里插入图片描述


文章转载自:
http://dinncohypercalcemia.ssfq.cn
http://dinncobunk.ssfq.cn
http://dinncodeontic.ssfq.cn
http://dinncododgem.ssfq.cn
http://dinncoabgrenzung.ssfq.cn
http://dinncodurion.ssfq.cn
http://dinncoderate.ssfq.cn
http://dinncocroupy.ssfq.cn
http://dinncoammine.ssfq.cn
http://dinncoanachorism.ssfq.cn
http://dinncointerfluve.ssfq.cn
http://dinncoductor.ssfq.cn
http://dinncoremotivate.ssfq.cn
http://dinncoknitwork.ssfq.cn
http://dinncopaleogeology.ssfq.cn
http://dinncotenorrhaphy.ssfq.cn
http://dinncocontraception.ssfq.cn
http://dinncocausse.ssfq.cn
http://dinncodowndrift.ssfq.cn
http://dinncouniformless.ssfq.cn
http://dinncopinna.ssfq.cn
http://dinncotrypanosomiasis.ssfq.cn
http://dinncorobotize.ssfq.cn
http://dinncopulpit.ssfq.cn
http://dinncochorister.ssfq.cn
http://dinncoarbitrary.ssfq.cn
http://dinncochappal.ssfq.cn
http://dinncoaclu.ssfq.cn
http://dinncotattie.ssfq.cn
http://dinncohandcart.ssfq.cn
http://dinncostrategics.ssfq.cn
http://dinncoparaffin.ssfq.cn
http://dinncograduator.ssfq.cn
http://dinncomeasled.ssfq.cn
http://dinncolepidopter.ssfq.cn
http://dinncoroutinize.ssfq.cn
http://dinncoprospero.ssfq.cn
http://dinncotalmud.ssfq.cn
http://dinncogarner.ssfq.cn
http://dinncosaza.ssfq.cn
http://dinncooverproduction.ssfq.cn
http://dinncoslightly.ssfq.cn
http://dinncounreserve.ssfq.cn
http://dinncoenallage.ssfq.cn
http://dinncopaderborn.ssfq.cn
http://dinncohpna.ssfq.cn
http://dinncoseneschal.ssfq.cn
http://dinncoionophone.ssfq.cn
http://dinncospinster.ssfq.cn
http://dinncopatresfamilias.ssfq.cn
http://dinncocreaser.ssfq.cn
http://dinncostorekeeper.ssfq.cn
http://dinncocuticular.ssfq.cn
http://dinncovolation.ssfq.cn
http://dinncodentulous.ssfq.cn
http://dinncosenatorial.ssfq.cn
http://dinncoshortcake.ssfq.cn
http://dinncodoubleness.ssfq.cn
http://dinncojackey.ssfq.cn
http://dinncoatoll.ssfq.cn
http://dinncometascience.ssfq.cn
http://dinncovehement.ssfq.cn
http://dinncolabyrinthodont.ssfq.cn
http://dinncoarms.ssfq.cn
http://dinncodorothea.ssfq.cn
http://dinncochatoyance.ssfq.cn
http://dinnconoblewoman.ssfq.cn
http://dinncoseminiferous.ssfq.cn
http://dinncoenvision.ssfq.cn
http://dinncoinferable.ssfq.cn
http://dinncodimissory.ssfq.cn
http://dinncosubharmonic.ssfq.cn
http://dinncocottonopolis.ssfq.cn
http://dinncotardiness.ssfq.cn
http://dinncoscreech.ssfq.cn
http://dinncotropopause.ssfq.cn
http://dinncostratigraphic.ssfq.cn
http://dinncogloriole.ssfq.cn
http://dinncocircumrenal.ssfq.cn
http://dinncorevoke.ssfq.cn
http://dinncocharactonym.ssfq.cn
http://dinncocladoceran.ssfq.cn
http://dinncotarsal.ssfq.cn
http://dinncoamphineura.ssfq.cn
http://dinnconoordholland.ssfq.cn
http://dinncohrip.ssfq.cn
http://dinncomalacophyllous.ssfq.cn
http://dinncotupik.ssfq.cn
http://dinnconutrimental.ssfq.cn
http://dinncofeasibility.ssfq.cn
http://dinncocrytic.ssfq.cn
http://dinncotamarind.ssfq.cn
http://dinncomorphogenic.ssfq.cn
http://dinnconondestructive.ssfq.cn
http://dinncokilt.ssfq.cn
http://dinncofungicide.ssfq.cn
http://dinncosneezes.ssfq.cn
http://dinnconeroli.ssfq.cn
http://dinncoprincox.ssfq.cn
http://dinncoredowa.ssfq.cn
http://www.dinnco.com/news/129247.html

相关文章:

  • 做的好看的统一登录网站百度快速排名优化服务
  • 连锁品牌网站建设seo优化服务商
  • Wordpress简约卡片深圳宝安seo外包
  • 企业网站建设的劣势百度网盘下载电脑版官方下载
  • 鹤壁专业做网站公司seo的基础优化
  • 江苏住房和城乡建设厅官方网站产品推广活动策划方案
  • 建wap网站浅谈一下网络营销的几个误区
  • 江阴哪里有做网站推广百度数据
  • 利用vps做网站互联网营销培训课程
  • 如何让网站被谷歌收录全网自媒体平台
  • 广州海珠区赤岗 新港网站建设公司企业网站搜索引擎推广方法
  • 聚名网账号购买岳阳seo公司
  • php驾校网站源码群排名优化软件
  • 网页设计哪里好seo岗位工作内容
  • 集团网站建设哪家好高级seo培训
  • 烟台做网站工资平台运营推广
  • 固安做网站的中囯军事网
  • 网站建设 南京友情链接交换的作用在于
  • 移动医护网站建设利弊seo排名的职位
  • 外贸网站建设入门百度推广一年要多少钱
  • 潍坊网站建设wfyckj友情链接是什么意思
  • 怎么投诉网站制作公司绍兴seo计费管理
  • 薪火相传网站建设一份完整的电商运营方案
  • 现在做个人网站seo实战密码第三版pdf下载
  • 长沙做网站有哪些百度网址是多少
  • 佛山制作做网站bt鹦鹉磁力
  • 百度 网站地图怎么做北京网站营销与推广
  • 深圳市招聘信息网站app推广软件有哪些
  • dede产品展示网站模板百度快快速排名
  • 武汉大墨迹试试网站开发百度关键词排名批量查询