简体   繁体   English

如何在 spring Controller 中的方法之间传递参数?

[英]How do i pass parameters between methods in a spring Controller?

I want to send the value of the variable "b" from AfterLogin function to EnterCoupon function.我想将变量“b”的值从 AfterLogin function 发送到 EnterCoupon function。 Is it possible to send the CustomerID and Password parameters to the EnterCoupon function from AfterLogin function?是否可以从 AfterLogin function 将 CustomerID 和 Password 参数发送到 EnterCoupon function?

@RequestMapping("AfterLogin")
    public String AfterLogin(Model m,@RequestParam("CustomerID") String cid, @RequestParam("Password") String pswd) {
        double b=dao.getCustomer(cid, pswd);
        System.out.println(b);
        if(b!=0) {
            m.addAttribute("Balance",b);
            m.addAttribute("cid", cid);
            m.addAttribute("pswd", pswd);
            m.addAttribute("cst", new Coupon());
            return "EnterCoupon";
        }
        {
            m.addAttribute("msg","Invalid Customer ID or Password");
            return "Failure";
        }   
}
@RequestMapping("EnterCoupon")
public ModelAndView EnterCoupon(@ModelAttribute("cst")Coupon c, @RequestParam("CouponCode")String cc)
{
    double nb=cs.NewBalance(b, dao.getCoupon(cc));
    
    if(nb!=0)
    {
        ModelAndView mv=new ModelAndView("CashBack","cst",cst);
        
        return mv;
    }
    else
    {
        ModelAndView mv=new ModelAndView("Failure","msg","Invalid Coupon Code");
        return mv;
    }
}

Thank you for the help.感谢您的帮助。

This is contradicting the whole purpose of Spring security.这与 Spring 安全性的全部目的相矛盾。 You should not be handling user login in that way.您不应该以这种方式处理用户登录。

Ideally, you should implement spring security.理想情况下,您应该实施 spring 安全性。 Use it to authenticate and authorise your users.使用它来验证和授权您的用户。 Then, your logged in user will be accessible to any method throughout the application through security context holder然后,您的登录用户将可以通过安全上下文持有者在整个应用程序中访问任何方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM