java - 检索特定 id 上的特定记录信息
问题描述
NewAccountDAOImpl
it is getting particular record id, username and password
according to that it should retrieve the records
@Transactional
@Modifying
public boolean checkLogin(int id, String username, String password){
System.out.println("In Check login"+ id);
System.out.println("In Check login"+ username);
System.out.println("In Check login"+ password);
Session session = sessionFactory.openSession();
boolean userFound = false;
//Query using Hibernate Query Language
//tring SQL_QUERY =" from NewAccount as n where n.id=? and n.username=? and password=?";
String SQL_Query=" from NewAccount where id=:id";
Query query = session.createQuery(SQL_Query);
query.setParameter("id",id).uniqueResult();
//query.setParameter(0,id);
//query.setParameter(1,username);
//query.setParameter(2,password);
List list = query.list();
if ((list != null) && (list.size() > 0)) {
userFound= true;
}
session.close();
return userFound;
}
控制器类
从银行余额表格中获取信息,例如 id、用户名、密码。我将它们添加到 checkLogin 方法参数它返回布尔值
@RequestMapping(value = "/balanceSave", method = RequestMethod.GET)
public ModelAndView saveBk(ModelAndView model, HttpServletRequest req,
HttpServletResponse res, @ModelAttribute NewAccount newaccount) {
int id=Integer.parseInt(req.getParameter("id"));
String username=req.getParameter("username");
String password=req.getParameter("password");
boolean userExists = newaccountService.checkLogin( id, username, password);
if(userExists ){
model.addObject("newaccount", newaccount);
return new ModelAndView("redirect:viewBalanceMoney");
}
return new ModelAndView("BalanceForm");
}
here i am sending list data to a jsp page viewbalanc
// 查看新账户余额
@RequestMapping(value = "/viewBalanceMoney", method = RequestMethod.GET)
public ModelAndView viewBalanceMoney(ModelAndView model) {
// public NewAccount getNewAccount(int newaccountid);
List<NewAccount> listnewaccount = newaccountService.getAllNewAccounts();
model.addObject("listnewaccount", listnewaccount);
model.setViewName("viewBalanc");
return model;
}
图 1 显示了将输入发送到控制器方法的平衡表
图 2 显示检索到的记录,但我需要特定的 id 记录信息
图2
解决方案
您可以使用@PathVariable
并调用该 accountId 的方法来执行此操作。
@RequestMapping(value = "/viewBalanceMoney/{newAccountId}", method = RequestMethod.GET)
public ModelAndView viewBalanceMoney(@PathVariable("newAccountId") Integer newaccountid,
ModelAndView model) {
//write code for fetching data for newaccountid
}
推荐阅读
- kentico - Kentico - 在父转发器上显示兄弟文档名称
- amazon-web-services - 我可以在 Spring Boot/Cloud @SqsListener 上设置 AWS 凭证吗?(爪哇)
- python - Python - 打开受密码保护的 CSV 以读取/写入
- python - 使用python如何摆脱从网站上抓取的文本中的尾随空格
- go - 使用 add 运算符连接字符串时,Go 变量转义到堆
- python - 我有一个关于 Python 字母数值计算的问题
- c++ - 为什么在返回类型选项时返回 None
当 T 不是引用时不返回空指针 - c++ - 在 C++ 中计算二项式系数模块素数 p
- rdf - graphDB 规则集(RDFS-Plus)与 Protege(Pellet/Hermit)中“表现力”差异的示例
- c - Cortex M3 的 Keil ARMCC int64 比较