当用户传递参数时,我有一个搜索名称的方法。 现在我需要一种方法来告诉我员工在公司中的角色
我们的想法是将这些数据插入到组合框中。
这是我用来查找名称传递参数的方法:
public List<User> findbyName(String name) {
EntityManager em = getEntityManager();
String sql = "select u from User u where UPPER(u.name) like UPPER ('" + name + "%')";
List<User> u = null;
try {
u = (List<User> ) em.createQuery(sql).getResultList();
} catch (Exception e) {
return null;
}
return u;
}
以下是我尝试做的方法:
public List<User> findbyRole(){
EntityManager em = getEntityManager();
String sql = "select u from User u where UPPER(u.role) like (journalist)";
List<User> u = null;
try {
u = (List<User> ) em.createQuery(sql).getResultList();
} catch (Exception e) {
return null;
}
return u;
}
插入组合框的代码,对吗?
List <User> list= new UserJpaController().findbyRole();
for(int i=0;i<lista.size();i++){
combojournalist.addItem(list.get(i).getCargo());
}
答案 0 :(得分:0)
如果要在查询中使用文字字符串define i32 @dbl(i32* %a, i32 %x) #0 {
call void @__myFuncCall(i32 1, i32 1)
%1 = alloca i32, align 4
%2 = alloca i32*, align 8
%3 = alloca i32, align 4
store i32* %a, i32** %2, align 8
%4 = ptrtoint i32* %3 to i64
call void @__myStore(i32 2, i64 %4)
store i32 %x, i32* %3, align 4
%5 = load i32* %3, align 4
%6 = ptrtoint i32* %3 to i64
call void @__myLoad(i32 3, i64 %6, i32 %5)
call void @__myLoad(i32 4, i64 0, i32 5)
%7 = icmp sgt i32 %5, 5
call void @__myApply(i32 5, i32 14, i1 %7)
br i1 %7, label %_then, label %_else
; <label>:8 ; preds = %_then
%9 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([3 x i8]* @.str, i32 0, i32 0))
call void @__Clear(i32 8)
%10 = load i32* %3, align 4
%11 = ptrtoint i32* %3 to i64
call void @__myLoad(i32 9, i64 %11, i32 %10)
%12 = ptrtoint i32* %1 to i64
call void @__StoreTo(i32 10, i64 %12)
store i32 %10, i32* %1
br label %18
_else: ; preds = %0
call void @__test(i32 7, i32 2, i32 0)
br label %13
_then: ; preds = %0
call void @__test(i32 6, i32 1, i32 1)
br label %8
; <label>:13 ; preds = %_else
%14 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([3 x i8]* @.str1, i32 0, i32 0))
call void @__Clear(i32 11)
%15 = load i32* %3, align 4
%16 = ptrtoint i32* %3 to i64
call void @__myLoad(i32 12, i64 0, i32 2)
call void @__myLoad(i32 13, i64 %16, i32 %15)
%17 = mul nsw i32 2, %15
call void @__myApply(i32 14, i32 2, i32 %17)
call void @__myStore(i32 15, i64 %12)
store i32 %17, i32* %1
br label %18
; <label>:18 ; preds = %13, %8
%19 = load i32* %1
%20 = ptrtoint i32* %1 to i64
call void @__myLoad(i32 16, i64 %20, i32 %19)
call void @__myReturn(i32 17)
ret i32 %19
}
,则需要将其放入引号中,或将其作为参数传递。否则,JPA会认为journalist
是别名,但查询中未定义此类别名。
所以你的查询应该是这样的(参见记者的引言):
journalist
或者如果您使用参数,这总是更好的选择:
select u from User u where UPPER(u.role) like ('journalist')