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

网站的邀请怎么做的云速成美站

网站的邀请怎么做的,云速成美站,贵州省建设厅网站公众一体化平台,asp网站建设 iis配置一、MyBatis Generator 为 MyBastis 框架设计的代码生成工具#xff0c;简化持久层编码工作。根据数据库表自动生成 Java 实体类、Mapper 接口、SQL 的 xml 文件。让开发者专注于业务逻辑。 1、引入插件 MyBatis 官网搜索 MyBatis Generator 插件#xff1a;Running MyBatis…一、MyBatis Generator 为 MyBastis 框架设计的代码生成工具简化持久层编码工作。根据数据库表自动生成 Java 实体类、Mapper 接口、SQL 的 xml 文件。让开发者专注于业务逻辑。 1、引入插件 MyBatis 官网搜索 MyBatis Generator 插件Running MyBatis Generator With Maven – MyBatis Generator Corehttps://mybatis.org/generator/running/runningWithMaven.html plugingroupIdorg.mybatis.generator/groupIdartifactIdmybatis-generator-maven-plugin/artifactIdversion1.3.6/versionexecutionsexecutionidGenerate MyBatis Artifacts/idphasedeploy/phasegoalsgoalgenerate/goal/goals/execution/executionsconfiguration!--generator配置文件所在位置--configurationFilesrc/main/resources/generator/generatorConfig.xml/configurationFile!-- 允许覆盖生成的文件xml不会覆盖, 采用追加的方式--overwritetrue/overwriteverbosetrue/verbose!--将当前pom的依赖项添加到生成器的类路径中--includeCompileDependenciestrue/includeCompileDependencies/configuration!--该插件的依赖在 dependencies 中引入的它识别不到--dependenciesdependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactIdversion8.0.33/version/dependency/dependencies/plugin 2、修改 generatorConfig.xml 文件 ?xml version1.0 encodingUTF-8? !DOCTYPE generatorConfigurationPUBLIC -//mybatis.org//DTD MyBatis Generator Configuration 1.0//ENhttp://mybatis.org/dtd/mybatis-generator-config_1_0.dtd !-- 配置生成器 -- generatorConfiguration!-- 一个数据库一个context --context idMysqlTables targetRuntimeMyBatis3Simple!--禁用自动生成的注释--commentGeneratorproperty namesuppressDate valuetrue/property namesuppressAllComments valuetrue //commentGenerator!--数据库连接信息--jdbcConnection driverClasscom.mysql.jdbc.DriverconnectionURLjdbc:mysql://127.0.0.1:3306/book_test?serverTimezoneAsia/Shanghaiamp;nullCatalogMeansCurrenttrueuserIdrootpasswordroot/jdbcConnection!-- 生成实体类, 配置路径 --javaModelGenerator targetPackagecom.edu.generator.model targetProjectsrc/main/java property nameenableSubPackages valuefalse/property nametrimStrings valuetrue//javaModelGenerator!-- 生成mapxml文件 --sqlMapGenerator targetPackagegeneratorMapper targetProjectsrc/main/resources property nameenableSubPackages valuefalse //sqlMapGenerator!-- 生成mapxml对应client也就是接口dao --javaClientGenerator targetPackagecom.edu.generator.mapper targetProjectsrc/main/java typeXMLMAPPER property nameenableSubPackages valuefalse //javaClientGenerator!-- table可以有多个,tableName表示要匹配的数据库表 --table tableNameuser_info domainObjectNameUserInfo enableSelectByExampletrueenableDeleteByExampletrue enableDeleteByPrimaryKeytrue enableCountByExampletrueenableUpdateByExampletrue!-- 类的属性是否用数据库中的真实字段名做为属性名, 不指定这个属性会自动转换 _ 为驼峰命名规则 --property nameuseActualColumnNames valuefalse /!-- 数据库表主键 --generatedKey columnid sqlStatementMysql identitytrue //tabletable tableNamebook_info domainObjectNameBookInfo enableSelectByExampletrueenableDeleteByExampletrue enableDeleteByPrimaryKeytrue enableCountByExampletrueenableUpdateByExampletrue!-- 类的属性是否用数据库中的真实字段名做为属性名, 不指定这个属性会自动转换 _ 为驼峰命名规则 --property nameuseActualColumnNames valuefalse /!-- 数据库表主键 --generatedKey columnid sqlStatementMysql identitytrue //table/context /generatorConfiguration targetRuntimeMyBatis3SimpleMyBatis3Simple 生成的 SQL 的 xml 语句比较简单MyBatis3 比较复杂。targetPackagecom.edu.generator.model生成在哪个包。tableNameuser_info数据库对应的表名。domainObjectNameBookInfo对应的实体类名。generatedKey columnid主键名。property nameuseActualColumnNames valuefalse /属性名自动转换成驼峰命名规则。 只生成实体类的版本 ?xml version1.0 encodingUTF-8? !DOCTYPE generatorConfigurationPUBLIC -//mybatis.org//DTD MyBatis Generator Configuration 1.0//ENhttp://mybatis.org/dtd/mybatis-generator-config_1_0.dtd !-- 配置生成器 -- generatorConfiguration!-- 一个数据库一个context --context idMysqlTables targetRuntimeMyBatis3Simple!-- 禁用自动生成的注释 --commentGeneratorproperty namesuppressDate valuetrue/property namesuppressAllComments valuetrue //commentGenerator!-- 数据库连接信息 --jdbcConnection driverClasscom.mysql.jdbc.DriverconnectionURLjdbc:mysql://127.0.0.1:3306/mybatis_test?serverTimezoneAsia/Shanghaiamp;nullCatalogMeansCurrenttrueuserIdrootpassword123456/jdbcConnection!-- 生成实体类配置 --javaModelGenerator targetPackagecom.edu.mybatis.plus.model targetProjectsrc/main/java property nameenableSubPackages valuefalse/property nametrimStrings valuetrue//javaModelGenerator!-- 移除SQL映射文件生成器不生成Mapper XML --!-- 移除Java客户端生成器不生成Mapper接口 --!-- 表配置 --table tableNameuser_info domainObjectNameUserInfoproperty nameuseActualColumnNames valuefalse /generatedKey columnid sqlStatementMysql identitytrue //table/context /generatorConfiguration3、生成代码 在 maven 中运行插件自动生成代码 生成的文件 实体类把 getter、setter 都生成了为了好看可以调整为 Data Mapper 接口、xml 文件生成了一些基础的数据库操作。不建议用mxl 文件代码太乱了看着很复杂 该插件的使用需要配置很多东西比如数据库连接的信息但是这些信息已经在 spring boot 的配置文件中配置过了因此该插件还不够方便。对于 mapper、xml 的编写Mybatis-plus 框架才是我们学习的重点。用用 MyBatis Generator 的实体类自动生成即可。 二、MyBatis-plus MyBatis-plus 在 MyBatis 的基础上扩展功能跟 MyBatis 不冲突。直接在 Spring Boot 项目的POM 文件中引入依赖即可。 官方文档 快速开始 | MyBatis-Plushttps://baomidou.com/getting-started/ 1、快速上手 创建一个 Spring Boot 项目 引入依赖spring boot3 对应的版本 dependencygroupIdcom.baomidou/groupIdartifactIdmybatis-plus-spring-boot3-starter/artifactIdversion3.5.12/version /dependency 配置数据库连接信息.yml。 在启动类中加入 MapperScan指定要扫描的 Mapper 文件路径。或者每个 mapper 类加上 Mapper二选其一。 创建要操作的表对应的实体类。 编写 Mapper 接口类 2、简单 CRUD 单元测试 1查 Testpublic void testSelectAll() {System.out.println((----- 查询所有 ------));ListUserInfo userList userInfoMapper.selectList(null);userList.forEach(System.out::println);}Testvoid testSelectById(){System.out.println((----- 按 主键 查询 ------));UserInfo userInfo userInfoMapper.selectById(2);System.out.println(userInfo);}Testvoid testSelectByIds(){System.out.println((----- 按 主键 集合查询 ------));ListUserInfo userInfos userInfoMapper.selectByIds(List.of(1,2));userInfos.forEach(System.out::println);} 2增 Testvoid testInsert(){System.out.println((----- 插入一条数据 ------));UserInfo userInfo new UserInfo();userInfo.setUserName(Jay);userInfo.setPassword(Chou);int insert userInfoMapper.insert(userInfo);System.out.println(影响行数: insert);} id 生成了随机数 想自增需要使用 TableId 设置 id 会从最大值 2 开始自增 如果想修改最大值表上右键 设计表 选项 修改 3改 Testvoid testUpdate(){System.out.println((----- 按 主键 更新一条数据 ------));UserInfo userInfo new UserInfo();userInfo.setId(2);userInfo.setUserName(lisi);userInfo.setDeleteFlag(1);userInfoMapper.updateById(userInfo);} 4删 Testvoid testDelete(){System.out.println((----- 按 主键 删除一条数据 ------));userInfoMapper.deleteById(-2019921918);} 3、命名映射注解 MyBatis-plus 如何将类名、属性名与数据库表、主键字段、普通字段对应 根据实体类名推断表名。TableName默认 id 属性是主键。TableId驼峰规则的属性名对应的蛇形命名就是表字段。TableField如果 java 命名不符合自动对应的的规则可以用注解进行绑定。 4、打印日志 把 mybatis 改成 mybatis-plus 即可 mybatis-plus:configuration: # 配置打印 MyBatis ⽇志log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 5、自动生成代码了解 参考代码生成器 | MyBatis-Plus 引入依赖generator 模板引擎 dependencygroupIdcom.baomidou/groupIdartifactIdmybatis-plus-generator/artifactIdversion3.5.12/version/dependencydependencygroupIdorg.freemarker/groupIdartifactIdfreemarker/artifactIdversion2.3.31/version/dependency 自动生成代码 ​public void test() {FastAutoGenerator.create(jdbc:mysql://127.0.0.1:3306/book_test?characterEncodingutf8 useSSLfalseallowPublicKeyRetrievaltrue,root, 123456).globalConfig(builder - builder.outputDir(Paths.get(System.getProperty(user.dir)) /src/main/java)).packageConfig(builder - builder.parent(com.edu.mybatis.plus.generator).entity(entity).mapper(mapper).service(service).xml(mapper.xml)).strategyConfig(builder - builder.entityBuilder().enableLombok()).templateEngine(new FreemarkerTemplateEngine()).execute();}​ 6、复杂 CRUD 操作 1什么是条件构造器 条件构造器Wrapper 类允许链式构造条件用 . 的方式直接引用条件构造方法避免编写复杂 SQL同时减少 SQL 注入风险。 AbstractWrapper抽象类提供 Wrapper 类共有的方法和属性。QueryWrapper构造查询条件。UpdateWrapper构造更新条件可以不用构造实体类设置 set。LambdaQueryWrapper基于 Lambda 表达式构造查询条件。LambdaUpdateWrapper基于 Lambda 表达式构造更新条件。 AbstractWrapper 实现了 Compare 接口包含了各种条件构造器比如大于、等于、模糊查询等这些操作是四种 Wrapper 共有的更多详情参考官方文档 (Lambda)QueryWrapper 和 (Lambda)UpdateWrapper 的不同之处就是红框的部分。绿框是构造函数其余方法都是差不多一样的。 2QueryWrapper 增删改查都能用 QueryWrapper 实现。 查询 SELECT id,user_name,password FROM user_info WHERE delete_flag 0 AND user_name LIKE %min% Testvoid testQueryWrapper(){QueryWrapperUserInfo queryWrapper new QueryWrapper();queryWrapper.select(id, user_name, password).eq(delete_flag, 0).like(user_name, min);ListUserInfo userList userInfoMapper.selectList(queryWrapper);userList.forEach(System.out::println);} 更新需要构造实体类设置修改值。 UPDATE user_info SET delete_flag1 WHERE id 3 Testvoid testQueryWrapper2(){QueryWrapperUserInfo queryWrapper new QueryWrapper();UserInfo userInfo new UserInfo();userInfo.setDeleteFlag(1);queryWrapper.lt(id, 3);userInfoMapper.update(userInfo, queryWrapper);} 删 DELETE FROM user_info WHERE user_name Jay2 Testvoid testQueryWrapper3(){QueryWrapperUserInfo queryWrapper new QueryWrapper();queryWrapper.eq(user_name, Jay2);userInfoMapper.delete(queryWrapper);} 3UpdateWrapper 更新不用构造实体类直接 set。 UPDATE user_info SET delete_flag0 WHERE id IN (1,2) Testvoid testUpdateWrapper(){UpdateWrapperUserInfo updateWrapper new UpdateWrapper();updateWrapper.set(delete_flag, 0).in(id, List.of(1,2));userInfoMapper.update(updateWrapper);} 直接 set sql 语句更新 UPDATE user_info SET delete_flagdelete_flag1 WHERE id IN (1,2) Testvoid testUpdateWrapper2(){UpdateWrapperUserInfo updateWrapper new UpdateWrapper();updateWrapper.setSql(delete_flag delete_flag 1).in(id, List.of(1,2));userInfoMapper.update(updateWrapper);} 4LambdaQueryWrapper 字段名容易写错Lambda 的版本就是用 实体类名::get属性名来替代字段名字符串。 可以直接 new Lambda 版本或者 new 普通版本再使用 lambda 方法转为 Lambda 版本。 SQL SELECT id,user_name,password FROM user_info WHERE delete_flag 0 AND user_name LIKE %min% Testvoid testLambdaQueryWrapper(){ // LambdaQueryWrapperUserInfo lambdaQueryWrapper new LambdaQueryWrapper();QueryWrapperUserInfo queryWrapper new QueryWrapper();queryWrapper.lambda().select(UserInfo::getId, UserInfo::getUserName, UserInfo::getPassword).eq(UserInfo::getDeleteFlag, 0).like(UserInfo::getUserName, min);ListUserInfo userList userInfoMapper.selectList(queryWrapper);userList.forEach(System.out::println);} 5LambdaUpdateWrapper SQL UPDATE user_info SET delete_flag0 WHERE id IN (1,2) Testvoid testLambdaUpdateWrapper(){UpdateWrapperUserInfo updateWrapper new UpdateWrapper();updateWrapper.lambda().set(UserInfo::getDeleteFlag, 1).in(UserInfo::getId, List.of(1,2));userInfoMapper.update(updateWrapper);} setIncrBy递增 setDecrBy递减 示例 UPDATE user_info SET delete_flag delete_flag 1 Testvoid testLambdaUpdateWrapper(){UpdateWrapperUserInfo updateWrapper new UpdateWrapper();updateWrapper.lambda().set(UserInfo::getDeleteFlag, 1).in(UserInfo::getId, List.of(1,2));userInfoMapper.update(updateWrapper);} 6自定义 SQL MyBatis-plus 框架提供的操作不能满足所有的需求我们可以利用 Wrapper 构造条件在 Mapper 自定义 SQL。 条件构造器传参参数名 ew 或者重命名 Param(Constants.WRAPPER)。 构造器使用${ew.customSqlSegment} 引用。 SQL select id,username,password FROM user_info WHERE user_name admin 注解方式 Select(SELECT id, user_name, password FROM user_info ${ew.customSqlSegment})UserInfo selectByCustom(Param(Constants.WRAPPER) WrapperUserInfo wrapper); XML 方式 select idselectByCustom2 resultTypecom.edu.mybatis.plus.model.UserInfoSELECT id, user_name, password FROM user_info ${ew.customSqlSegment}/select 测试代码 Testvoid testSelectByCustom(){QueryWrapperUserInfo queryWrapper new QueryWrapper();queryWrapper.lambda().eq(UserInfo::getUserName, admin);userInfoMapper.selectByCustom(queryWrapper);}
http://www.zqtcl.cn/news/391235/

