public Object userQuery(String name) {
try {
session = this.sessionFactory.openSession();
String sql = "select * from phome_enewsuser where username='"+ name + "'";
Object obj=session.createSQLQuery(sql).uniqueResult();
return obj;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
我获取到object对象怎么在java后台怎么解析object 获取到它里边的内容
String sql = "select * from phome_enewsuser where username='"
+ name + "'";
Query query = session.createSQLQuery(sql).addEntity(PhomeEnewsuser.class);
List<PhomeEnewsuser> userList=query.list();
for (int i = 0; i < userList.size(); i++) {
System.out.println(userList.get(i).getUserid());
System.out.println(userList.get(i).getUsername());
}
把Object换成你的映射对象
转成我要映射的那个对象查不到东西的我才用object接受可以查到数据但是不知道怎么解析出来它
比如查的是User这个实体,先要把object转换成具体的实体
User user = (User)obj.get(0);
兄弟 用get(0),没有这个方法把 报错的