本文介绍了如何在Spring MVC中将一个控制器调用到另一个控制器URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Spring MVC的新手,我想从一个控制器调用方法到另一个控制器,我该怎么做.请在下面检查我的代码
Hi I am new to Spring MVC ,I want to call method from one controller to another controller ,how can I do that .please check my code below
@Controller
@RequestMapping(value="/getUser")
@ResponseBody
public User getUser()
{
User u = new User();
//Here my dao method is activated and I wil get some userobject
return u;
}
@Controller
@RequestMapping(value="/updatePSWD")
@ResponseBody
public String updatePswd()
{
here I want to call above controller method and
I want to update that user password here.
how can I do that
return "";
}
任何人都可以帮助我.
推荐答案
您永远不必将业务逻辑放入控制器中,并且与数据库相关的业务逻辑更少,事务类/方法应该在服务层中.但是,如果您需要重定向到其他控制器方法,请使用redirect
You never have to put business logic into the controller, and less business logic related with database, the transactionals class/methods should be in the service layer. But if you need to redirect to another controller method use redirect
@RequestMapping(value="/updatePSWD")
@ResponseBody
public String updatePswd()
{
return "redirect:/getUser.do";
}
这篇关于如何在Spring MVC中将一个控制器调用到另一个控制器URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!