相关文章:

  • 黑龙江做网站的公司上海企业网站建设公
  • 做公众号时图片的网站安徽建设工程造价信息网站
  • 网站开发的在淘宝上是什么类目深圳做网站的大公司
  • 手机网站 html5信阳哪里做网站
  • 网站服务器多少钱一月wordpress 博客宠物
  • 怎么制作网站游戏辽宁建设工程网
  • 网站开发好还要空间吗网站支付链接怎么做的
  • 网站制作报价图片欣赏杭州做网站价格
  • 帮人家做家务的网站host绑定网站
  • 地方门户网站盈利模式这样做微信网站
  • 企业网站要怎么做wordpress w3
  • 网站备案帐号找回密码seo优化工作有哪些
  • 美橙网站建设教程网站建站系统
  • 湖北网站建设公司哪家好重庆建站模板平台
  • 青岛企业建站最新上线的手游
  • 织梦网站wap精品下载
  • 专业做包装的电商网站搜索推广图片
  • 淘客网站佣金建设怎么制作网站页面
  • 网站数据库 mysql如何构建wordpress
  • 牙克石网站建设宁波pc营销型网站制作
  • 具有营销价值好的网站深圳工程建设服务网
  • 全flash网站源码app软件开发公司员工守则
  • 曹鹏wordpress建站seo视频本溪做网站的公司
  • 提示网站有风险老电脑做网站服务器
  • 怎么做网站导航外链出入青岛最新通知今天
  • 济宁房产网站建设海外电商怎么做如何从零开始
  • 网站优化插件中国建设银采购发文网站
  • 重庆企业网站的推广电力建设集团网站
  • 长沙制作网站词条有哪些网站可以做
  • 网站 网页区别简单的网页设计作品