<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 类型的对象中。
在该结果映射配置中,使用了
该结果映射配置定义了 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 中,使用了
在每个
该 resultMap 中,将查询结果中的 id、order_id、num、type 和 content 列,分别映射到 Comment 对象的 id、orderId、num、type 和 content 属性中。
最终,当执行查询操作时,MyBatis 会根据该 resultMap 将查询结果映射成 Comment 对象,从而方便 Java 代码对查询结果进行处理和操作。
<resultMap id="BaseResultMap" type="com.tangu.fxyjytrust.po.BoilMedicine"> <id column="MED_CENTER_ID" property="id" jdbcType="INTEGER"/> <result column="MED_CENTER_NAME" property="name" jdbcType="VARCHAR"/> <result column="credit_code" property="creditCode" jdbcType="VARCHAR"/> <result column="city_address_id" property="cityAddressId" jdbcType="INTEGER"/> <result column="medicine_address_id" property="medicineAddressId" jdbcType="INTEGER"/> <result column="contact_name" property="contactName" jdbcType="VARCHAR"/> <result column="phone" property="phone" jdbcType="VARCHAR"/> <result column="del_flag" property="delFlag" jdbcType="INTEGER"/> </resultMap>
这段代码是一个 MyBatis 的 resultMap 配置,用于将查询结果映射到一个名为 "BaseResultMap" 的对象中。该对象的类型是 com.tangu.fxyjytrust.po.BoilMedicine。
在这个 resultMap 中,每一个
jdbcType 属性指定了数据库中对应列的数据类型,以便在映射时进行正确的类型转换。
请注意,这只是 resultMap 的配置,它并不包含实际的 SQL 查询语句。该配置通常与 SQL 映射文件中的 select 语句配合使用,以实现将查询结果映射到 Java 对象的功能。
相关推荐
















