關(guān)于Mybatis 使用select返回?cái)?shù)據(jù)的問(wèn)題
代碼如下
public interface BookMapper {
@Select( "SELECT * FROM book")
List<Book> getAllBooks();
}
實(shí)體類 (省略部分get/set方法)
package com.ly3.entity;
public class Book {
private String id;
private String name;
private int pageSize;
/**
* 建議這里需要有默認(rèn)的無(wú)參構(gòu)造函數(shù)
* 出錯(cuò)的情形 如果select id,name,pageSizem,如果只有一個(gè)構(gòu)造函數(shù)且type為String.class,或int,則不會(huì)有問(wèn)題
* 如果有多個(gè)構(gòu)造函數(shù)【Book(String name),Book(int pageSize)】且里面沒(méi)有完全匹配【Book(String id,String name, int pageSize)】的構(gòu)造函數(shù)
* 則會(huì)報(bào)錯(cuò),要么類型轉(zhuǎn)換錯(cuò)誤,要么提示沒(méi)有構(gòu)造函數(shù)匹配
*/
public Book() {
}
/* public Book(String name) {
this.name = name;
}*/
public Book(int pageSize) {
this.pageSize = pageSize;
}
/*public Book(String id,String name, int pageSize) {
this.id=id;
this.name = name;
this.pageSize = pageSize;
}*/
當(dāng)返回的列值不能在構(gòu)造函數(shù)中