mapper

MyBatis系列(二) MyBatis接口绑定与多参数传递

六月ゝ 毕业季﹏ 提交于 2019-12-16 12:19:27
前言 通过上一篇博文的,已经可以做到通过MyBatis连接数据库,现在再来介绍一种方法通过接口绑定SQL语句。 不使用接口绑定的方式 不使用接口绑定的方式,是通过调用SqlSession中的selectxxx方法,通过传递一个String类型的参数(通常为namespace的属性+SQLID),来寻找对应SQL文件中的参数。 测试类: //创建SqlSessionFactory对象,并指向全局配置文件mybatis-config.xml public SqlSessionFactory getSqlSessionFactory() throws IOException { String resource = "mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); return new SqlSessionFactoryBuilder().build(inputStream); } @Test public void test() throws IOException { //引用SqlSessionFactory对象 SqlSessionFactory sqlSessionFactory = getSqlSessionFactory(); /

Springboot整合Mybatis

孤者浪人 提交于 2019-12-16 10:43:39
概述 Springboot通过整合Mybatis对数据库进行相关操作,这里数据库连接池还是使用Springboot默认的连接池tomcat.jdbc.pool,我们不再配置Druid或者其他连接池,关于Springboot如何整合Druid或者其他连接池,后面鹏哥会给出。 整合 导入数据库驱动依赖 //数据库驱动 <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> //mybatis依赖 <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version> </dependency> 当然,依赖可以通过idea中的Sping插件创建项目时候快速选择即可,配置文件中配置数据源信息 #数据源 spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306

Mybatis无效邦定 mapper接口与xml同路径

≯℡__Kan透↙ 提交于 2019-12-16 02:19:25
检查路径都无问题但是却一直报错绑定无效 最后发现是因为xml文件没被编译进项目 gradle: sourceSets.main.resources.srcDirs = ["src/main/java","src/main/resources"] maven: <build> <resources> <!-- mapper.xml文件在java目录下 --> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> <!-- mapper.xml文件在resources目录下--> <--<resource> <directory>src/main/resources</directory> </resource>--> </resources> </build> 来源: CSDN 作者: getUserById 链接: https://blog.csdn.net/qq_38948514/article/details/103460568

linux lvs扩展

不羁岁月 提交于 2019-12-16 01:19:59
今天看到yum本地缓存源空间满了 [root@mirrors data]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 92G 6.9G 85G 8% / devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs tmpfs 1.9G 157M 1.7G 9% /run tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/mapper/vg_bricks-data xfs 498G 498G 6.6M 100% /data /dev/sda1 xfs 497M 321M 176M 65% /boot /dev/dm-8 xfs 10G 59M 10G 1% /var/lib/docker/devicemapper/mnt/bc4585e2e2be37994554223e3a8875910b20532293d1cd1c86af996357fdcb5e shm tmpfs 64M 0 64M 0% /var/lib/docker/containers

SpringBoot快速搭建流程

六眼飞鱼酱① 提交于 2019-12-15 23:27:20
创建一个新项目 使用maven创建一个新项目 给定项目名称、finsh完成创建 跑起来SpringBoot 引入依赖parent > SpringBoot父级依赖,spring-boot-starter默认加载了许多设置好的依赖,省去springMVC繁杂的配置过程 <parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>2.1.5.RELEASE</version> <relativepath> </relativepath></parent> 设置资源属性 > 分别为,源码编码格式、输出编码格式、jdk版本 <properties> <project.build.sourceencoding>UTF-8</project.build.sourceencoding> <project.reporting.outputencoding>UTF-8</project.reporting.outputencoding> <java.version>1.8</java.version> </properties> 引入依赖dependency > 引入springboot、springboot自带的web模块

SpringBoot系列之集成Mybatis教程

