ibatis 动态sql(Dynamic SQL)
程序员文章站
2022-05-09 19:56:39
...
springside2allOne中ibatis只用几个孤零的ibatis的dao封装,没看到什么demo。
官网http://wiki.springside.org.cn/display/springside/iBatis的说明也很简略。在Springside中使用ibatis,参考这里,http://leondu.iteye.com/blog/54694。
IBatisGenericDao中get、getall明显公用一个statement,因此sql是动态的,参考
http://ibatis.apache.org/docs/dotnet/datamapper/ch03s09.html
个人ibatis配置如下
官网http://wiki.springside.org.cn/display/springside/iBatis的说明也很简略。在Springside中使用ibatis,参考这里,http://leondu.iteye.com/blog/54694。
IBatisGenericDao中get、getall明显公用一个statement,因此sql是动态的,参考
http://ibatis.apache.org/docs/dotnet/datamapper/ch03s09.html
个人ibatis配置如下
<?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> <settings cacheModelsEnabled="true" enhancementEnabled="true" lazyLoadingEnabled="true" errorTracingEnabled="true" maxRequests="32" maxSessions="10" maxTransactions="5" useStatementNamespaces="true" /> <sqlMap resource="com/jake/ibatis/conf/attraction-ibatis.xml" /> </sqlMapConfig>
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd"> <sqlMap namespace="com.jake.model.Attraction"> <!-- Use type aliases to avoid typing the full classname every time. --> <typeAlias alias="Attraction" type="com.jake.model.Attraction" /> <!-- Select with no parameters using the result map for Account class. --> <select id="select" resultClass="Attraction" parameterClass="int"> select * from Attraction <isGreaterThan compareValue="0"> where id = #id# </isGreaterThan> </select> <!-- <select id="com.jake.model.Attraction.select" resultClass="Attraction" parameterClass="int"> select * from Attraction where id=#id# </select> --> <insert id="insert" parameterClass="Attraction"> insert into Attraction(id,name,description) values ( #id#,#name#,#description# ) </insert> <update id="update" parameterClass="Attraction"> update Attraction set name = #name#,description=#description# where id=#id# </update> <delete id="delete" parameterClass="int"> delete from Attraction where id=#id# </delete> <select id="load" resultClass="Attraction" parameterClass="int"> select * from Attraction where id=#id# </select> </sqlMap>
上一篇: logback中用日期/时间作为文件夹/目录/文件名
下一篇: DateUtils