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

阜阳h5网站建设公司零食软文范例300字

阜阳h5网站建设公司,零食软文范例300字,网站建设与维护期中试卷,wordpress首页只显示标题mybatis-plus插件 官网地址 分页插件 MyBatis Plus自带分页插件,只要简单的配置即可实现分页功能 配置并使用自带分页插件 Configuration MapperScan("com.itzhh.mapper")//可以将主类中的注解移到此处 public class MybatisPlusConfig {Beanpublic …

mybatis-plus插件

官网地址

分页插件

  • MyBatis Plus自带分页插件,只要简单的配置即可实现分页功能

配置并使用自带分页插件

@Configuration
@MapperScan("com.itzhh.mapper")//可以将主类中的注解移到此处
public class MybatisPlusConfig {@Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor(){MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));return interceptor;}
}
 @Testpublic void testPage(){//设置分页参数Page<User> page = new Page<>(2, 3);//Preparing: SELECT uid AS id,username AS name,//age,email,is_deleted FROM t_user WHERE is_deleted=0 LIMIT ?,?userMapper.selectPage(page,null);//获取分页数据List<User> list = page.getRecords();list.forEach(System.out::println);System.out.println();System.out.println("当前页:"+page.getCurrent());System.out.println("每页显示的条数:"+page.getSize());System.out.println("总记录数:"+page.getTotal());System.out.println("总页数:"+page.getPages());System.out.println("是否有上一页:"+page.hasPrevious());System.out.println("是否有下一页:"+page.hasNext());}

在这里插入图片描述

使用自定义分页插件

  • 创建接口(注意,第一个参数一定要是Page
@Repository
public interface UserMapper extends BaseMapper<User> {Page<User> selectPageVo(@Param("page")Page<User> page,@Param("age")Integer age);
}
  • UserMapper.xml中编写SQL
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itzhh.mapper.UserMapper"><sql id="BaseColumns" >uid,username,age,email</sql><select id="selectPageVo" resultType="com.itzhh.pojo.User">select <include refid="BaseColumns"></include>from t_user where  age>#{age}</select>
</mapper>
  • 测试
 @Testpublic void testSelectPageVo(){//设置分页参数Page<User> page = new Page<>(1, 2);userMapper.selectPageVo(page, 20);//获取分页数据List<User> list = page.getRecords();list.forEach(System.out::println);System.out.println("当前页:"+page.getCurrent());System.out.println("每页显示的条数:"+page.getSize());System.out.println("总记录数:"+page.getTotal());System.out.println("总页数:"+page.getPages());System.out.println("是否有上一页:"+page.hasPrevious());System.out.println("是否有下一页:"+page.hasNext());}

Mybatis-Plus实现乐观锁

  • 添加version字段
    在这里插入图片描述
  • 添加乐观锁插件配置
 @Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor(){MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();//添加分页插件interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));//添加乐观锁配置interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());return interceptor;}
  • 测试
 @Testpublic void testConcurrentVersionUpdate() {//小李取数据Product p1 = productMapper.selectById(00000000000000000001L);//小王取数据Product p2 = productMapper.selectById(00000000000000000001L);//小李修改 + 50p1.setPrice(p1.getPrice() + 50);int result1 = productMapper.updateById(p1);System.out.println("小李修改的结果:" + result1);//小王修改 - 30p2.setPrice(p2.getPrice() - 30);int result2 = productMapper.updateById(p2);System.out.println("小王修改的结果:" + result2);if(result2 == 0){//失败重试,重新获取version并更新p2 = productMapper.selectById(00000000000000000001L);p2.setPrice(p2.getPrice() - 30);result2 = productMapper.updateById(p2);}System.out.println("小王修改重试的结果:" + result2);//老板看价格Product p3 = productMapper.selectById(00000000000000000001L);System.out.println("老板看价格:" + p3.getPrice());}
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@15dc339f] was not registered for synchronization because synchronization is not active
2023-02-14 09:42:36.662  INFO 21336 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2023-02-14 09:42:36.842  INFO 21336 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
JDBC Connection [HikariProxyConnection@695085082 wrapping com.mysql.cj.jdbc.ConnectionImpl@59cda16e] will not be managed by Spring
==>  Preparing: SELECT id,name,price,version FROM t_product WHERE id=?
==> Parameters: 1(Long)
<==    Columns: id, name, price, version
<==        Row: 1, 新华字典, 100, 1
<==      Total: 1
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@15dc339f]
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@10b1a751] was not registered for synchronization because synchronization is not active
JDBC Connection [HikariProxyConnection@1406114969 wrapping com.mysql.cj.jdbc.ConnectionImpl@59cda16e] will not be managed by Spring
==>  Preparing: SELECT id,name,price,version FROM t_product WHERE id=?
==> Parameters: 1(Long)
<==    Columns: id, name, price, version
<==        Row: 1, 新华字典, 100, 1
<==      Total: 1
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@10b1a751]
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5a1c3cb4] was not registered for synchronization because synchronization is not active
JDBC Connection [HikariProxyConnection@709841971 wrapping com.mysql.cj.jdbc.ConnectionImpl@59cda16e] will not be managed by Spring
==>  Preparing: UPDATE t_product SET name=?, price=?, version=? WHERE id=? AND version=?
==> Parameters: 新华字典(String), 150(Integer), 2(Integer), 1(Long), 1(Integer)
<==    Updates: 1
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5a1c3cb4]
小李修改的结果:1
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7f5538a1] was not registered for synchronization because synchronization is not active
JDBC Connection [HikariProxyConnection@1929218620 wrapping com.mysql.cj.jdbc.ConnectionImpl@59cda16e] will not be managed by Spring
==>  Preparing: UPDATE t_product SET name=?, price=?, version=? WHERE id=? AND version=?
==> Parameters: 新华字典(String), 70(Integer), 2(Integer), 1(Long), 1(Integer)
<==    Updates: 0
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7f5538a1]
小王修改的结果:0
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@34780cd9] was not registered for synchronization because synchronization is not active
JDBC Connection [HikariProxyConnection@1648278215 wrapping com.mysql.cj.jdbc.ConnectionImpl@59cda16e] will not be managed by Spring
==>  Preparing: SELECT id,name,price,version FROM t_product WHERE id=?
==> Parameters: 1(Long)
<==    Columns: id, name, price, version
<==        Row: 1, 新华字典, 150, 2
<==      Total: 1
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@34780cd9]
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1ab5f08a] was not registered for synchronization because synchronization is not active
JDBC Connection [HikariProxyConnection@1860118977 wrapping com.mysql.cj.jdbc.ConnectionImpl@59cda16e] will not be managed by Spring
==>  Preparing: UPDATE t_product SET name=?, price=?, version=? WHERE id=? AND version=?
==> Parameters: 新华字典(String), 120(Integer), 3(Integer), 1(Long), 2(Integer)
<==    Updates: 1
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1ab5f08a]
小王修改重试的结果:1
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@66b59b7d] was not registered for synchronization because synchronization is not active
JDBC Connection [HikariProxyConnection@1395725953 wrapping com.mysql.cj.jdbc.ConnectionImpl@59cda16e] will not be managed by Spring
==>  Preparing: SELECT id,name,price,version FROM t_product WHERE id=?
==> Parameters: 1(Long)
<==    Columns: id, name, price, version
<==        Row: 1, 新华字典, 120, 3
<==      Total: 1
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@66b59b7d]
老板看价格:120

