ibatis resultMap
2014-04-12 14:14
295 查看
1.如果只要查询一个表的几个字段,可以使用ibatsi resultMap
Log.xml配置文件服务下
sqlmap配置文件如下:
java代码如下
logObject对象中,只有id以及client字段的数据
Log.xml配置文件服务下
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd"> <sqlMap namespace="Log"> <typeAlias alias="log" type="com.xxx.Log"/> <resultMap id="logResultMap" class="log"> <result property="id" column="id" nullValue="0"/> <result property="client" column="client" ></result> </resultMap> <select id="selectById" parameterClass = "int" resultMap = "logResultMap"> select id ,client from tableName where id = #id# </select> </sqlMap>
sqlmap配置文件如下:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0/" "http://ibatis.apache.org/dtd/sql-map-config-2.dtd"> <sqlMapConfig> <settings cacheModelsEnabled="true" enhancementEnabled="true" lazyLoadingEnabled="false" errorTracingEnabled="true" maxRequests="32" maxSessions="10" maxTransactions="5" useStatementNamespaces="true" /> <sqlMap resource="sqlmap/Log.xml"/> <settings useStatementNamespaces="true"/> <transactionManager type="JDBC"> <dataSource type="SIMPLE"> <property name="JDBC.Driver" value="com.mysql.jdbc.Driver"/> <property name="JDBC.ConnectionURL" value="jdbc:mysql://127.0.0.1:3306/dbName"/> <property name="JDBC.Username" value="xxx"/> <property name="JDBC.Password" value="xxx"/> </dataSource> </transactionManager> </sqlMapConfig>
java代码如下
public static void main(String[] args) { try { InputStream inputStream = new FileInputStream("D:\\sqlmap-config-log.xml"); SqlMapClient sqlMapClient=SqlMapClientBuilder.buildSqlMapClient(inputStream); Log logObject=(Log)sqlMapClient.queryForObject("Log.selectById",1); } catch (Exception e) { e.printStackTrace(); } }
logObject对象中,只有id以及client字段的数据
相关文章推荐
- 【iBatis】使用resultMap配置返回结果时报错“列名无效”
- org.apache.ibatis.builder.IncompleteElementException: Could not find result map com.szh.bean.product
- ibatis.net查询float类型返回实体类或者ResultMap时无效的问题
- ibatis的resultClass与resultMap
- ibatis中的resultClass,parameterClass,resultMap,resultType的使用与区别
- org.apache.ibatis.builder.IncompleteElementException: Could not find result map
- ibatis ResultMap ParameterMap
- ibatis resultMap 的用法
- ibatis_resultClass与resultMap
- org.apache.ibatis.builder.IncompleteElementException:Could not find result map cn.tengfei.core.dao.p
- iBATIS ResultMap基础浅析
- iBATIS SQL Maps之支持ParameterMap和ResultMap的数据类型的对照表。
- 关于IBATIS中SqlMap配置文件中resultType和resultMap的小差异
- ibatis resultMap使用的问题
- ibatis ResultMap ParameterMap
- 使用resultMap实现ibatis复合数据结构查询(1.多重属性查询;2.属性中含有列表查询)
- org.apache.ibatis.builder.xml.IncompleteStatementException: Could not find result map java.util.Map
- ibatis resultMap用法
- iBatis select for resultMap
- iBATIS ResultMap基础浅析