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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:53:56+00:00 2026-06-18T10:53:56+00:00

i hav a home controller within which i hav 2 methods one is @RequestMapping(value

  • 0

i hav a home controller within which i hav 2 methods one is

    @RequestMapping(value = "/mypage.te", method = RequestMethod.GET)
    public String mypage1(Locale locale, Model model){

        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName(); //get logged in username 
        model.addAttribute("username", name);       
        model.addAttribute("customGroup",grpDao.fetchCustomGroup());        
        model.addAttribute("serverTime", formattedDate);
        model.addAttribute("username", name);

        return "mypage";
}

here in this method actually i call grpDao.fetchCustomGroup() method from a Dao class which performs a native query and fetches data and returns and it is saved in customGroup.

now the same fetchcustomGroup() method is to be used in another method i.e

@RequestMapping(value = "/manageGrps.te", method = RequestMethod.GET)
public String man_grp_connections(@RequestParam("id") Integer groupId,@RequestParam("name") String groupName, Model model) {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    String name = auth.getName();
    System.out.println("I am in the fetchCustomGroup controller");  
    int profileid=grpDao.getProfileId(name);        
    //model.addAttribute("customGroup",grpDao.fetchCustomGroup());
    model.addAttribute("memberList",grpDao.fetchGroupMembers(groupId,profileid));
    model.addAttribute("groupid",groupId);
    model.addAttribute("profileid",profileid);

    model.addAttribute("groupName",groupName);
    System.out.println("groupid="+groupId);
    System.out.println("groupName="+groupName);
    return "manageGrps";
}

so instead of calling the fetchCustomGroup() in both the methods i just want to call in only one method and use the result in both the methods in the home controller.

so how can i use customGroup in another method to use the result of the fetchCustomGroup()

  • 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-06-18T10:53:57+00:00Added an answer on June 18, 2026 at 10:53 am

    I think that what you want is to avoid executing the query twice. This can be done in different ways. The easiest way would be to assign the response to a variable in your controller and then use a getter instead of the dao. Controllers are singleton by default. Something like :

    private Foo customGroup;
    
    private synchronized Foo getCustomGroup() {
        if(customGroup == null) {
            customGroup = grpDao.fetchCustomGroup();
        } 
        return customGroup;
    }
    

    And then use getCustomGroup() instead of grpDao.fetchCustomGroup()

    I don’t know what you are using for your persistence but using cache would also be a good idea to avoid executing the query twice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hav especific need of removing word from string, But I am having problem
i am new to this iphone.... i hav navigation controller ,itoolbar having the button
i hav created a jsp page from which i m taking some values and
I hav tis example code here which i am trying. char test[256], test1[256]; char
I hav a code where Include method contains lowerd name of navigation property (Include(descriptions)
i hav a piece of code in which i have been comparing 2D and
I hav a table with following fields public class ActivationCode { public virtual int
i hav String date & i want to inceament date by 1 & it
I hav a string e.g. 2010-09-24 . Now I want this string read as
i hav a tabular forms used to generate reports which are html files and

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.