iBatis学习小结

sqlMap文件

代码
  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2. <!DOCTYPE sqlMap         
  3.     PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"         
  4.     "http://ibatis.apache.org/dtd/sql-map-2.dtd">  
  5. <sqlMap namespace="Account">  
  6.   <typeAlias alias="Account" type="test.Account"/>  
  7.   <!--列表查询,返回Account Object的List-->    
  8.   <resultMap id="AccountResult" class="Account">  
  9.     <result property="id" column="ID"/>  
  10.     <result property="firstName" column="FIRST_NAME"/>  
  11.     <result property="lastName" column="LAST_NAME"/>  
  12.     <result property="emailAddress" column="EMAIL"/>  
  13.   </resultMap>     
  14.   <select id="selectAllAccounts" resultMap="AccountResult">  
  15.     select * from ACCOUNT   
  16.   </select>  
  17.      
  18.   <!--列表查询,返回HashMap的List -->      
  19.   <!--resultMap无需再通过JDBC ResultSetMetaData 来动态获取字段信息,性能有提高-->  
  20.   
  21.   <resultMap id="mapResult" class="java.util.HashMap">  
  22.     <result property="roleid" column="ROLEID"/>  
  23.     <result property="rolename" column="ROLENAME"/>  
  24.     <result property="id" column="ID"/>  
  25.     <result property="firstName" column="FIRST_NAME"/>  
  26.     <result property="lastName" column="LAST_NAME"/>  
  27.     <result property="emailAddress" column="EMAIL"/>  
  28.     <result property="dt" column="DT"/>  
  29.   </resultMap>  
  30.   <select id="selectAllAccountsWithMap" resultMap="mapResult">  
  31.         select B.ROLEID, B.ROLENAME, A.ID, A.FIRST_NAME,A.LAST_NAME,A.EMAIL,A.DT   
  32.         from ACCOUNT A left outer join ROLE B   on A.ROLEID = B.ROLEID   
  33.         ORDER BY A.ID DESC   
  34.   </select>  
  35.      
  36. <!--动态构造查询条件-->  
  37. <select id="getUsers" parameterClass="user" resultMap="get-user-result">  
  38.     Select id,name,sex from t_user   
  39.     <dynamic prepend="WHERE">  
  40.         <isNotEmpty prepend="AND" property="name">  
  41.             (name like #name#)   
  42.         </isNotEmpty>  
  43.         <isNotEmpty prepend="AND" property="address">  
  44.             (address like #address#)   
  45.         </isNotEmpty>  
  46.     </dynamic>  
  47. </select>  
  48. <isNotEmpty prepend="AND" property="name">  
  49.     ( name=#name#   
  50.         <isNotEmpty prepend="AND" property="address">  
  51.             address=#address#   
  52.         </isNotEmpty>  
  53.     )   
  54. </isNotEmpty>  
  55. <select id="dynamicGetAccountList" resultMap="account-result" >  
  56.     select * from ACCOUNT   
  57.     <dynamic prepend="WHERE">  
  58.         <isNotNull prepend="AND" property="firstName" open=”(“ close=”)”>  
  59.             ACC_FIRST_NAME = #firstName#   
  60.             <isNotNull prepend="OR" property="lastName">  
  61.                 ACC_LAST_NAME = #lastName#   
  62.             </isNotNull>  
  63.         </isNotNull>  
  64.         <isNotNull prepend="AND" property="emailAddress">  
  65.             ACC_EMAIL like #emailAddress#   
  66.         </isNotNull>  
  67.         <isGreaterThan prepend="AND" property="id" compareValue="0">  
  68.             ACC_ID = #id#   
  69.         </isGreaterThan>  
  70.     </dynamic>  
  71.     order by ACC_LAST_NAME   
  72. </select>  
  73.   
  74. <isParameterPresent> <isNotParameterPresent> <isNull> <isNotNull> <isEmpty> <isNotEmpty>  
  75. <isEqual> <isNotEqual> <isGreaterThan> <isGreaterEqual> <isLessThan> <isLessEqual>  
  76.   
  77. <!-- Sql片段的是用-->  
  78. <sql id="selectItem_fragment">  
  79.     FROM items WHERE parentid = 6  
  80. </sql>  
  81. <select id="selectItemCount" resultClass="int">  
  82.     SELECT COUNT(*) AS total   
  83.     <include refid="selectItem_fragment"/>  
  84. </select>  
  85. <select id="selectItems" resultClass="Item">  
  86.     SELECT id, name   
  87.     <include refid="selectItem_fragment"/>  
  88. </select>  
  89.   
  90. <!--缓存-->  
  91. <cacheModel id="product-cache" type="LRU">  
  92.     <flushInterval hours="24"/>  
  93.     <flushOnExecute statement="insertProduct"/>  
  94.     <flushOnExecute statement="updateProduct"/>  
  95.     <flushOnExecute statement="deleteProduct"/>  
  96.     <property name=”size” value=”1000” />  
  97. </cacheModel>  
  98. <select id=”getProductList” parameterClass=”int” cacheModel=”product-cache”>  
  99.     select * from PRODUCT where PRD_CAT_ID = #value#   
  100. </select>  
  101.   
  102. <!—对XML支持 -->  
  103. <select id="getPerson" parameterClass=”int” resultClass="xml" xmlResultName=”person”>  
  104.     SELECT   
  105.     PER_ID as id,   
  106.     PER_FIRST_NAME as firstName,   
  107.     PER_LAST_NAME as lastName,   
  108.     PER_BIRTH_DATE as birthDate,   
  109.     PER_WEIGHT_KG as weightInKilograms,   
  110.     PER_HEIGHT_M as heightInMeters   
  111.     FROM PERSON   
  112.     WHERE PER_ID = #value#   
  113. </select>  
  114. <person>  
  115.     <id>1</id>  
  116.     <firstName>Clinton</firstName>  
  117.     <lastName>Begin</lastName>  
  118.     <birthDate>1900-01-01</birthDate>  
  119.     <weightInKilograms>89</weightInKilograms>  
  120.     <heightInMeters>1.77</heightInMeters>  
  121. </person>  
  122.   
  123. <!—字符串替换   
  124. select * from $tableName$   
  125. Important Note 1: This support will only substitute Strings, so it is not appropriate for complex data types like Date or Timestamp.   
  126. Important Note 2: If you use this support to alter a table name, or a column list, in an SQL select statement,then you should always specify remapResults=“true”   
  127. -->.   
  128.   
  129. <!—关联查询方式,有1/N问题-->  
  130. <sqlMap namespace="User">  
  131.     <typeAlias alias="user" type="com.ibatis.sample.User"/>  
  132.     <typeAlias alias="address" type="com.ibatis.sample.Address"/>  
  133.     <resultMap id="get-user-result" class="user">  
  134.         <result property="id" column="id"/>  
  135.         <result property="name" column="name"/>  
  136.         <result property="sex" column="sex"/>  
  137.         <result property="addresses" column="id"    select="User.getAddressByUserId"/>  
  138.     </resultMap>  
  139.     <select id="getUsers"   parameterClass="java.lang.String" resultMap="get-user-result">  
  140.         <![CDATA[Select id,name,sex from t_user where id = #id#]]>  
  141.     </select>  
  142.     <select id="getAddressByUserId" parameterClass="int" resultClass="address">  
  143.         <![CDATA[select address,zipcode from t_address where user_id = #userid# ]]>  
  144.     </select>  
  145. </sqlMap>  
  146. <resultMap id="get-user-result" class="user">  
  147.     <result property="id" column="id"/>  
  148.     <result property="name" column="name"/>  
  149.     <result property="sex" column="sex"/>  
  150.     <result property="address" column="t_address.address"/>  
  151.     <result property="zipCode" column="t_address.zipcode"/>  
  152. </resultMap>  
  153. <select id="getUsers" parameterClass="java.lang.String" resultMap="get-user-result">  
  154.     <![CDATA[select* from t_user,t_address where t_user.id=t_address.user_id]]>  
  155. </select>  
  156. 保证User 类中包含address和zipCode两个String型属性。   
  157.   
  158. <!—关联查询,无1/N问题-->  
  159.   <resultMap id="AccountResultWithRole" class="Account" groupBy="id">  
  160.     <result property="id" column="ID"/>  
  161.     <result property="firstName" column="FIRST_NAME"/>  
  162.     <result property="lastName" column="LAST_NAME"/>  
  163.     <result property="emailAddress" column="EMAIL"/>       
  164.     <result property="role" resultMap="Account.roleResult"/>  
  165.   </resultMap>  
  166.   <resultMap id="roleResult" class="test.Role">  
  167.     <result property="roleid" column="ROLEID"/>  
  168.     <result property="rolename" column="ROLENAME"/>  
  169.   </resultMap>  
  170.   <select id="selectAccountByIdWithRole" parameterClass="int" resultMap="AccountResultWithRole">  
  171.         select B.ROLEID, B.ROLENAME, A.ID, A.FIRST_NAME,A.LAST_NAME,A.EMAIL from ACCOUNT A left outer join ROLE B on A.ROLEID = B.ROLEID where A.ID = #id#   
  172.   </select>  
  173.      
  174.   <!--查询-->    
  175.   <select id="selectAccountById" parameterClass="int" resultClass="Account">  
  176.     select ID as id,FIRST_NAME as firstName,LAST_NAME as lastName,       EMAIL as emailAddress from ACCOUNT where ID = #id#   
  177.   </select>  
  178.      
  179.   <!--新增-->      
  180.   <insert id="insertAccount" parameterClass="Account">  
  181.     insert into ACCOUNT (FIRST_NAME,LAST_NAME,EMAIL,PID,DT)     
  182.     values (#firstName:VARCHAR#, #lastName:VARCHAR#, #emailAddress:VARCHAR#,#pid:INTEGER:0#,#dt:TIME#)   
  183.     <selectKey resultClass="int" type="post" keyProperty="id">  
  184.         SELECT @@IDENTITY AS ID   
  185.     </selectKey>       
  186.   </insert>  
  187.      
  188.   <!--更新-->    
  189.   <update id="updateAccount" parameterClass="Account">  
  190.     update ACCOUNT set   
  191.       FIRST_NAME = #firstName:VARCHAR#,   
  192.       LAST_NAME = #lastName:VARCHAR#,   
  193.       EMAIL = #emailAddress:VARCHAR#   
  194.     where   
  195.       ID = #id#   
  196.   </update>  
  197.   
  198.   <!--删除-->  
  199.   <delete id="deleteAccountById" parameterClass="int">  
  200.     delete from ACCOUNT where ID = #id#   
  201.   </delete>  
  202.      
  203.   <!--存储过程,如果没有返回列表,procTest的resultMap可以省略-->      
  204.   <parameterMap id="procParamMap" class="java.util.HashMap" >  
  205.     <parameter property="id" jdbcType="INTEGER" javaType="java.lang.Integer" mode="IN"/>  
  206.     <parameter property="outid" jdbcType="INTEGER" javaType="java.lang.Integer" mode="OUT"/>  
  207.     <parameter property="errMsg" jdbcType="VARCHAR" javaType="java.lang.String" mode="OUT"/>  
  208.   </parameterMap>  
  209.   <resultMap id="procResultMap" class="java.util.HashMap" >  
  210.     <result property="a" column="AAA"/>  
  211.     <result property="b" column="BBB"/>  
  212.     <result property="c" column="CCC"/>       
  213.   </resultMap>     
  214.   <procedure id="procTest" parameterMap="procParamMap" resultMap="procResultMap">  
  215.     {call test_sp_1 (?,?,?)}   
  216.   </procedure>  
  217. </sqlMap>  

 

 

java 代码

代码
  1. public class TestDao extends SqlMapClientDaoSupport {   
  2.     public List selectAllAccounts() throws SQLException {   
  3.         return getSqlMapClientTemplate().queryForList("selectAllAccounts");   
  4.     }   
  5.   
  6.     public List selectAllAccountsWithMap() throws SQLException {   
  7.         return getSqlMapClientTemplate().queryForList(   
  8.                 "selectAllAccountsWithMap");   
  9.     }      
  10.        
  11.     public Account selectAccountById(int id) throws SQLException {   
  12.         return (Account) getSqlMapClientTemplate().queryForObject(   
  13.                 "selectAccountById"new Integer(id));   
  14.     }   
  15.     public List procTest(Map params) throws Exception {   
  16.         List ret = (List) getSqlMapClientTemplate().queryForList("procTest",params);   
  17.         return ret;   
  18.     }   
  19.     public Account selectAccountByIdWithRole(int id) throws SQLException {   
  20.         return (Account) getSqlMapClientTemplate().queryForObject(   
  21.                 "selectAccountByIdWithRole"new Integer(id));   
  22.     }      
  23.        
  24.    
基于数据驱动的 Koopman 算子的递归神经网络模型线性化,用于纳米定位系统的预测控制研究(Matlab代码实现)内容概要:本文围绕“基于数据驱动的Koopman算子的递归神经网络模型线性化”展开,旨在研究纳米定位系统的预测控制方法。通过结合数据驱动技术与Koopman算子理论,将非线性系统动态近似为高维线性系统,进而利用递归神经网络(RNN)建模并实现系统行为的精确预测。文中详细阐述了模型构建流程、线性化策略及在预测控制中的集成应用,并提供了完整的Matlab代码实现,便于科研人员复现实验、优化算法并拓展至其他精密控制系统。该方法有效提升了纳米级定位系统的控制精度与动态响应性能。; 适合人群:具备自动控制、机器学习或信号处理背景,熟悉Matlab编程,从事精密仪器控制、智能制造或先进控制算法研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①实现非线性动态系统的数据驱动线性化建模;②提升纳米定位平台的轨迹跟踪与预测控制性能;③为高精度控制系统提供可复现的Koopman-RNN融合解决方案; 阅读建议:建议结合Matlab代码逐段理解算法实现细节,重点关注Koopman观测矩阵构造、RNN训练流程与模型预测控制器(MPC)的集成方式,鼓励在实际硬件平台上验证并调整参数以适应具体应用场景。
提供了一套完整的基于51单片机的DDS(直接数字频率合成)信号波形发生器设计方案,适合电子爱好者、学生以及嵌入式开发人员学习和实践。该方案详细展示了如何利用51单片机(以AT89C52为例)结合AD9833 DDS芯片来生成正弦波、锯齿波、三角波等多种波形,并且支持通过LCD12864显示屏直观展示波形参数或状态。 内容概述 源码:包含完整的C语言编程代码,适用于51系列单片机,实现了DDS信号的生成逻辑。 仿真:提供了Proteus仿真文件,允许用户在软件环境中测试整个系统,无需硬件即可预览波形生成效果。 原理图:详细的电路原理图,指导用户如何连接单片机、DDS芯片及其他外围电路。 PCB设计:为高级用户准备,包含了PCB布局设计文件,便于制作电路板。 设计报告:详尽的设计文档,解释了项目背景、设计方案、电路设计思路、软硬件协同工作原理及测试结果分析。 主要特点 用户交互:通过按键控制波形类型和参数,增加了项目的互动性和实用性。 显示界面:LCD12864显示屏用于显示当前生成的波形类型和相关参数,提升了项目的可视化度。 教育价值:本资源非常适合教学和自学,覆盖了DDS技术基础、单片机编程和硬件设计多个方面。 使用指南 阅读设计报告:首先了解设计的整体框架和技术细节。 环境搭建:确保拥有支持51单片机的编译环境,如Keil MDK。 加载仿真:在Proteus中打开仿真文件,观察并理解系统的工作流程。 编译与烧录:将源码编译无误后,烧录至51单片机。 硬件组装:根据原理图和PCB设计制造或装配硬件。 请注意,本资源遵守CC 4.0 BY-SA版权协议,使用时请保留原作者信息及链接,尊重原创劳动成果。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值