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

app网站开发报价湖南禹班建设集团有限公司网站

app网站开发报价,湖南禹班建设集团有限公司网站,网站兼容怎么调,机械设备怎样做网络推广MyBatis Generator附批量操作分页查询存储过程 Generator 介绍网址#xff1a;Introduction to MyBatis Generator Generator #xff0c;一个用于 MyBatis 的代码生成工具#xff0c;可以根据数据库表结构自动生成对应的实体类、DAO 接口和 SQL 映射文件#xff0c;提高… MyBatis Generator附批量操作分页查询存储过程 Generator 介绍网址Introduction to MyBatis Generator Generator 一个用于 MyBatis 的代码生成工具可以根据数据库表结构自动生成对应的实体类、DAO 接口和 SQL 映射文件提高开发效率和代码质量。同时MyBatis Generator 还支持自定义生成规则可以按照自己的需求进行配置。 简单示例 首先在 pom.xml 中添加依赖 !-- https://mvnrepository.com/artifact/org.mybatis.generator/mybatis-generator-core -- dependencygroupIdorg.mybatis.generator/groupIdartifactIdmybatis-generator-core/artifactIdversion1.4.0/version /dependency接着在 resources 目录下创建一个 Generator 的配置文件 mybatis_generator.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.dtdgeneratorConfigurationcontext idDB2Tables targetRuntimeMyBatis3commentGenerator!-- 是否去除自动生成的注释 --property namesuppressAllComments valuetrue //commentGenerator!-- MySQL数据库连接的信息驱动类、连接地址、用户名、密码 --jdbcConnection driverClasscom.mysql.cj.jdbc.DriverconnectionURLjdbc:mysql://localhost:3306/mybatisdemo?useUnicodetrueamp;characterEncodingutf8amp;useSSLfalseamp;serverTimezoneUTCuserIdrootpassword0123 /!-- Java 类型解析器一般默认为 false --javaTypeResolverproperty nameforceBigDecimals valuefalse //javaTypeResolver!-- Domain 生成器生成实体类。属性 targetProject 生成 POJO 类的位置其余默认 --javaModelGenerator targetPackagecn.edu.MyBatisDemo.model targetProject.\src\main\java /!-- Mapping 生成器生成映射文件。属性 targetProject mapper 映射文件生成的位置其余默认 --sqlMapGenerator targetPackagecn.edu.MyBatisDemo.mapper targetProject.\src\main\java!-- enableSubPackages :是否让 schema 作为包的后缀 --property nameenableSubPackages valuetrue //sqlMapGenerator!-- Mapper 生成器生成接口。targetProject 属性mapper 接口生成的的位置 --javaClientGenerator typeXMLMAPPER targetPackagecn.edu.MyBatisDemo.mapper targetProject.\src\main\java!-- enableSubPackages :是否让 schema 作为包的后缀 --property nameenableSubPackages valuetrue //javaClientGenerator!-- 指定数据表。tableName 属性指定数据库的表名domainObjectName 属性生成对应实体类的名字...Example 属性设置关闭即可 --table tableNamemybatis_generatordomainObjectNameMyBatisGeneratorenableCountByExamplefalseenableUpdateByExamplefalseenableDeleteByExamplefalseenableSelectByExamplefalseselectByExampleQueryIdfalse //context/generatorConfiguration然后只需在数据库中创建一个数据表 mybatis_generator 。表名称需要与 mybatis_generator.xml 的 table 标签中的 tableName 属性值对应 表结构信息如图 最后测试结果 package cn.edu.MyBatisDemo.test;import org.junit.Test; import org.mybatis.generator.api.MyBatisGenerator; import org.mybatis.generator.config.Configuration; import org.mybatis.generator.config.xml.ConfigurationParser; import org.mybatis.generator.exception.InvalidConfigurationException; import org.mybatis.generator.exception.XMLParserException; import org.mybatis.generator.internal.DefaultShellCallback;import java.io.File; import java.io.IOException; import java.sql.SQLException; import java.util.ArrayList; import java.util.List;public class MyBatisGeneratorTest {Testpublic void mbgTest() throws IOException, XMLParserException, InvalidConfigurationException, SQLException, InterruptedException {ListString warnings new ArrayListString();boolean overwrite true;// 只需修改 Generator 的配置文件名称即可String path this.getClass().getClassLoader().getResource(mybatis_generator.xml).getPath();File configFile new File(path);ConfigurationParser cp new ConfigurationParser(warnings);Configuration config cp.parseConfiguration(configFile);DefaultShellCallback callback new DefaultShellCallback(overwrite);MyBatisGenerator myBatisGenerator new MyBatisGenerator(config, callback, warnings);myBatisGenerator.generate(null);} }结果如图实体类、接口与映射文件会自动生成在设定的目录下 接口中声明一系列方法介绍如图 附 在上面案例的基础下简单实现批量操作与分页查询。 批量操作 首先在实体类 MyBatisGenerator 中添加无参构造方法、有参构造方法与 toString() 方法 public MyBatisGenerator() {super(); }public MyBatisGenerator(Integer id, String name, Integer age, String hobby, String career) {this.id id;this.name name;this.age age;this.hobby hobby;this.career career; }Override public String toString() {return MyBatisGenerator{ id id , name name \ , age age , hobby hobby \ , career career \ }; }然后在测试类 MyBatisGenerator 中添加批量操作测试方法 Test public void test() throws IOException {//1.根据配置文件创建数据库连接会话的工厂类InputStream inputStream Resources.getResourceAsStream(mybatis.xml);//获取工厂类SqlSessionFactory sqlSessionFactory new SqlSessionFactoryBuilder().build(inputStream);//2.通过工厂类获取数据库连接的会话SqlSession sqlSession sqlSessionFactory.openSession(ExecutorType.BATCH);//3.通过 sqlSession 操作数据库try {MyBatisGeneratorMapper myBatisGeneratorMapper sqlSession.getMapper(MyBatisGeneratorMapper.class);for (int i 0 ; i 36 ; i){//实体类的名字 MyBatisGenerator 与导入的 org.mybatis.generator.api.MyBatisGenerator 名字重复。故此写上 cn.edu.MyBatisDemo.model.myBatisGeneratorMapper.insert(new cn.edu.MyBatisDemo.model.MyBatisGenerator(20230901i,Qi,18,看书,歌手));}sqlSession.commit();} finally {sqlSession.close();} }注在创建会话中传入参数 ExecutorType.BATCH设定采用批量操作的方式执行 SQL 语句 最后测试结果 结果如图 分页查询 MyBatis 分页插件 PageHelper 作者 — isea533 Mybatis-PageHelper 网址 首先在 pom.xml 中添加依赖 dependencygroupIdcom.github.pagehelper/groupIdartifactIdpagehelper/artifactIdversion5.3.2/version /dependency接着在全局配置文件 mybatis.xml 中配置插件 !-- plugins 标签需要在 environments 标签前 -- pluginsplugin interceptorcom.github.pagehelper.PageInterceptor/plugin /plugins然后在接口 MyBatisGeneratorMapper 中声明获取所有用户信息的方法。同时在映射文件 MyBatisGeneratorMapper.xml 中实现方法 select idselectAll resultTypemyBatisGenerator selectinclude refidBase_Column_List /from mybatis_generator /select最后测试结果 存储过程 在 MySQL调优 文章中了解过存储过程。接下来简单介绍 MyBatis 如何调用存储过程。 首先创建一个存储过程 mybatis_generator_storedProcedure DELIMITER $$CREATE/*[DEFINER { user | CURRENT_USER }]*/PROCEDURE mybatisdemo.mybatis_generator_storedProcedure(IN start_id INT,IN end_id INT)BEGINSELECT id,name,age,hobby,career FROM mybatis_generator WHERE id start_id AND id end_id;END$$DELIMITER ;然后在接口 MyBatisGeneratorMapper 中声明通过调用存储过程获取指定用户信息的方法。同时在映射文件 MyBatisGeneratorMapper.xml 中实现方法 public ListMyBatisGenerator selectByStoredProcedure(Param(start_id) int start_id,Param(end_id) int end_id); //通过调用存储过程获取指定用户的信息!-- 指定 statementType 属性值为 CALLABLE -- select idselectByStoredProcedure resultTypemyBatisGenerator statementTypeCALLABLE {call mybatis_generator_storedProcedure(#{start_id,modeIN,jdbcTypeINTEGER},#{end_id,modeIN,jdbcTypeINTEGER})} /select最后测试结果
http://www.hkea.cn/news/14422118/

