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 265783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:47:59+00:00 2026-05-11T22:47:59+00:00

Lets assume a simple Spring MVC Controller that receives the ID of a domain

  • 0

Lets assume a simple Spring MVC Controller that receives the ID of a domain object. The Controller should call a service that should do something with that domain object.

Where do you “convert” the ID of the domain object into the domain object by loading it from the database? This should not be done by the Controller. So the service method interface has to use accept the ID of the domain object instead of the domain object itself. But the interface of the service would be nicer if it takes the domain object as a parameter.

What are your thoughts about this common use case? How do you solve this?

  • 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-11T22:47:59+00:00Added an answer on May 11, 2026 at 10:47 pm

    The controller should pass the id down into the service layer and then get back whatever is needed to render the rest of the HTTP response.

    So –

    Map<String,Object> doGet (@RequestParam("id") int id) {
         return serviceLayer.getStuffByDomainObjectId(id);
    }
    

    Anything else is just going to be polluting the web layer, which shouldn’t care at all about persistence. The entire purpose of the service layer is to get domain objects and tell them to perform their business logic. So, a database call should reside in the service layer as such –

    public Map<String,Object> getStuffByDomainObjectId(int id) {
        DomainObject domainObject = dao.getDomainObjectById(id);
        domainObject.businessLogicMethod();
        return domainObject.map();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This should be simple, but I can't figure it out For example, lets assume
lets assume the following simple Object: class Mock: def __init__(self, name, age): self.name =
Lets assume I've got an authorization token from user, that I will use later
Lets assume that we have PyV8: import PyV8 ctxt = PyV8.JSContext() and a python
Lets assume a scenario that i have a remote, a developer1 and a developer2.
Lets assume that I have the following configuration in my conf/InjectionConfig.groovy file: x {
I am having a question with Jackson that I think should be simple to
Today I come across a Function that makes me really wondering. So lets assume
I cant find the answer anywhere. The quesion is (?) simple. Lets assume I
Let's assume we have a simple internet socket, and it's going to send 10

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.