標籤:
這個問題我讓我搞了大半天,實在氣人,話不多說,直接上代碼
<select id="*" resultMap="Blog" parameterType="Integer">
select * (select count(*) from table_name c where c.bbs_id=t.id) as plcount, //子查詢 plcount為虛擬欄位 排序
from table_name t <![CDATA[ where rownum <=10 ]]> order by t.pvcount desc //mybatis識別不出來<或>,用<![CDATA[ where rownum <=10 ]]>可以
</select>
插入語句的編寫
<insert id="*" parameterType="Blog">
<selectKey order="BEFORE" resultType="java.lang.Long" keyProperty="id">
select ZDCJ_BLOG_SEQ.Nextval from dual //序列,在後台執行添加的時候,建構函式沒有序列ID
</selectKey>
insert into table_name (ID,BBS_TITLE,BBS_CENTER,BBS_DATE,AUTHOR,AC,BANKUAI,PVCOUNT,CREATE_DATE,CREATE_USER,POPULARITY) values(#{id,jdbcType=NUMERIC},# {bbsTitle,jdbcType=VARCHAR},#{bbsCenter,jdbcType=VARCHAR},#{bbsDate,jdbcType=VARCHAR},#{author,jdbcType=VARCHAR},#{ac,jdbcType=VARCHAR},# {bankuai,jdbcType=VARCHAR},#{pvcount,jdbcType=VARCHAR},#{createDate,jdbcType=VARCHAR},#{createUserid,jdbcType=NUMERIC},#{popularity,jdbcType=VARCHAR})
</insert>
//這是我自己想出來的表串連查詢,效果可以實現,可能不太專業,請諒解
<select id="*" resultType="Blog" parameterType="Integer">
select * from table_name1 u,table_name2 t where u.BLOG_ID = t.ID AND t.CREATE_USER=#{createUserid}
</select>
在oracle裡寫各種語句得心應手,但是在mybatis.xml檔案裡呢?