如何通过Java方法参数使用变量?
下面是一些简单的代码。
@RequestMapping(value="/main")
public ModelAndView main(ModelAndView model) {
model.addObject("project",mainService.selectProject());
return null;
}
到目前为止我认为参数的作用应该仅以方法名称(x,y等..)的形式在其他地方使用。
然而,当像上面的代码一样使用时,它不是一个接收某个值的角色,而是一个“一个变量?”或“一个构造函数?”
好像
可以像使用new一样使用,但我想知道原理。
能解释一下原理或者给我一个可以研究的关键词吗?
===
public ModelAndView main(ModelAndView model) {
ModelAndView model 中就是这部分。
当这部分调用方法(例如,方法名称(x,y))时,
我只是为了接收某些东西的值而想到它。
但是,上面的 ModelAndView 模型本身可以用作变量或构造函数。
据我所知,ModelAndView model = new ModelAndView();应该是 但是,这部分被省略了,可以通过在参数中声明来使用。
Below is some simple code.
@RequestMapping(value="/main")
public ModelAndView main(ModelAndView model) {
model.addObject("project",mainService.selectProject());
return null;
}
I thought until now that the role of parameter should be used only in the form of method name (x,y, etc..) elsewhere.
However, when used like the code above, it is not a role that receives a certain value, but rather a "one variable?" or "One constructor?"
It seems to be used like
It can be used as if using new, but I would like to know the principle.
Could you explain the principle or point me to a keyword that I can study?
===
public ModelAndView main(ModelAndView model) {
In the ModelAndView model is this part.
When this part calls the method (ex, method name (x, y))
I was only thinking of it for the purpose of receiving the value of something.
However, the ModelAndView model above can be used as a variable or constructor by itself.
From the line of knowledge I know, ModelAndView model = new ModelAndView(); should be However, this part was omitted and it can be used by declaring it in the parameter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论