MyBatis整合Spring的实现(16)
2019独角兽企业重金招聘Python工程师标准>>>
本章中分析update元素的解析。
1 配置文件
<update id="updateByPrimaryKeySelective" parameterType="cn.vansky.schedule.time.menu.bo.Menu"><!--WARNING - @mbggeneratedThis element is automatically generated by MyBatis Generator, do not modify.This element was generated on Fri Aug 14 16:08:36 CST 2015.-->update tb_menu<set><if test="menuName != null">menu_name = #{menuName,jdbcType=VARCHAR},</if><if test="menuRemark != null">menu_remark = #{menuRemark,jdbcType=VARCHAR},</if><if test="menuParentId != null">menu_parent_id = #{menuParentId,jdbcType=INTEGER},</if><if test="menuUrl != null">menu_url = #{menuUrl,jdbcType=VARCHAR},</if><if test="isShow != null">is_show = #{isShow,jdbcType=TINYINT},</if><if test="isDelete != null">is_delete = #{isDelete,jdbcType=TINYINT},</if><if test="operationUserName != null">operation_user_name = #{operationUserName,jdbcType=VARCHAR},</if><if test="operationTime != null">operation_time = #{operationTime,jdbcType=TIMESTAMP},</if></set>where Id = #{id,jdbcType=INTEGER}
</update>
2 方法parseStatementNode
public void parseStatementNode() {// updateByPrimaryKeySelectiveString id = context.getStringAttribute("id");// nullString databaseId = context.getStringAttribute("databaseId");// 第一次检查这里是不通过的,直接跳过if (!databaseIdMatchesCurrent(id, databaseId, this.requiredDatabaseId)) return;// null Integer fetchSize = context.getIntAttribute("fetchSize");// nullInteger timeout = context.getIntAttribute("timeout");// nullString parameterMap = context.getStringAttribute("parameterMap");// cn.vansky.schedule.time.menu.bo.MenuString parameterType = context.getStringAttribute("parameterType");// class cn.vansky.schedule.time.menu.bo.MenuClass<?> parameterTypeClass = resolveClass(parameterType);// nullString resultMap = context.getStringAttribute("resultMap");// nullString resultType = context.getStringAttribute("resultType");// nullString lang = context.getStringAttribute("lang");// 获取默认的处理对象// org.apache.ibatis.scripting.xmltags.XMLLanguageDriverLanguageDriver langDriver = getLanguageDriver(lang);// nullClass<?> resultTypeClass = resolveClass(resultType);// nullString resultSetType = context.getStringAttribute("resultSetType");// PREPAREDStatementType statementType = StatementType.valueOf(context.getStringAttribute("statementType", StatementType.PREPARED.toString()));// nullResultSetType resultSetTypeEnum = resolveResultSetType(resultSetType);// updateString nodeName = context.getNode().getNodeName();// UPDATESqlCommandType sqlCommandType = SqlCommandType.valueOf(nodeName.toUpperCase(Locale.ENGLISH));// falseboolean isSelect = sqlCommandType == SqlCommandType.SELECT;// trueboolean flushCache = context.getBooleanAttribute("flushCache", !isSelect);// falseboolean useCache = context.getBooleanAttribute("useCache", isSelect);// falseboolean resultOrdered = context.getBooleanAttribute("resultOrdered", false);// Include Fragments before parsingXMLIncludeTransformer includeParser = new XMLIncludeTransformer(configuration, builderAssistant);// 解析<include refid="Base_Column_List" />includeParser.applyIncludes(context.getNode());// Parse selectKey after includes and remove them.processSelectKeyNodes(id, parameterTypeClass, langDriver);// 这里很明显也是动态SQL// org.apache.ibatis.scripting.xmltags.DynamicSqlSourceSqlSource sqlSource = langDriver.createSqlSource(configuration, context, parameterTypeClass);// nullString resultSets = context.getStringAttribute("resultSets");// nullString keyProperty = context.getStringAttribute("keyProperty");// nullString keyColumn = context.getStringAttribute("keyColumn");// org.apache.ibatis.executor.keygen.NoKeyGeneratorKeyGenerator keyGenerator;// updateByPrimaryKeySelective!selectKeyString keyStatementId = id + SelectKeyGenerator.SELECT_KEY_SUFFIX;// cn.vansky.schedule.time.menu.dao.MenuMapper.updateByPrimaryKeySelective!selectKeykeyStatementId = builderAssistant.applyCurrentNamespace(keyStatementId, true);if (configuration.hasKeyGenerator(keyStatementId)) {keyGenerator = configuration.getKeyGenerator(keyStatementId);} else {keyGenerator = context.getBooleanAttribute("useGeneratedKeys",configuration.isUseGeneratedKeys() && SqlCommandType.INSERT.equals(sqlCommandType))? new Jdbc3KeyGenerator() : new NoKeyGenerator();}builderAssistant.addMappedStatement(id, sqlSource, statementType, sqlCommandType,fetchSize, timeout, parameterMap, parameterTypeClass, resultMap, resultTypeClass,resultSetTypeEnum, flushCache, useCache, resultOrdered, keyGenerator, keyProperty, keyColumn, databaseId, langDriver, resultSets);}
updateByPrimaryKeySelective最终的MappedStatement
下面就来看动态SqlSource的属性。
转载于:https://my.oschina.net/u/1269959/blog/523851
MyBatis整合Spring的实现(16)相关推荐
- MyBatis整合Spring的实现(2)
2019独角兽企业重金招聘Python工程师标准>>> 分析 MyBatis整合Spring的实现(1)中代码实现的4.1可以知道,XMLConfigBuilder类读取MyBati ...
- MyBatis整合Spring原理分析
目录 MyBatis整合Spring原理分析 MapperScan的秘密 简单总结 假如不结合Spring框架,我们使用MyBatis时的一个典型使用方式如下: public class UserDa ...
- (转)MyBatis框架的学习(六)——MyBatis整合Spring
http://blog.csdn.net/yerenyuan_pku/article/details/71904315 本文将手把手教你如何使用MyBatis整合Spring,这儿,我本人使用的MyB ...
- Mybatis——Mybatis整合Spring详解
mybatis-spring官网 1. MyBatis整合Spring实现 我们首先实现MyBatis和Spring的整合操作. 1.1 添加相关的依赖 这些是整合的依赖,不包括其他分页插件等依赖. ...
- 【Mybatis+spring整合源码探秘】--- mybatis整合spring事务原理
文章目录 1 mybatis整合spring事务原理 1 mybatis整合spring事务原理 本篇文章不再对源码进行具体的解读了,仅仅做了下面一张图: 该图整理了spring+mybatis整合后 ...
- Spring学习笔记:Spring整合Mybatis(mybatis-spring.jar)(二:mybatis整合spring)
http://blog.csdn.net/qq598535550/article/details/51703190 二.Spring整合mybatis其实是在mybatis的基础上实现Spring框架 ...
- MyBatis(五)MyBatis整合Spring原理分析
前面梳理了下MyBatis在单独使用时的工作流程和关键源码,现在看看MyBatis在和Spring整合的时候是怎么工作的 也先从使用开始 Spring整合MyBatis 1.引入依赖,除了MyBati ...
- Mybatis整合spring
整合思路 1.SqlSessionFactory对象应该放到spring容器中作为单例存在. 2.传统dao的开发方式中,应该从spring容器中获得sqlsession对象. 3.Mapper代理形 ...
- mybatis 整合spring之mapperLocations配置的问题
今天尝试spring整合mybatis时遇到这么一个问题,就是在配置sqlSessionFactory时是否要配置mapperLocations的问题. <bean id="sessi ...
- mybatis整合spring下的的各种配置文件
1.applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans ...
最新文章
- KubeEdge — Overview
- Android开发--Notification和PendingIntent
- 极简数据分析实操指南(下)
- static void SetSysClockTo72(void)的一些理解
- 数据库同步热备方案(云南某金属企业)
- Index of sql server
- Vue指令篇_v-model_数据双向绑定
- 阿里云Redis混合存储典型场景:如何轻松搭建视频直播间系统
- 使用DistroTweaks复制您的自定义Linux设置
- angular tslint 自动修正
- 记录一次cordova升级react native安装失败版本过低的趟坑之旅
- 手机无启动抓拍的想法
- ITIL学习(四) 服务、IT服务、服务台管理、IT服务管理
- 分布式session解决方案
- excel单元格内容拆分_Excel分列解决不了的问题,VBA轻松搞定之拆分单元格
- usb热插拔多次之后无法识别
- python uiautomator2控制手机点击_uiautomator2 python远程操作Android
- Vue进阶(幺贰叁):v-for 实现一行展示 n 个元素
- ARM Mbed在线IDE编程意法半导体(ST)开发板
- 微软亚洲研究院 可视化_如何为亚洲市场本地化手机游戏