sqlMapConfig.xml文件:
OrdersMapperCustom.xml 文件:
Orders 类:
package com.mx.resultType;import java.util.Date;public class Orders { private int id; private String user_id; private String number; private Date createtime; private String note; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getUser_id() { return user_id; } public void setUser_id(String user_id) { this.user_id = user_id; } public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } public Date getCreatetime() { return createtime; } public void setCreatetime(Date createtime) { this.createtime = createtime; } public String getNote() { return note; } public void setNote(String note) { this.note = note; } @Override public String toString() { return "Orders [id=" + id + ", user_id=" + user_id + ", number=" + number + ", createtime=" + createtime + ", note=" + note + "]"; } }
OrdersCustom 类:
package com.mx.resultType;public class OrdresCustom extends Orders{ private String username; private String sex; private String address; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } }
OrdersMapperCustom接口:
package com.mx.resultType;import java.util.List;public interface OrdersMapperCustom { public ListfindUser();}
Test 测试类:
package com.mx.resultType;import java.io.IOException;import java.io.InputStream;import java.util.List;import org.apache.ibatis.io.Resources;import org.apache.ibatis.session.SqlSession;import org.apache.ibatis.session.SqlSessionFactory;import org.apache.ibatis.session.SqlSessionFactoryBuilder;public class Test { public static void main(String[]args) throws IOException{ String resource = "sqlMapConfig.xml"; InputStream is = Resources.getResourceAsStream(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is); SqlSession sqlSession = sqlSessionFactory.openSession(); OrdersMapperCustom omc = sqlSession.getMapper(OrdersMapperCustom.class); Listlist=omc.findUser(); System.out.println(list); sqlSession.close(); }}