萝らか妹 提交于 2019-12-15 19:03:14
SpringBoot系列之集成Mybatis教程 环境准备:IDEA + maven 本博客通过例子的方式,介绍Springboot集成Mybatis的两种方法,一种是通过注解实现,一种是通过xml的方式 进行实验,要先创建一个Initializer工程,如图: 打包方式选择jar即可,因为Springboot使用了嵌入式的Servlet容器,直接运行jar即可,即使是web工程也支持 选择必要的jar,Mybatis、数据库驱动是必要的 新建项目后,会自动加上如下配置,,如果你的mysql服务器是5.7版本的,建议指定mysql-connector-java版本,Druid也需要自己加上,pom配置参考: <properties> <java.version>1.8</java.version> <druid.version>1.1.2</druid.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId>

【MapReduce】Mapreduce基础知识整理(三)

女生的网名这么多〃 提交于 2019-12-14 23:41:52
目录 1. 为什么需要自定义输入 2. 默认输入源码分析 2.1 org.apache.hadoop.mapreduce.Mapper 2.2 org.apache.hadoop.mapred.MapTask 2.3 org.apache.hadoop.mapreduce.lib.map.WrappedMapper 2.4 org.apache.hadoop.mapreduce.task.MapContextImpl 2.5 org.apache.hadoop.mapred.MapTask.NewTrackingRecordReader 2.6 org.apache.hadoop.mapreduce.JobContext#getInputFormatClass 2.7 org.apache.hadoop.mapreduce.task.JobContextImpl#getInputFormatClass 2.8 org.apache.hadoop.mapreduce.lib.input.TextInputFormat 2.9 org.apache.hadoop.mapreduce.lib.input.LineRecordReader 2.10 源码总结 3. 自定义输入 1. 为什么需要自定义输入 我们都知道namenode负责存储文件的metadata,运行时所有数据都保存到内存

自动生成Mybatis的Mapper文件

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-14 10:09:44
工作中使用mybatis时我们需要根据数据表字段创建pojo类、mapper文件以及dao类,并且需要配置它们之间的依赖关系,这样的工作很琐碎和重复,mybatis官方也发现了这个问题,因此给我们提供了mybatis generator工具来帮我们自动创建pojo类、mapper文件以及dao类并且会帮我们配置好它们的依赖关系。 插件依赖 < build > < plugins > < plugin > < groupId > org . springframework . boot < / groupId > < artifactId > spring-boot-maven-plugin < / artifactId > < / plugin > < plugin > < groupId > org . mybatis . generator < / groupId > < artifactId > mybatis-generator-maven-plugin < / artifactId > < version > 1.3 .5 < / version > < dependencies > < dependency > < groupId > mysql < / groupId > < artifactId > mysql-connector-java < /

反射的使用

◇◆丶佛笑我妖孽 提交于 2019-12-14 04:00:39
因为要根据不同的数据源查询数据,mapper中的方法除了数据源不一样,其他基本一致,而且未来要拓展新的数据源,因此想到使用反射。代码如下:public Map commonGetCountyCount(Mapper mapper,String sql,String methodName, String county){ Map map = new HashMap(); try{ Method method = mapper.getClass().getMethod(methodName,String.class); map = (Map) method.invoke(commonQuery,sql); }catch (Exception e){ map.put("MSG",county+"查询异常:"+e.getMessage()); e.printStackTrace(); } return map;}以后要添加新的数据源时,直接在mapper中写方法,实现类中可以减少很多代码,改动也方便。以下为mapper中代码: @DS("test")@Select("${sql}")Map jzqCommonQuery(@Param("sql") String sql); 来源: https://www.cnblogs.com/shihx/p/12034680.html

mybatis generator完整配置

喜欢而已 提交于 2019-12-14 03:58:20
原文出处见:https://www.jianshu.com/p/e09d2370b796 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> <!-- 配置生成器 --> <generatorConfiguration> <!-- 可以用于加载配置项或者配置文件,在整个配置文件中就可以使用${propertyKey}的方式来引用配置项 resource:配置资源加载地址,使用resource,MBG从classpath开始找,比如com/myproject/generatorConfig.properties url:配置资源加载地质,使用URL的方式,比如file:///C:/myfolder/generatorConfig.properties. 注意,两个属性只能选址一个; 另外,如果使用了mybatis-generator-maven-plugin,那么在pom