in Education by
first of all,i am fairly new with spring mvc so .. how springmvc find the right class to instantiate and fill its object properties when sending post-request to some controller. for example lets assume i have this class package springmvc_test.user public class User { private String username; private String password; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } and controller class as the flowing @Controller @RequestMapping(value = {"/user"} ) public class UserController { private List users; @Autowired public UserController(List users) { this.users = users; } @RequestMapping(value = "/add",method = POST) public String addUser(User user,Model m){ users.add(user); //do some other stuf //..... } } when i do post-request for http://localhost/myapp/user/add along with form fields that has the same names as User class properties, it works fine. but my question is that how could springmvc find the User class and instantiated it ?although the User class is not annotated with noting at all note: i know that spring binds the User object properties by matching their names with form fields names JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
As the Spring Framework reference states in the respective section you should use either: @RequestBody, if you want to let a HttpMessageConverter deserialize your HTTP request to any Java Object @ModelAttribute if you want to get access to model variables, e.g. also out of your HTTP request. on the parameter which you want to associate with your request data.

Related questions

0 votes
    @RequestMapping annotation is used to map a HTTP request method (GET or POST) to a specific class or method in the ... which will handle the respective request. A. True B. False...
asked Nov 8, 2022 in Education by JackTerrance
0 votes
    I want to make a method that will populate the lst_List list with rows from various tables and fields. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I want to make a method that will populate the lst_List list with rows from various tables and fields. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I am working on wordpress with woocommerce and using WCK plugin for custom fields. I am creating products ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I want to get the search result using scrapy post request after giving the input to CP Number as 16308 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 1, 2022 in Education by JackTerrance
0 votes
    I am new to jmeter. I have been experimenting on creating a jmeter script manually by inspecting the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    I've recently seen quite a bit of the following pattern in Python: class Foo: pass class Bar: ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    I am using mac mojave 10.14.3, JDK 1.8, Serenity core 2.0.40 (latest) to develop my test ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    This is a cURL function that can send or retrieve data. It should work with any PHP app that ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    I am working on my first Android Application. What I am trying to do is a POST request to a REST ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    Is it possible to make a timeout of 3 seconds in a post request ? How ? My code for the moment ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    I am trying to calculate the progress of a file upload, so I was using Superagent. I was able to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    I am a very novice C# person so please dont be too hard on me Im trying to make a post request ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I have an Enum package com.javarnd.bbms.enums; public enum BloodTypeEnum { A_PLUS(1, "A+"), ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    I was wondering if I can customize my url into controller to accept null values @RequestMapping( value = " ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 28, 2022 in Education by JackTerrance
...