mapper

Mybatis面试题

人走茶凉 提交于 2020-01-04 03:08:32
1、Mybatis动态sql是做什么的?都有哪些动态sql?简述一下动态sql的执行原理? 答:动态Sql主要是根据对象中的不通的取值,来实现对Sql的一个动态的拼接,实现不同的Sql的语句。 主要动态Sql 的标签有 If语句(简单的条件判断) Choose(when/otherwise),相当于java语言中的switch,与jstl中choose类似 Trim(对包含的内容加上prefix,或者suffix) Where(主要是用来简化SQL语句中where条件判断,能智能的处理and/or 不用担心多余的语法导致的错误) Set(主要用于更新时候) Foreach(一般使用在mybatis in语句查询时特别有用) 以及 sql 标签来抽取sql 的片段,简化代码 执行原理: 2、Mybatis是否支持延迟加载?如果支持,它的实现原理是什么? 答:Mybatis仅支持association关联对象和collection关联集合对象的延迟加载,association指的就是一对一,collection指的就是一对多查询。在Mybatis配置文件中,可以配置是否启用延迟加载 lazyLoadingEnabled =true|false。 它的原理是,使用CGLIB创建目标对象的代理对象,当调用目标方法时,进入拦截器方法,比如调用a.getB().getName()

快速创建Spring Boot web项目集成mybatis、tk.mybatis、mybatis-generator、spring mvc、thymeleaf

陌路散爱 提交于 2020-01-03 21:25:25
创建基础SpringBoot项目集成 mybatis、tk.mybatis、mybatis-generator pom.xml <?xml version="1.0" encoding="UTF-8"?> < project xmlns = " http://maven.apache.org/POM/4.0.0 " xmlns: xsi = " http://www.w3.org/2001/XMLSchema-instance " xsi: schemaLocation = " http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd " > < modelVersion > 4.0.0 </ modelVersion > < parent > < groupId > org.springframework.boot </ groupId > < artifactId > spring-boot-starter-parent </ artifactId > < version > 2.0.3.RELEASE </ version > < relativePath /> </ parent > < groupId > com.zhun </ groupId > < artifactId

Mybatis自动生成代码

扶醉桌前 提交于 2020-01-03 15:11:24
Mybatis自动生成代码 1、配置maven依赖 <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.7</version> </dependency> 2、xml文件配置 <?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> <context id="tusiTables" targetRuntime="MyBatis3"> <commentGenerator> <!-- 是否去除自动生成的注释--> <property name="suppressAllComments" value="true"/> </commentGenerator> <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->

MyBatis 注解开发+逆向(Generator)