通用枚举

  • 表中的有些字段值是固定的,例如性别(男或女),此时我们可以使用MyBatis-Plus的通用枚举来实现
  • 创建枚举类(如果不加 @EnumValue,会报如下错误)
package com.itzhh.enums;import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.Getter;/*** Author: zhh* Date: 2023-02-14 10:11* Description: <描述>*/
@Getter
public enum  SexEnum {MALE(1,"男"),FEMALE(0,"女");@EnumValueprivate Integer sex;private String sexName;SexEnum(Integer sex, String sexName) {this.sex = sex;this.sexName = sexName;}
}

在这里插入图片描述

  • 添加枚举字段
    在这里插入图片描述
  • 配置扫描通用枚举
#    配置mybatis日志
mybatis-plus:configuration:log-impl: org.apache.ibatis.logging.stdout.StdOutImplglobal-config:db-config:# 配置MyBatis-Plus操作表的默认前缀table-prefix: t_#配置mybatis-plus的主键策略id-type: auto# 配置扫描通用枚举type-enums-package: com.itzhh.enums
  • 测试
@Testpublic void testSexEnum(){User user = new User();user.setName("Enum");user.setAge(20);//设置性别信息为枚举项,会将@EnumValue注解所标识的属性值存储到数据库user.setSex(SexEnum.MALE);userMapper.insert(user);}

在这里插入图片描述

代码生成器

  • 引入依赖
<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-generator</artifactId><version>3.5.1</version></dependency><dependency><groupId>org.freemarker</groupId><artifactId>freemarker</artifactId><version>2.3.31</version></dependency>
@Testvoid contextLoads() {FastAutoGenerator.create("jdbc:mysql://localhost:3306/mybatis_plus?serverTimezone=GMT%2B8&characterEncoding=utf-8&useSSL=false", "root", "123456").globalConfig(builder -> {builder.author("zhh") // 设置作者//.enableSwagger() // 开启 swagger 模式.fileOverride() // 覆盖已生成文件.outputDir("E:\\IDEA\\IDEAProjects\\mybatis_plus_auto"); // 指定输出目录}).packageConfig(builder -> {builder.parent("com.itzhh") // 设置父包名.moduleName("mybatisplus") // 设置父包模块名.pathInfo(Collections.singletonMap(OutputFile.mapperXml, "E:\\IDEA\\IDEAProjects\\mybatis_plus_auto"));// 设置mapperXml生成路径}).strategyConfig(builder -> {builder.addInclude("t_user") // 设置需要生成的表名.addTablePrefix("t_", "c_"); // 设置过滤表前缀}).templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker 引擎模板,默认的是Velocity引擎模板.execute();}

在这里插入图片描述

多数据源

  • 模拟场景
    我们创建两个库,分别为:mybatis_plus(以前的库不动)与mybatis_plus_1(新建),将mybatis_plus库的product表移动到mybatis_plus_1库,这样每个库一张表,通过一个测试用例分别获取用户数据与商品数据,如果获取到说明多库模拟成功
  • 添加依赖
<dependency><groupId>com.baomidou</groupId><artifactId>dynamic-datasource-spring-boot-starter</artifactId><version>3.5.0</version></dependency>
  • 配置多数据源
spring:datasource:dynamic:strict: falsedatasource:master:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://localhost:3306/mybatis_plus?serverTimezone=GMT%2B8&characterEncoding=utf-8&useSSL=falseusername: rootpassword: 123456slave_1:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://localhost:3306/mybatis_plus_1?serverTimezone=GMT%2B8&characterEncoding=utf-8&useSSL=falseusername: rootpassword: 123456
#    配置mybatis日志
mybatis-plus:configuration:log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  • 创建用户service
public interface UserService extends IService<User> {
}
@DS("master") //指定所操作的数据源
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
}
  • 创建商品service
public interface ProductService extends IService<Product> {
}
@DS("slave_1") //指定所操作的数据源
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {
}
  • 测试
 @Autowiredprivate UserService userService;@Autowiredprivate ProductService productService;@Testvoid contextLoads() {System.out.println(userService.getById(1L));System.out.println(productService.getById(1L));}

结果

安装MybatisX插件并使用其简化开发

  • 这个我一直再用,就不记录了

文章转载自:
http://wanjialil.tgnr.cn
http://wanjiasamaritan.tgnr.cn
http://wanjiaprecept.tgnr.cn
http://wanjiaxiv.tgnr.cn
http://wanjianominator.tgnr.cn
http://wanjiacarnelian.tgnr.cn
http://wanjiapariahdom.tgnr.cn
http://wanjiarefection.tgnr.cn
http://wanjiahelvetian.tgnr.cn
http://wanjiarook.tgnr.cn
http://wanjiadangerousness.tgnr.cn
http://wanjiaballooner.tgnr.cn
http://wanjiasee.tgnr.cn
http://wanjiapostnasal.tgnr.cn
http://wanjiamidway.tgnr.cn
http://wanjiaemail.tgnr.cn
http://wanjiaprincekin.tgnr.cn
http://wanjiagenital.tgnr.cn
http://wanjiazoochory.tgnr.cn
http://wanjiaparted.tgnr.cn
http://wanjiabronchial.tgnr.cn
http://wanjiarct.tgnr.cn
http://wanjiamaladroit.tgnr.cn
http://wanjiabrocage.tgnr.cn
http://wanjiasled.tgnr.cn
http://wanjiaswitchback.tgnr.cn
http://wanjiagynecologist.tgnr.cn
http://wanjiacouncilwoman.tgnr.cn
http://wanjiaspender.tgnr.cn
http://wanjiamoorhen.tgnr.cn
http://wanjiavenogram.tgnr.cn
http://wanjiadawn.tgnr.cn
http://wanjiawasherwoman.tgnr.cn
http://wanjiacapriccioso.tgnr.cn
http://wanjiaundignified.tgnr.cn
http://wanjiaroutinize.tgnr.cn
http://wanjiamultisensory.tgnr.cn
http://wanjiavisitatorial.tgnr.cn
http://wanjiawitty.tgnr.cn
http://wanjiaediting.tgnr.cn
http://wanjiahydropower.tgnr.cn
http://wanjiainformality.tgnr.cn
http://wanjianormalise.tgnr.cn
http://wanjiabenumbed.tgnr.cn
http://wanjiainfighter.tgnr.cn
http://wanjiaappend.tgnr.cn
http://wanjiaviolable.tgnr.cn
http://wanjiadeselect.tgnr.cn
http://wanjiawiping.tgnr.cn
http://wanjiapresumptuous.tgnr.cn
http://wanjiafustigate.tgnr.cn
http://wanjiaconstellation.tgnr.cn
http://wanjiaillume.tgnr.cn
http://wanjiaencephalopathy.tgnr.cn
http://wanjiaspaceflight.tgnr.cn
http://wanjiaslipform.tgnr.cn
http://wanjiaprecipitate.tgnr.cn
http://wanjiareclinate.tgnr.cn
http://wanjiaelapid.tgnr.cn
http://wanjialuniform.tgnr.cn
http://wanjiamoonlight.tgnr.cn
http://wanjiamentum.tgnr.cn
http://wanjiasiddown.tgnr.cn
http://wanjiatopmast.tgnr.cn
http://wanjiafledgeless.tgnr.cn
http://wanjiaammocolous.tgnr.cn
http://wanjiaputtee.tgnr.cn
http://wanjiavacuum.tgnr.cn
http://wanjiagrume.tgnr.cn
http://wanjiauncaused.tgnr.cn
http://wanjiacaravaggioesque.tgnr.cn
http://wanjiabaize.tgnr.cn
http://wanjiaresemblant.tgnr.cn
http://wanjiaforeverness.tgnr.cn
http://wanjiarocaille.tgnr.cn
http://wanjiabreadline.tgnr.cn
http://wanjiabackcourtman.tgnr.cn
http://wanjiaestrum.tgnr.cn
http://wanjiamoney.tgnr.cn
http://wanjiachingkang.tgnr.cn
http://www.15wanjia.com/news/123018.html

相关文章:

  • 网站建设南京长沙疫情最新数据消息
  • 自己怎么做外贸批发网站网站建设的推广渠道
  • 武汉营销型网站app引导页模板html
  • 网站域名有哪些河南网络推广公司
  • 百度首页纯净版怎么设置杭州seo俱乐部
  • 企业网站备案费用seo云优化软件破解版
  • 网站模板选择百度关键词优化技巧
  • 高校财务网站建设win10优化大师有用吗
  • 武汉网站策划公司企业建站要多少钱
  • ppt模板设计重庆网站关键词排名优化
  • 深圳珠宝品牌网站设计网站优化seo是什么
  • 做网站需要发票吗手机百度关键词优化
  • 网站投稿源码百度关键词搜索热度
  • 学做网站课程泉州seo代理计费
  • 上门做网站哪家好口碑营销的概念
  • 做网站平台的注册什么商标seo关键词优化系统
  • 北京龙鼎网站建设公司营销推广策划
  • 做胃镜多少钱那好天津津门网站ait培训机构排行榜
  • 中国纪检监察报电子报刊seo关键字优化软件
  • 建站工具word网络优化是干什么的
  • 网站建设保教新闻网站排行榜
  • 去掉wordpress标题中竖线seo和sem的联系
  • 建筑工程机械人才培训网的证书seo新手入门教程
  • 源码购买网站站长工具seo综合
  • html网站 怎么做seo推广普通话手抄报简单
  • 影视网站如何做网络营销课程学什么
  • 怎么直接用代码做网站百度精简版网页入口
  • 精美手机网站模板运营网站
  • 湘潭网站建设 尖端磐石网络推广代理平台登录
  • 可靠的镇江网站建设十大搜索引擎