@SuppressWarnings("unchecked")
@Override
public List<Goods> getGoodsUseGoodsName(String goodsName) {
System.out.println("get goods with goodsnam");
System.out.println(goodsName);
List<Goods> list = sessionFactory
.getCurrentSession()
.createQuery(
"from t_goods tg where tg.goodsName=" + "'"+goodsName+"'")
.list();
return list;
}
my action:
List<UserInfo> list = userService.isExistUser(username, password);
UserInfo u = (UserInfo) list.get(0);
System.out.println(u.getAdmin());
following error 0.0 . . . . . . . . . . . . . . .
------ Solution ------------------------------------ --------
select * from t_UserInfo u where u.username =? and u.password =? ") returns a bunch of list array
not correspond to the set of classes
should be from t_UserInfo u where u.username =? and u.password =? " Obviously Cuoa
---- - Solution --------------------------------------------
createSQLQuery original ecological sql statement is a query , the query should be inside the table name . The result is an array object .
createQuery is hql query , the query is inside the object name . The result is an array of entities .
tell you type conversion mistake.
------ For reference only -------------------------------------- -
isExistUser method returns a value to reflect removed. . .
------ For reference only -------------------------------------- -
generics. . . . . . Wrong
------ For reference only ----------------------------------- ----
UserLogin
------ For reference only --------------------- ------------------
you list.get (0) how will the return type is UserInfo, not the Goods Well
------ For reference only ---------------------------------------
posted wrong . This is ==
@Override
public List<UserInfo> isExistUser(String username, String password) {
System.out.println("get user with name");
Query query = sessionFactory
.openSession()
.createSQLQuery(
"select * from t_UserInfo u where u.username=? and u.password=?");
query.setParameter(0, username);
query.setParameter(1, password);
@SuppressWarnings("unchecked")
List<UserInfo> list = query.list();
System.out.println(list.size());
return list;
}
------ For reference only ----------------------------------- ----
generics. . . . . . Wrong
did not understand -
------ For reference only ---------------------------------------
amount ? ? ? ?
------ For reference only ---------------------------------------
UserAction code issues look
------ For reference only ---------------------------------- -----
I said you put generics removed, and then print it look okay baby ?
mistake in your generics on . . . . ! !
------ For reference only -------------------------------------- -
@ SuppressWarnings ("unchecked")
do not add this , we write the code cleared the red dot of light is not enough , the yellow dot description is not standardized , but also needs to change .
As for your question, you do an experiment
@ SuppressWarnings ("unchecked") / / this removed, do not
List
System.out.println (list.size ());
this section , you enter
query.list () ;/ / then mouse over ; behind
while pressing
Alt + Shift + l
automatically generate a return type object, and you look at the return type is not UserInfo type. .
------ For reference only ---------------------------------- -----
type conversion errors.
------ For reference only -------------------------------------- -
s Bangding - ----- For reference only ---------------------------------------
the above two methods are right.
1. 12 F method
2. removed @ SuppressWarnings ("unchecked"), and all the list followed by the generic
------ For reference only ---- -----------------------------------
String sql = "select * from base_menu where resourceid in (select menu_id from BASE_MENU_ROLE where role_id in (select role_res_id from BASE_USER_ROLE where user_res_id = '"+ user.getResourceId ( ) + "' ) ) " ;
Session session = super.getSession ();
List
没有评论:
发表评论