首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

mybatis学习札记2-SQL的简单应用

2013-02-19 
mybatis学习笔记2-SQL的简单应用简单EG:insert idinsertAuthor parameterTypedomain.blog.Author

mybatis学习笔记2-SQL的简单应用

简单EG:

<insert id="insertAuthor" parameterType="domain.blog.Author"> <selectKey keyProperty="id" resultType="int" order="BEFORE"> select CAST(RANDOM()*1000000 as INTEGER) a from SYSIBM.SYSDUMMY1 </selectKey> insert into Author (id, username, password, email,bio, favourite_section) values (#{id}, #{username}, #{password}, #{email}, #{bio}, #{favouriteSection,jdbcType=VARCHAR} ) </insert> 

注:

<selectKey
keyProperty="id" //selectKey 语句结果应该被设置的目标属性。
resultType="int"   //结果的类型。MyBat is 通常可以算出来,但是写上也没有问题。
MyBat is 允许任何简单类型用作主键的类型,包括字符串。
order="BEFORE" //这可以被设置为 BEFORE 或 AFTER。如果设置为 BEFORE,那
么它会首先选择主键,设置 keyProperty 然后执行插入语句。如果
设置为 AFTER,那么先执行插入语句,然后是 selectKey 元素-
这和如 Oracle 数据库相似,可以在插入语句中嵌入序列调用。

statementType="PREPARED">

热点排行
Bad Request.