what the hell is model and why controller returns random string?

hey guys. can smb explain what the hell model is? bc i tried googling and its just vaguely said that model is your data. yes, i know its from MVC pattern, but it still doesnt make any sense, can smb explain what the f is going on here:
@GetMapping("/importBgwEod")
public String importBgwEod(Model model) throws JAXBException, IOException {
importService.importBgwEod(getUserId());
model.addAttribute("status", "Success!!!");
return "status";
}
@GetMapping("/importBgwEod")
public String importBgwEod(Model model) throws JAXBException, IOException {
importService.importBgwEod(getUserId());
model.addAttribute("status", "Success!!!");
return "status";
}
how can importBgwEod accept model argument, but its not requeired for the GET request? why this method is returning random string status? where do i get this needed model from? thx
28 Replies
JavaBot
JavaBot6mo ago
This post has been reserved for your question.
Hey @bambyzas! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
bambyzas
bambyzasOP6mo ago
but how can importBgwEod accept model argument, but its not requeired for the GET request?
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
bambyzas
bambyzasOP6mo ago
what thats not what i asked i asked about one thing, and u r talking about smth other than that
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
bambyzas
bambyzasOP6mo ago
what are you talking about sorry but i honestly dont understand ur point and what u mean
Rag...JN 🌌 🦡 👽 💰 🐊
do you have any option to call the "/importBgwEod"?
Peter Rader
Peter Rader6mo ago
how can importBgwEod accept model argument, but its not requeired for the GET request? The request arrives the spring framework in the first place. Then spring notice that the getmapped method requires a argument of type "Model" (most likely org.springframework.ui.Model). Spring now have a special logic for that. Spring creates a new, plain instance of Model. Spring put arguments from the session and from the request into that model and with that instance, the method importBgwEod is called. Now, the return-string is indicating what template should be filled and sent back to the browser.
Rag...JN 🌌 🦡 👽 💰 🐊
So the model is not an object that we can access a row of a table row?
Rag...JN 🌌 🦡 👽 💰 🐊
and you access it like this
No description
Peter Rader
Peter Rader6mo ago
At this moment only the OP knows what full-qualified-name the class Model has. It must be a type having the method "addAttribute". I am certain that the full-qualified-classname is org.springframework.ui.Model. Because: 1. The classname is the same 2. The method exists 3. The parameters match.
bambyzas
bambyzasOP6mo ago
finally someone explained it to me. thanks alot!. so basically since im using MVC pattern, sprint automagically takes care of model?
JavaBot
JavaBot6mo ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
bambyzas
bambyzasOP6mo ago
yeah, with postman
Rag...JN 🌌 🦡 👽 💰 🐊
So what is your Model's fully qualified name?
Rag...JN 🌌 🦡 👽 💰 🐊
I am just curious to know you can even pass an Entity like this
No description
bambyzas
bambyzasOP6mo ago
no idea. idk how/where to look
Rag...JN 🌌 🦡 👽 💰 🐊
on the top imports find the line what Model
Rag...JN 🌌 🦡 👽 💰 🐊
somewhere here
No description
bambyzas
bambyzasOP6mo ago
No description
Rag...JN 🌌 🦡 👽 💰 🐊
good shit, now you can see search for it for futher details
Peter Rader
Peter Rader6mo ago
Heh, I knew it 😄
Rag...JN 🌌 🦡 👽 💰 🐊
so what do they mean by a place holder?
No description
Rag...JN 🌌 🦡 👽 💰 🐊
hmm it's like a dynamic object hah
Peter Rader
Peter Rader6mo ago
Yea, placeholder is misleading. It is an dynamic-outgoing-value-wrapper to be used as an method-argument. Usually method arguments should consume data into the method. But this dynamic-object is primarily used for returning values. Usually a returning value is used with the return command of the method-result-type. Borgrel was absolutly correct that this is a not well written code! Since we have two result-values in that code (the attribute "status" and the template-view-name "status"), you better use the Return-Type return new ModelAndView(...);
JavaBot
JavaBot6mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server