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

My company has been evaluating Spring MVC to determine if we should use it
I'm currently building a Spring MVC application. I was looking to use JSP pages
What is a very good jsp framework to use with Spring MVC. Are the
I am using Spring MVC to build my web application, and I have a
We are using Hibernate 3.1 with Spring MVC 2.0. Our problem occurs when data
I'm working on a Spring MVC project, and I have unit tests for all
I'm building a MVC web application (using the Spring MVC framework), and I'm a
I basically have the following flow: XML -> JSON -> Spring MVC -> jsp
In every MVC framework I've tried (Rails, Merb, Waves, Spring, and Struts), the idea
Almost every new Java-web-project is using a modern MVC-framework such as Struts or Spring

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.