this.getJdbcTemplate().query();取多条不一样数据库数据,返回的是多条一样的数据
方法:privateList<MenuBean>getMenusByRoleInUser(UserBeanuser){StringgetMenuSql="selectm....
方法:
private List<MenuBean> getMenusByRoleInUser(UserBean user) {
String getMenuSql = "select m.menuid,m.menuname,m.menulink,m.pmenuid,m.orderid" +
" from T_MENU m,T_MENU_ROLE mr,T_USER u,T_USER_ROLE ur,T_ROLE r where" +
" r.del!=1 and m.del!=1 and u.userid=ur.userid and r.roleid=ur.roleid" +
" and r.roleid=mr.roleid and m.menuid = mr.menuid and u.userid='"
+ user.getUserid() + "' order by m.orderid asc";
List<MenuBean> menus =this.getJdbcTemplate().query(getMenuSql,MenuMapper);
return menus;
}
MenuMapper:
private RowMapper MenuMapper = new RowMapper() {
@Override
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
// TODO Auto-generated method stub
menu.setMenuid(rs.getInt("MENUID"));
menu.setMenuname(rs.getString("MENUNAME"));
menu.setMenulink(rs.getString("MENULINK"));
menu.setPmenuid(rs.getInt("PMENUID"));
menu.setOrderid(rs.getInt("ORDERID"));
return menu;
}
};
问题是,我数据库中有8条数据,该语句在plsql返回正确,在页面跑的时候返回的是8遍的最后一条数据,请问该怎么解决 展开
private List<MenuBean> getMenusByRoleInUser(UserBean user) {
String getMenuSql = "select m.menuid,m.menuname,m.menulink,m.pmenuid,m.orderid" +
" from T_MENU m,T_MENU_ROLE mr,T_USER u,T_USER_ROLE ur,T_ROLE r where" +
" r.del!=1 and m.del!=1 and u.userid=ur.userid and r.roleid=ur.roleid" +
" and r.roleid=mr.roleid and m.menuid = mr.menuid and u.userid='"
+ user.getUserid() + "' order by m.orderid asc";
List<MenuBean> menus =this.getJdbcTemplate().query(getMenuSql,MenuMapper);
return menus;
}
MenuMapper:
private RowMapper MenuMapper = new RowMapper() {
@Override
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
// TODO Auto-generated method stub
menu.setMenuid(rs.getInt("MENUID"));
menu.setMenuname(rs.getString("MENUNAME"));
menu.setMenulink(rs.getString("MENULINK"));
menu.setPmenuid(rs.getInt("PMENUID"));
menu.setOrderid(rs.getInt("ORDERID"));
return menu;
}
};
问题是,我数据库中有8条数据,该语句在plsql返回正确,在页面跑的时候返回的是8遍的最后一条数据,请问该怎么解决 展开
1个回答
2013-05-05
展开全部
this.getJdbcTemplate().query()
要的SQL应该是HQL。 使用了框架,应该尽量不要使用标准的SQL
要的SQL应该是HQL。 使用了框架,应该尽量不要使用标准的SQL
追问
我用的是struts2和spring,没有用hibernate,query时要用HQL?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询