DBFound2.2クエリはlistタイプの使用を返します
1822 ワード
一、まずモデルファイルを書きます。 <?xml version="1.0" encoding="UTF-8"?>
<model xmlns="http://dbfound.googlecode.com/model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://dbfound.googlecode.com/model https://dbfound.googlecode.com/svn/tags/v2/model.xsd">
<query pagerSize="10" >
<sql>
<![CDATA[
SELECT
u.user_id,
u.user_name,
u.role_id,
u.user_code,
u.status
u.create_date date,
u.password
FROM SYS_USER u
#WHERE_CLAUSE#
order by u.user_code
]]>
</sql>
</query>
</model>
二、それからUserのdtoオブジェクトを書きますimport java.util.Date;
import com.nfwork.dbfound.model.reflector.Column;
import com.nfwork.dbfound.util.JsonUtil;
public class User {
@Column(name="user_name")
String userName;
String password;
@Column(name="create_date")
Date createDate;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String toString(){
return JsonUtil.beanToJson(this);
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
}
三、最後にテストクラスを書くpublic class TestUser {
public static void main(String[] args) {
DBFoundConfig.init("${@classpath}/model-test.xml");
Context context = new Context();
List<User> users = ModelEngine.query(context, "sys/user", null, User.class).getDatas();
System.out.println(users);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<model xmlns="http://dbfound.googlecode.com/model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://dbfound.googlecode.com/model https://dbfound.googlecode.com/svn/tags/v2/model.xsd">
<query pagerSize="10" >
<sql>
<![CDATA[
SELECT
u.user_id,
u.user_name,
u.role_id,
u.user_code,
u.status
u.create_date date,
u.password
FROM SYS_USER u
#WHERE_CLAUSE#
order by u.user_code
]]>
</sql>
</query>
</model>
import java.util.Date;
import com.nfwork.dbfound.model.reflector.Column;
import com.nfwork.dbfound.util.JsonUtil;
public class User {
@Column(name="user_name")
String userName;
String password;
@Column(name="create_date")
Date createDate;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String toString(){
return JsonUtil.beanToJson(this);
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
}
public class TestUser {
public static void main(String[] args) {
DBFoundConfig.init("${@classpath}/model-test.xml");
Context context = new Context();
List<User> users = ModelEngine.query(context, "sys/user", null, User.class).getDatas();
System.out.println(users);
}
}