mybits配置文件resultMap标签的配置

什么时候用resultType?什么时候用resultMap?

resultMap:当查询结果和pojo类不能直接对应时,可以使用resultMap对查询结果和pojo做一个映射,使其匹配。

标签:resultMap

标签结构:

<resultMap id="" type="">

<id column="" property=""/>

<result column="" property=""/>

<association property="" javaType="">

<id column="" property=""/>

<result column="" property=""/>

</assocaiation>

<collection property="" ofType="">

<id column="" property=""/>

<result column="" property=""/>

</collection>

属性说明:

id:唯一标识resultMap,statement通过id调用到它。

type:resultMap将查询结果映射到的pojo类

子标签:association、collection、id、result

子标签说明:

1.id:唯一标识查询结果的属性

属性:

column:数据库查询结果的字段名

property:映射到的pojo类的属性名

2.result:查询结果中的普通列

属性:

column:数据库查询结果的字段名

property:映射到的pojo类的属性名

3.association:一对一查询时使用,里面映射子结果的内容

属性:

property:查询结果映射到的resultMap的type属性对应pojo的哪一个属性

javaType:对应的java类,也就是pojo类

(该子标签下也有id和result子标签,作用和resultMap下的id和result类似)

4.collection:一对多查询时使用,里面映射子结果的集合(List)

属性:

property:查询结果映射到的resultMap的type属性对应pojo的哪一个属性

ofType:指定映射到list集合属性中pojo的类型

(同样的,该子标签下也有id和result子标签,作用和resultMap下的id和result类似)

原文地址:https://www.cnblogs.com/zhihow/p/9027013.html

时间: 2024-08-14 09:57:35

mybits配置文件resultMap标签的配置的相关文章

mybatis 中 sql 映射文件 select 标签以及 入 resultMap 标签的应用

1.自定义某个 javabean 的封装规则: 注:可以看到,select 标签中引用了 定义好的 resultMap 的值.resultMap 标签中的 type 为javabean 类型,id 为唯一标识.id 子标签定义主键(这样定义底层会有优化.)column 属性为字段名,property 属性为字段值. 注:可以看到测试结果没有出现问题,说明代码没有错误. 2.自定义某个 javabean 的级联属性封装: a.准备工作:mysql 数据库中,在之前 tbl_employees 表的

JEECMS站群管理系统-- 标签的配置流程

以cms_content_list为例,首先,每一个标签的声明都是在jeecms-context.xml中进行的, <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&qu

mybatis学习 十三 resultMap标签 一对一

1 .<resultMap>标签 写在mapper.xml中,由程序员控制SQL查询结果与实体类的映射关系. 在写<select>标签中,有一个resultType属性,此时select标签中,select语句的返回字段要与resultType属性指定的类的属性名称一致,此时成为自动映射,但是当要接收查询接口的类的属性名称,与select语句的返回字段不一致时,mybatis时无法自动进行映射的,此时需要程序员手动指定映射,此时就用到resultMap标签. 2. <resu

mybatis resultmap标签type属性什么意思

mybatis resultmap标签type属性什么意思? :就表示被转换的对象啊,被转换成object的类型啊 <resultMap id="BaseResultMap" type="BaseObject"> <id property="id" column="id" /> <result property="appId" column="appid"

在配置文件web.xml中配置Struts2的启动信息

在配置文件web.xml中配置Struts2的启动信息: <?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://ja

SpringBoot配置文件application.properties数据库配置

1 #DB Configuration 2 spring.datasource.driver-class-name=com.mysql.jdbc.Driver 3 spring.datasource.url=jdbc:mysql://127.0.0.1:3306/user?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = GMT 4 spring.datasource.username=roo

6.maven的pom.xml配置文件中常用的配置标签解析

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <!-- 指定当前pom的版

maven的pom.xml配置文件中常用的配置标签解析(2018-03-13)

来自:https://www.cnblogs.com/Nick-Hu/p/7288198.html 拿过来记录下 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://mave

spring配置文件&lt;import&gt;标签中使用${}占位符获得配置文件的属性值

一般情况下我们在Spring的配置文件中使用<import>标签是这样的,<import resource="spring-other.xml">,但是最近项目中使用到其他工程的依赖jar包,在自己的spring配置文件中需要这样写 <context:property-placeholder location="classpath:eoa/eoa_config.properties" /> <import resource=