ibatis
来源:互联网 发布:梦幻西游for mac 编辑:程序博客网 时间:2024/05/12 02:09
Student.xml:
<?xml version="1.0" encoding="UTF-8"?>
<sqlMap>
<typeAlias alias="Student" type="com.cn.entity.Student"/>
<insert id="insertStudentBySequene" parameterClass="Student">
<selectKey resultClass="int" keyProperty="sid">
select studentPKSequence.nextVal as sid from dual
</selectKey>
insert into Student(sid,sname,major,birth) values (#sid#,#sname#,#major#,#birth#)
</insert>
<select id="selectAllStudents" resultClass="Student">
select * from student
</select>
<select id="selectStudentById" parametername="int" resultClass="Student">
select * from student where sid = #sid#
</select>
<insert id="insertStudent" parameterClass="Student">
insert into Student(sid,sname,major,birth) values (#sid#,#sname#,#major#,#birth#)
</insert>
<delete id="deleteStudentById" parameterClass="int">
delete from Student where sid = #sid#
</delete>
<update id="updateStudentById" parameterClass="Student">
update Student set sname=#sname#,marjor=#major#,birth=#birth# where id="#sid#"
</update>
<select id="selectStudentByName" parameterClass="String" resultClass="Student">
select * from student where sname like '%$sname$%'
</select>
<!--
以下个为例写动态sql
判断是否为空
判断是否存在
-->
<select id="selectStudentByName" parameterClass="String" resultClass="Student">
select * from student
<dynamic prepend=" where ">
<isNotEmpty property="sname" prepend="and" open="(" close=")">
sname like '%$sname$%'
</isNotEmpty>
<isNotNull property="sname">
...
</isNotNull>
</dynamic>
</select>
</sqlMap>
SqlMap.properties:
driver=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@localhost:1521:orcl
username=scott
password=scott
SqlMapConfig.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<properties resource="com/cn/SqlMap.properties"/>
<settings
useStatementNamespaces="true"
cacheModelsEnabled="true"/>
<transactionManager type="JDBC">
<dataSource type="SIMPLE">
<property value="${driver}" name="JDBC.Driver"/>
<property value="${url}" name="JDBC.ConnectionURL"/>
<property value="${username}" name="JDBC.Username"/>
<property value="${password}" name="JDBC.Password"/>
</dataSource>
</transactionManager>
<sqlMap resource="com/cn/entity/Student.xml"/>
</sqlMapConfig>
- ibatis
- iBatis
- ibatis
- iBatis
- ibatis
- ibatis
- IBATIS
- ibatis
- iBATIS
- ibatis
- ibatis
- Ibatis
- iBatis
- IBATIS
- ibatis
- ibatis
- ibatis
- ibatis
- 使用EMF建立模型并生成Java代码
- Linux 基于TCP/IP的文件传输系统
- strcpy()和strncpy()的区别
- linux send recv函数详解
- recv/recvfrom/recvmsg系统调用
- ibatis
- 二单元 eight
- 设计需求的发现方式对设计的影响
- 基于模型设计的FPGA开发与实现:基本流程(一)之入门小例子(一):跑马灯
- 分层软件设计
- c#中label标签上标的输入
- IE8在写csdn的博客时,必须在兼容模式下,功能才能用
- 杂记2011/10/08
- 64. An old dog can't learn new tricks. 老狗学不会新把戏