相关文章:

  • 上海著名的网站制作公司域名与网站
  • asp网站安全常见的推广平台有哪些
  • 自助建站实验报告西安网站开发服务多少钱
  • 百度收录提交入口网址seo优化技术
  • 大新网站制作成都铁路局贵阳建设指挥部网站
  • 番禺网站建设哪家好深圳燃气公司是国企吗
  • 怎么自己在微信上做网站内部建设网站需要什么条件
  • 学做网站零基础阿里云 网站备案
  • 佛山新网站制作代理商网站建设类的职位
  • 福建富通建设有限公司网站重庆网络安全公司
  • wifi管理网站会计证继续教育在哪个网站做
  • 企业门户网站建设流程重庆网站排名公司
  • wordpress最大发布大小排名优化seo
  • 建设的招标网站创建论坛网站需要多少钱
  • 中山论坛建站模板重庆seo网站运营
  • 手机端视频网站模板下载网站更新的意义
  • 国家重点项目建设部网站机械网站建设中心
  • 网站集约化后如何建设励志响亮的建筑公司名
  • 租用微信做拍卖网站家装公司报价
  • 自己有网站怎么推广iis管理器添加网站
  • 网站域名不合法西安网站建设g
  • 做网站有哪些项目南宁平台公司
  • 学校网站结构图快速做网站
  • 网站原型用wampserver搭建网站
  • asp网站伪静态规则银川做网站服务
  • 电子商务网站是什么意思网站建设现状分析
  • 电子商务网站建设计划如何维护自己公司网站
  • 做网站卖专业卖文玩建筑网站汇总
  • 江西省建设工程安全质量监督管理局网站免费企业静态网站模板
  • 网站的市场如何制作做网站怎么弄