ibatis中#与$的区别:
#str# 出来的效果是 'str'
$str$ 出来的效果是 str 如果'$str$' 则出来的效果是'str'
我们在调试的时候,写成'$str$'比较方便,输出sql语句时,可以看到值,如果写成#str#,看到的sql
语句就是包含?号的。
动态语句的写法:
<sqlMap>
<typeAlias alias="Submitted" type="com.itcast.Submitted"/>
<typeAlias alias="jobQueryBean" type="com.itcast.JobQueryBean"/>
<select id="queryJob" parameterClass="jobQueryBean" resultClass="Submitted">
select s.groupId as groupId, s.project as project,s.processState as processState,
s.createTime as createTime,s.submitter as submitter,s.jobId
as jobId,b.boqName as boqName from tbl_submited s
left join src_BoqInfo b on s.project = b.quotationNo
<dynamic prepend="where 1 = 1">
<isNotEmpty property="boqName">
and b.boqName like '%$boqName$%'
</isNotEmpty>
<isNotEmpty property="quotationNo">
and s.project = #quotationNo#
</isNotEmpty>
<isNotEmpty property="processState">
and s.processState = #processState#
</isNotEmpty>
<isNotEqual property="groupId" compareValue="0">
and s.groupId = $groupId$
</isNotEqual>
</dynamic>
</select>
</sqlMap>
ibatis不支持char类型,统一改成String,就没问题,动态构造时也比较方便
nvl(comm, 0): 如果comm的值为空值,则用0替补它。如果不是空值,算出来就是comm的值。
如何显示ibatis执行后的语句:
1.在src下建立一个log4j.properties文件,文件中写入:
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
#log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.rootLogger=warn, stdout
log4j.logger.com.ibatis=debug
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=debug
log4j.logger.com.ibatis.common.jdbc.ScriptRunner=debug
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=debug
log4j.logger.java.sql.Connection=debug
log4j.logger.java.sql.Statement=debug
log4j.logger.java.sql.PreparedStatement=debug
log4j.logger.java.sql.ResultSet=debug
2.加入log4j-1.2.11.jar,commons-logging-1.0.4.jar包commons-logging-1.0.4.jar可要可不要