1. 程式人生 > 其它 >mybatis複雜對映

mybatis複雜對映

1.mybatis高階查詢

當實體類與表中欄位完全一致時,mapper檔案裡返回型別用resultType,否則要用resultMap,並且建立resultMap對映

package com.rf.domain;

import java.util.Date;

public class User {
//    `id` INT(11) NOT NULL AUTO_INCREMENT,
    private  int id;
//`username` VARCHAR(32) NOT NULL COMMENT '使用者名稱稱',
    private String usernameabc;
//`birthday` DATETIME DEFAULT NULL COMMENT '生日',
private Date birthdayabc; //`sex` CHAR(1) DEFAULT NULL COMMENT '性別', private String sexabc; //`address` VARCHAR(256) DEFAULT NULL COMMENT '地址',PRIMARY KEY (`id`) private String addressbc; //getter and setter 省略 }
public interface UserMapper {
public List<User> findAllResultMap();
}
<resultMap id="userResultMap" type="user">
<id column="uid" property="id"></id>
<result column="NAME" property="username"></result>
<result column="PASSWORD" property="username"></result>
</resultMap>
<select id="findAllResultMap" resultMap="userResultMap">
SELECT id AS uid,username AS NAME,password AS PASSWORD FROM USER
</select>