1.sqlMapConfig
<sqlMapConfig> <properties resource="db.properties"/> <settings cacheModelsEnabled="true" enhancementEnabled="true" lazyLoadingEnabled="true" maxRequests="128" maxSessions="32" maxTransactions="16" useStatementNamespaces="true"/> <typeAlias alias="stringBooleanHandler" type="com....common.ibatis.StringBooleanTypeHandler"/> <typeAlias alias="integerBooleanHandler" type="com....common.ibatis.IntegerBooleanTypeHandler"/> <sqlMap resource="ibatis/sql/statistics.xml"/> <sqlMap resource="ibatis/sql/user.xml"/> </sqlMapConfig>
2.命名空间和别名
<sqlMap namespace="statistics"> <typeAlias alias="websiteCnt" type="cn....tables.statistics.TrackingWebsiteCnt"/>
3.
<sql id="getOrderCondition"> <isNotEmpty prepend="ORDER BY" property="sortField"> <![CDATA[ $sortField$ $orderBy$ ]]> </isNotEmpty> <isEmpty prepend="ORDER BY" property="sortField"> <![CDATA[ a.created_at desc ]]> </isEmpty> <isGreaterThan property="page" compareValue="0"> <isGreaterThan property="pageSize" compareValue="0"> <![CDATA[ limit $pos$ , $pageSize$ ]]> </isGreaterThan> </isGreaterThan> </sql>
<select id="getSubCompanyCntsList" parameterClass="subCompanyCnt" resultClass="subCompanyCnt">
SELECT a.id , a.username userName , a.company_id companyId , a.name name , a.created_at createdAt , IFNULL(c.validMetaCount, 0) validMetaCount , IFNULL(c.pendingMetaCount, 0) pendingMetaCount , IFNULL(d.orderCount, 0) orderCount , IFNULL(d.pendingOrderCount, 0) pendingOrderCount , IFNULL(d.confirmedOrderCount, 0) confirmedOrderCount , IFNULL(d.startOrderCount, 0) startOrderCount , IFNULL(d.stopOrderCount, 0) stopOrderCount , IFNULL(d.closeOrderCount, 0) closeOrderCount , IFNULL(e.matchCount, 0) matchCount , IFNULL(f.reportCount, 0) reportCount FROM ${sso.database}.company_subCompany b ,${sso.database}.user a LEFT JOIN (SELECT subCompany_id , SUM(CASE WHEN is_valid = 'valid' THEN 1 ELSE 0 END) validMetaCount , SUM(CASE WHEN is_valid = 'pending' THEN 1 ELSE 0 END) pendingMetaCount FROM meta GROUP BY subCompany_id ) c ON c.subCompany_id = a.company_id LEFT JOIN (SELECT subCompany_id , count(id) orderCount , SUM(CASE WHEN order_status = 'need confirm' THEN 1 ELSE 0 END) pendingOrderCount , SUM(CASE WHEN order_status = 'confirmed' THEN 1 ELSE 0 END) confirmedOrderCount , SUM(CASE WHEN order_status = 'in process' and start_at > 0 and stop_at = 0 THEN 1 ELSE 0 END) startOrderCount , SUM(CASE WHEN order_status = 'in process' and start_at = 0 and stop_at > 0 THEN 1 ELSE 0 END) stopOrderCount , SUM(CASE WHEN order_status = 'finished' THEN 1 ELSE 0 END) closeOrderCount FROM trackingOrder GROUP BY subCompany_id) d ON a.company_id = d.subCompany_id LEFT JOIN (SELECT company_id , count(*) matchCount FROM matchedPage where verification = 'mediadna' GROUP BY company_id) e ON a.company_id = e.company_id LEFT JOIN (SELECT subCompany_id , count(*) reportCount FROM rpo_summaryCompany WHERE is_deleted = 'false' GROUP BY subCompany_id) f ON a.company_id = f.subCompany_id WHERE a.is_deleted = 'false' AND b.company_id = #companyId# AND b.subCompany_id = a.company_id <isNotEmpty prepend="AND" property="searchKeyword"> a.name like '%$searchKeyword$%' </isNotEmpty> <include refid="getOrderCondition" /> </select>
<select id="getSubCompanyCntsList" parameterClass="subCompanyCnt" resultClass="subCompanyCnt"> SELECT a.id , a.username userName , a.company_id companyId , a.name name , a.created_at createdAt , IFNULL(c.validMetaCount, 0) validMetaCount , IFNULL(c.pendingMetaCount, 0) pendingMetaCount , IFNULL(d.orderCount, 0) orderCount , IFNULL(d.pendingOrderCount, 0) pendingOrderCount , IFNULL(d.confirmedOrderCount, 0) confirmedOrderCount , IFNULL(d.startOrderCount, 0) startOrderCount , IFNULL(d.stopOrderCount, 0) stopOrderCount , IFNULL(d.closeOrderCount, 0) closeOrderCount , IFNULL(e.matchCount, 0) matchCount , IFNULL(f.reportCount, 0) reportCount FROM ${sso.database}.company_subCompany b ,${sso.database}.user a LEFT JOIN (SELECT subCompany_id , SUM(CASE WHEN is_valid = 'valid' THEN 1 ELSE 0 END) validMetaCount , SUM(CASE WHEN is_valid = 'pending' THEN 1 ELSE 0 END) pendingMetaCount FROM meta GROUP BY subCompany_id ) c ON c.subCompany_id = a.company_id LEFT JOIN (SELECT subCompany_id , count(id) orderCount , SUM(CASE WHEN order_status = 'need confirm' THEN 1 ELSE 0 END) pendingOrderCount , SUM(CASE WHEN order_status = 'confirmed' THEN 1 ELSE 0 END) confirmedOrderCount , SUM(CASE WHEN order_status = 'in process' and start_at > 0 and stop_at = 0 THEN 1 ELSE 0 END) startOrderCount , SUM(CASE WHEN order_status = 'in process' and start_at = 0 and stop_at > 0 THEN 1 ELSE 0 END) stopOrderCount , SUM(CASE WHEN order_status = 'finished' THEN 1 ELSE 0 END) closeOrderCount FROM trackingOrder GROUP BY subCompany_id) d ON a.company_id = d.subCompany_id LEFT JOIN (SELECT company_id , count(*) matchCount FROM matchedPage where verification = 'mediadna' GROUP BY company_id) e ON a.company_id = e.company_id LEFT JOIN (SELECT subCompany_id , count(*) reportCount FROM rpo_summaryCompany WHERE is_deleted = 'false' GROUP BY subCompany_id) f ON a.company_id = f.subCompany_id WHERE a.is_deleted = 'false' AND b.company_id = #companyId# AND b.subCompany_id = a.company_id <isNotEmpty prepend="AND" property="searchKeyword"> a.name like '%$searchKeyword$%' </isNotEmpty> <include refid="getOrderCondition" /> </select>
基础
<select id="getUserByKey" resultClass="user" parameterClass="int"> <![CDATA[ select a.id , a.company_id companyId , a.name , a.username userName , a.password , a.email , a.phone , a.company_name companyName , a.address1 , a.address2 , a.signature , a.description , ifnull(b.role_id, 0) roleId from user a left join user_role b on a.id = b.user_id where a.id = #value# ]]> </select>
<sql id="getQueryCondition"> <isNotEmpty prepend="AND" property="searchKeyword"> <![CDATA[ user.name like '%$searchKeyword$%' ]]> </isNotEmpty> <isNotEmpty prepend="AND" property="start"> <![CDATA[ user.created_at >= #start# ]]> </isNotEmpty> <isNotEmpty prepend="AND" property="end"> <![CDATA[ user.created_at < date_add(#end#,INTERVAL 1 day) ]]> </isNotEmpty> </sql> <sql id="getOrderCondition"> <isNotEmpty prepend="order by" property="user.sortField"> <![CDATA[ $user.sortField$ ]]> </isNotEmpty> <isEmpty prepend="order by" property="user.sortField"> <![CDATA[ user.created_at ]]> </isEmpty> <isNotEmpty property="user.orderBy"> <![CDATA[ $user.orderBy$ ]]> </isNotEmpty> <isGreaterThan property="user.page" compareValue="0"> <isGreaterThan property="user.pageSize" compareValue="0"> <![CDATA[ limit $user.pos$ , $user.pageSize$ ]]> </isGreaterThan> </isGreaterThan> </sql>
<select id="getUserByUserName" resultClass="user" parameterClass="string"> <![CDATA[ SELECT a.id , a.company_id companyId , a.username userName , a.name , a.password , a.user_type userType FROM user a WHERE a.username = #userName# AND a.is_deleted = 'false' AND a.company_id NOT IN (SELECT b.subCompany_id FROM company_subCompany b) ]]> </select>
<select id="getUserByKey" resultClass="user" parameterClass="int"> <![CDATA[ select a.id , a.company_id companyId , a.name , a.username userName , a.password , a.email , a.phone , a.company_name companyName , a.address1 , a.address2 , a.signature , a.description , ifnull(b.role_id, 0) roleId from user a left join user_role b on a.id = b.user_id where a.id = #value# ]]> </select>
相关推荐
#### 三、SQL语句编写基础 在ibatis中,可以通过XML配置文件或者注解的方式定义SQL语句。以下是一些常见的SQL语句类型及其编写方式: ##### 3.1 查询(SELECT) 查询操作是最常见的数据库操作之一,用于从数据库...
在IT行业中,数据库操作是开发工作中的重要环节,而Ibatis作为一款优秀的持久层框架,为Java开发者提供了灵活的SQL映射功能,减轻了手动编写SQL和操作结果集的负担。SQLServer则是一款广泛使用的商业关系型数据库...
Ibatis 是一款轻量级的Java持久层框架,它提供了SQL映射文件和基于XML或注解的SQL语句配置,使得开发者可以更加灵活地控制SQL的编写,从而避免了传统的JDBC代码中的大量模板式代码。这个"ibatis SQL映射文件、DAO、...
iBATIS SQL Maps官方中文教程是一份非常宝贵的资源,它为初学者和进阶开发者提供了深入理解iBATIS SQL Maps的途径。iBATIS是一个Java框架,它将应用程序的业务逻辑与数据库操作分离,简化了数据访问层的开发。SQL ...
在深入探讨iBATIS-SqlMaps2的具体用法之前,需要先了解一些基础知识和准备工作。 ##### 1. SQLMap概述 - **适用范围**:SQLMap可以有效地应用于设计不佳的数据库模型或对象模型。然而,在设计数据库和对象模型时,...
除了基础功能外,教程还会涉及IBATIS的高级特性,比如缓存机制,这能提高应用的性能。此外,还有关于事务管理和异常处理的内容,这些都是实际开发中不可忽视的部分。 通过《ibatis-sqlmaps-2_cn》,你不仅可以学习...
【标题】:“C# IBatis IBatis基础 完整项目” 【描述】中提到的是一个基于C#的IBatis学习项目,适用于初学者。IBatis是一个流行的数据访问层框架,它允许开发者将SQL语句与应用程序代码分离,提高了代码的可维护性...
通过《iBATIS-SqlMaps-中文教程.pdf》,你将能够熟练掌握iBATIS的使用,为你的Java Web开发之路打下坚实基础。同时,由于iBATIS与MyBatis的关系(MyBatis是iBATIS的后续发展项目),学习iBATIS也能为将来学习MyBatis...
总的来说,《iBATIS-SqlMaps-2-Tutorial_cn》是一本全面覆盖iBATIS基础和进阶内容的教程,它不仅适合初学者入门,也对有一定经验的开发者有很好的参考价值。通过阅读本书,你可以深入理解iBATIS的工作原理,掌握其...
如果源码公开,开发者可以通过阅读和学习`Sqlmap2Table.java` 来提升他们对MyBatis/iBatis框架的理解,也可以将其作为其他自动化任务的基础,如数据库同步或迁移。 总的来说,这个工具提供了从SQL映射文件到实际...
它主要用于简化JDBC编程,提供一种“半自动化”的ORM(对象关系映射)实现,与Hibernate等“一站式”ORM解决方案相比,iBATIS强调的是SQL的灵活性和可控性。 在理论体系中,iBATIS的核心价值在于SQL Maps。SQL Maps...
在“iBATIS-SqlMaps中文教程集合”中,你将找到四本深入浅出的教程,这些教程涵盖了iBATIS的基础使用、高级特性和实战案例,帮助开发者快速掌握并熟练运用iBATIS解决项目中的实际问题。 1. **基础篇** - iBATIS...
**Ibatis基础知识详解** Ibatis,全称MyBatis,是一个优秀的开源持久层框架,它支持定制化SQL、存储过程以及高级映射。在Java应用中,Ibatis可以帮助开发者将数据库操作与业务逻辑分离,从而简化开发工作,提高代码...
### iBATIS SQL Maps 入门教程知识点梳理 #### 一、iBATIS SQL Maps 概述 - **定义**:iBATIS SQL Maps(现称为 ...通过以上知识点的梳理,希望能帮助读者更好地理解和掌握iBATIS SQL Maps的基础知识及使用技巧。
这两个版本的开发指南是iBATIS开发者不可或缺的参考书籍,不仅适用于初学者理解iBATIS的基础操作,也为有经验的开发者提供了深入学习和优化项目的机会。通过阅读《iBATIS-SqlMaps-开发指南》,开发者可以更好地掌握...
《Ibatis 框架基础详解》 Ibatis,作为一个轻量级的持久层框架,以其灵活、简单的特点在Java开发领域中广受欢迎。本文将深入解析Ibatis的基本概念、核心功能以及使用方法,帮助开发者更好地理解和应用这一框架。 ...
教程《iBATIS-SqlMaps-2 Tutorial_ja.pdf》可能包含以下内容:基础安装和配置、SqlMap配置详解、数据源的设置、SQL映射文件的编写、动态SQL的使用、事务管理、结果集映射、参数映射、自定义类型处理器、异常处理以及...
iBATIS,全称为“Java SQL Mapping Framework”,是一款开源的Java数据访问框架,它为Java开发者提供了一种方便地将SQL语句与Java代码分离,实现数据库操作的方式。本资料集是针对iBATIS的基础入门教程,适合初学者...
【ibatis基础知识详解】 Ibatis,作为一个开源的Java持久层框架,主要目的是简化数据库操作,减少繁琐的JDBC代码编写。它将SQL语句与Java代码分离,使得开发者可以更专注于业务逻辑,而不必过于关心数据访问细节。...
**Ibatis基础教程** Ibatis,全称MyBatis,是一个优秀的开源Java持久层框架,它专注于SQL映射,使得开发者能够将精力集中在编写SQL上,而无需关注JDBC的繁琐工作。Ibatis的主要目标是简化Java应用与数据库之间的...