|
发表于 2020-7-30 17:15:02
|
显示全部楼层
/**
* DB検索
*/
public void findUsers() {
Query query;
String namePattern = null;
//入力されたユーザネーム表示
if (!user.getUserName().equals("")) {
namePattern = '%' + user.getUserName() + '%';
}
//一覧検索
if (user.getUserCode() == "" && user.getUserName() == "") { query = em.createQuery("from User");
}else if(user.getUserCode() != "" && user.getUserName() == "") {
query = em.createQuery("from User where user_code = :code");
query.setParameter("code", user.getUserCode());
log.info(">>>ユーザコード検索");
}
else if (user.getUserCode() == "" && user.getUserName() != "") {
query = em.createQuery("from User where user_name like :userName");
query.setParameter("userName", namePattern);
log.info(">>>ユーザ名検索");
}
else {
query = em.createQuery("from User where user_code = :code and user_name like :userName");
query.setParameter("code", user.getUserCode());
query.setParameter("userName", namePattern);
log.info(">>>ユーザコード・ユーザ名検索");
}
userList = query.getResultList();
log.info(">>>show userlist - #0", userList);
if (userList.isEmpty()) {
log.info(">>>ユーザリストが空");
return;
}
for(User u: userList) {
log.info(">>>show userList - #0 #1", u.getUserCode(), u.getUserName(), u.getPassword());
}
} |
|