0

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.

enter image description here

8
  • Please clarify your question, I have no idea what you are asking. There is nothing constructor-like or new-like in the code you showed. If the annotation is not what you are asking about, remove it. Commented Mar 1, 2022 at 7:24
  • sorry. Edited the content. Also, my comment said that my question was considered a duplicate and replaced with an answer to another post instead. I don't know what this means, but I wrote it down because I thought I couldn't get a reply to my post. Commented Mar 1, 2022 at 7:35
  • I've reopened the question, but I have no idea what you're asking... Your method is declared to accept an input parameter of type ModelAndView and to return a result of type ModelAndView (or null, which it does in this case). Commented Mar 1, 2022 at 7:47
  • 1
    Sorry, this makes no sense at all Commented Mar 1, 2022 at 7:49
  • Oh, sorry. Let me explain the question again. First of all, ModelAndView is a simple example, and return null is a temporary part for convenience. As you just commented, ModelAndView was used as a parameter. That's the part I'm curious about. Commented Mar 1, 2022 at 7:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.