笑着哭i 提交于 2020-01-02 18:42:50
注解开发 最初设计时,MyBatis 是一个 XML 驱动的框架。配置信息是基于 XML 的,而且映射语句也是定义在 XML 中的。随着技术的更新发展,对于开发效率要求也原来越高,特别是一些小型项目;越来越多的框架开始支持注解, 到MyBatis3时,MyBatis对注解有了完善的支持,利用注解可以在一些情况下提高开发效率 但不幸的是,Java 注解的的表达力和灵活性十分有限。尽管很多时间都花在调查、设计和试验上, 最强大的 MyBatis 映射并不能用注解来构建 1. select 接口方法声明: import com.kkb.pojo.User; import org.apache.ibatis.annotations.Select; public interface UserMapper2 { @Select("select * from kuser where id = #{id}") public User selectUserByID(int id); } 测试方法: @Test public void selectTest(){ SqlSession session = factory.openSession(); UserMapper2 mapper = session.getMapper(UserMapper2.class); User user = mapper

Hadoop streaming: single file or multi file per map. Don't Split

放肆的年华 提交于 2020-01-02 10:29:32
问题 I have a lot of zip files that need to be processed by a C++ library. So I use C++ to write my hadoop streaming program. The program will read a zip file, unzip it, and process the extracted data. My problem is that: my mapper can't get the content of exactly one file. It usually gets something like 2.4 files or 3.2 files. Hadoop will send several files to my mapper but at least one of the file is partial. You know zip files can't be processed like this. Can I get exactly one file per map? I

Spring+SpringMVC+MyBatis深入学习及搭建(七)——MyBatis延迟加载

♀尐吖头ヾ 提交于 2020-01-02 04:07:26
转载请注明出处: http://www.cnblogs.com/Joanna-Yan/p/6953005.html 前面讲到: Spring+SpringMVC+MyBatis深入学习及搭建(六)——MyBatis关联查询 1.什么是延迟加载 resultMap可以实现高级映射(使用association、collection实现一对一及一对多映射), association、collection具备延迟加载功能。 需求: 如果查询订单并且关联查询用户信息。如果先查询订单信息即可满足要求,当我们需要查询用户信息时再查下用户信息。把对用户信息的按需去查询就是延迟加载。 延迟加载:先从单表查询、需要时再从关联表去关联查询,大大提高数据库性能,因为查询单表要比关联查询多张表速度要快。 2.使用association实现延迟加载 2.1需求 查询订单并且关联查询用户信息 2.2mapper.xml 需要定义两个mapper的方法对应的statement。 (1)只查询订单信息 SELECT * FROM orders 在查询订单的statement中 使用association去延迟加载(执行)下边的statement(关联查询用户信息)。 <!-- 查询订单关联查询用户 --> <select id="findOrdersUserLazyLoading" resultMap=

Mybatis(0)——基础入门,hello,Mybatis! (使用IDEA)

倾然丶 夕夏残阳落幕 提交于 2020-01-01 12:34:46
首先,介绍Mybatis是什么: 然后,创建一个hello,Mybatis! 需要什么:   两个XML文件,一个是 mybatis-config.xml 全局配置文件;一个是:StudentMapper.xml映射文件,用来将数据库的内容映射成一个个对象。   由 全局配置文件 可以获得SqlSessionFactory对象,再由这个对象可以获得SqlSession对象,SqlSession对象相当于Connection对象,就可查询到数据库的内容。 0)基础介绍:https://www.jianshu.com/p/c77e3691867d             https://www.jianshu.com/p/374bcb90083d             javaee搭建环境:https://blog.csdn.net/FJJ543/article/details/81064891   Mybatis官方下载链接:https://github.com/mybatis/mybatis-3/releases     注:Github上的mybatis库上面有一个官方说明文档,里面有一个about页面,可以选择中文,刚刚试了一下,说明文档链接打不开,-_-|| 1)环境搭建:      首先 :导入最基本两个包 :mysql-connector-java-8.0.16.jar

Spring Boot 2.x 多数据源配置之 MyBatis 篇

别等时光非礼了梦想. 提交于 2020-01-01 12:30:47
场景假设:现有电商业务,商品和库存分别放在不同的库 配置数据库连接 app: datasource: first: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://127.0.0.1/product?useSSL=false username: root password: root configuration: maximum-pool-size: 10 second: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://127.0.0.1/stock?useSSL=false username: root password: root configuration: maximum-pool-size: 10 添加配置类 FirstConfig @Configuration @MapperScan( basePackages = {"com.karonda.springboot2datasourcesmybatis.dao.first"},// 1. dao 层所在的包 sqlSessionTemplateRef = "firstSqlSessionTemplate") public class FirstConfig { @Bean

myBatis自动生成mapping,dao和model

一世执手 提交于 2020-01-01 12:20:47
myBatis没有自动封装实体类。所以都需要自己编写,但是表数据过多时。编写难度就会增加,错误率也会增加! 所以myBatis提供mybatis-generator-core-1.3.2-bundle能够自动封装实体并生成相应的mapping。 首先在百度上下载mybatis-generator-core-1.3.2-bundle。 进入lib目录下 然后打开generatorConfig.xml <?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> <!-- 配置mysql 驱动jar包路径.用了绝对路径 --> <classPathEntry location="mysql-connector-java-5.1.17-bin.jar" /> <context id="yihaomen_mysql_tables" targetRuntime="MyBatis3"> <!--

【SSM框架】Spring + Springmvc + Mybatis 基本框架搭建集成教程

跟風遠走 提交于 2020-01-01 12:18:20
本文将讲解SSM框架的基本搭建集成,并有一个简单demo案例 说明:1、本文暂未使用maven集成,jar包需要手动导入。    2、本文为基础教程,大神切勿见笑。    3、如果对您学习有帮助,欢迎各种转载,注明出处。    4、本文涉及源码和jar包下载地址: 一、导包 需要准备的包:   1、spring包   2、springmvc 包   3、mybatis 包 请自行下载导入,也可以去本人分享的网盘下载。 在lib目录创建spring,mybatis分类管理,将包复制进入各自的文件夹,并加载包。 二、配置文件 创建名为: config 的Source Folder文件夹。新建xml文件, 命名为: springmvc.xml 2.1springmvc.xml 配置    2.1.1、加入需要的beans标签库(aop.tx.context.mvc) <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop=