<resultMap id="BaseResultMap" type="com.sinsegye.service.ps.modules.baseline.entity.MaterialBaselineEntity" > <result column="id" property="id" /> <result column="name" property="name" /> <result column="user_id" property="userId" /> <result column="remark" property="remark" /> <result column="url" property="url" /> <result column="is_delete" property="isDelete" /> <result column="created_at" property="createdAt" /> <result column="updated_at" property="updatedAt" /> </resultMap>
时间: 2023-12-05 20:47:35 浏览: 34
这是一个 MyBatis 的 resultMap 配置,用于将查询结果映射到对应的实体类 MaterialBaselineEntity 中。其中 column 属性表示查询结果中的列名,property 属性表示实体类中对应的属性名。这样配置后,查询结果就可以自动封装到 MaterialBaselineEntity 对象中了。
相关问题
<resultMap id="BaseResultMap" type="com.example.pojo.Admin" > <id column="id" property="id" jdbcType="INTEGER" /> <result column="username" property="username" jdbcType="VARCHAR" /> <result column="password" property="password" jdbcType="VARCHAR" /> </resultMap>
这是一个 MyBatis 的结果映射配置,id 为 BaseResultMap,类型为 com.example.pojo.Admin。该配置描述了如何将查询结果映射到 Admin 类型的对象中。
在该结果映射配置中,使用了 <id> 和 <result> 标签,分别表示主键列和普通列的映射关系。其中,column 属性指定了列名,property 属性指定了 Java 对象中对应的属性名,jdbcType 属性指定了列的 JDBC 类型。
该结果映射配置定义了 Admin 类型的三个属性的映射关系,分别是 id、username 和 password。在实际的查询中,可以通过 resultMap 属性来引用该结果映射配置,如下所示:
```
<select id="selectById" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select id, username, password from admin where id = #{id}
</select>
```
在该查询语句中,引用了 BaseResultMap 结果映射配置,从而将查询结果映射到 Admin 类型的对象中,提高了代码的可读性和可维护性。
<resultMap id="BaseResultMap" type="com.example.pojo.Comment" > <id column="id" property="id" jdbcType="INTEGER" /> <result column="order_id" property="orderId" jdbcType="INTEGER" /> <result column="num" property="num" jdbcType="INTEGER" /> <result column="type" property="type" jdbcType="VARCHAR" /> <result column="content" property="content" jdbcType="VARCHAR" /> </resultMap>
这是一个 MyBatis 中的 resultMap,id 为 BaseResultMap,type 为 com.example.pojo.Comment,用于将查询结果映射到 Comment 对象中。
在该 resultMap 中,使用了 <id> 和 <result> 标签来描述查询结果和 Java 对象之间的映射关系。其中,<id> 标签用于定义主键属性,<result> 标签用于定义普通属性。
在每个 <id> 和 <result> 标签中,都需要定义三个属性:column、property 和 jdbcType。其中,column 属性指定查询结果中的列名,property 属性指定 Java 对象中的属性名,jdbcType 属性指定属性的 JDBC 类型。
该 resultMap 中,将查询结果中的 id、order_id、num、type 和 content 列,分别映射到 Comment 对象的 id、orderId、num、type 和 content 属性中。
最终,当执行查询操作时,MyBatis 会根据该 resultMap 将查询结果映射成 Comment 对象,从而方便 Java 代码对查询结果进行处理和操作。