Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6101615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:31:11+00:00 2026-05-23T13:31:11+00:00

Spring MVC allows to define handler methods with a variety of parameters which are

  • 0

Spring MVC allows to define handler methods with a variety of parameters which are filled in with the appropriate values.

Is it possible to use the same approach to fill in the values into a POJO that is then passed to a handler method?

Currently, I have to do:

@RequestMapping
public ModelMap handle( @RequestParam("user") String user, ... )

What I’d like to do:

class HandlerPojo {
    @RequestParam("user") String user;
    ...
}

@RequestMapping
public ModelMap handle( HandlerPojo pojo )
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:31:12+00:00Added an answer on May 23, 2026 at 1:31 pm

    It is actually pretty simple, even without any Spring @RequestParam annotations inside POJO. What you are looking for is a custom WebArgumentResolver. Here is a complete example:

    @Service
    public class UserArgumentResolver implements WebArgumentResolver {
        @Override
        public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) throws Exception {
            if (methodParameter.getParameterType() == User.class) {
                return new User(webRequest.getParameter("user"));
            }
            return WebArgumentResolver.UNRESOLVED;
        }
    }
    

    Code is rather self-explanatory: if one of the handler parameters is of User type, retrieve request parameter named user and return whatever you want (of course it should be assignable to User. WebArgumentResolver.UNRESOLVED means that the resolver was incapable of handling this parameter and subsequent resolvers should be examined.

    Unfortunately resolver isn’t picked up by default, it must be registered:

    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="customArgumentResolver" ref="userArgumentResolver"/>
    </bean>
    
    <mvc:annotation-driven />
    

    That’s it! Your handler can now look like this:

    @RequestMapping
    public void handle(User user) {
        //...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm migrating a Spring MVC controller to use the newer style annotations, and want
I wish to use Spring MVC to provide a REST web service. However, running
I use Spring MVC [version: 2.5] and Security[version: 2.0.4]. My problem looks like that:
I have an ASP.NET MVC 2 application which in part allows a user to
Let's say I have a Spring MVC web application and it allows users to
I have a Restful web service developed in Spring MVC which currently returns farmer
I need to wait for a condition in a Spring MVC request handler while
I am using Spring MVC and Hibernate. I want to use the OpenSessionInViewFilter to
In Spring MVC a Dispatcher servlet is used as a front controller to handle
With Spring MVC, you can specify that a particular URL will handled by a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.