Mybatis 入门相关 如何将获得返回的所有数据对应到POJO类的LIST

unloserv 2016-03-21 10:44:42
如果查询一条数据

//mapper
<select id="select" resultType="com.pojo.Student" parameterType="java.lang.String">
select * from user where name=#{gender}
</select>

//查询并print数据
public static void selectUser(){
SqlSession session= factory.openSession();
try {
Student s=new Student();
s=session.selectOne("mapper.StudentMapper.select", "male");
System.out.println(s.toString());
}
catch (Exception e) {e.printStackTrace();}
finally {session.close();}

}



如果是多条数据怎么写呢
我试着写了点



//mapper
<select id="select" resultType="com.pojo.Student" parameterType="java.lang.String">
select * from user where name=#{gender}
</select>


public static void selectUser(){
SqlSession session= factory.openSession();
try {
//Student s=new Student();
List <Student>SList= new ArrayList<Student>();

SList=session.selectList("mapper.StudentMapper.select", "male");
System.out.println(SList.size());
for (Student student : SList) {
System.out.println(student.toString());
}
} catch (Exception e) {
e.printStackTrace();
}finally {
session.close();
}
}


运行之后不抱错
但是读不出来数据

正确的格式应改怎么写呢?
...全文
184 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
unloserv 2016-03-21
  • 打赏
  • 举报
回复
已解决 SQL语句写错了 查询条件 name=#{gender} 应改写成 gender=#{gender}

50,530

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