Solved

Wether to keep url params in method parameters or fetch it inside the method

Posted on 2016-08-11
4
58 Views
Last Modified: 2016-08-13
HI,
I have a function like :
 
@RequestMapping(value = "")
    public ModelAndView newNote(@RequestParam(value = "noteEvent", required = false) String noteEvent, HttpServletResponse response, HttpServletRequest request) throws IOException {
        String token = request.getParameter("token");

Open in new window

The noteEvent is actually a json param like : { "name":"sdfsdf","button":"sdfds","userId":"u:guid1","sdfdf":"sdfds","chat":"u:sdf","chatName":"Ben sdf"}

1) Once approach is i put everything in the params... Like here i am accessing request.getParameter("token")
which i could move to method params.. But somtimes i have noticed the function param list gets too large.

2) Other approach is to not put anything in params and access everything inside.

3) Or mix match

Need views from experts. What approach you follow and when ...Whats best to do ?

Thanks
0
Comment
Question by:Rohit Bajaj
  • 2
4 Comments
 
LVL 16

Expert Comment

by:gurpsbassi
ID: 41753606
Is this a GET request?
0
 

Author Comment

by:Rohit Bajaj
ID: 41753641
yes this is a get request
0
 
LVL 35

Accepted Solution

by:
mccarl earned 400 total points
ID: 41753679
Personally, I would probably just put them all as method parameters, but I don't have much of a problem with methods that have numerous parameters, I know some people do though.

The other possibility that I might consider, if you have some params that are required and some that are optional, is to leave the required ones in the method and attempt to retrieve the optional ones if/when needed.
0
 
LVL 16

Assisted Solution

by:gurpsbassi
gurpsbassi earned 100 total points
ID: 41754138
if you were to flatten that JSON object into request params, it wouldn't be so bas as mccarl suggested. Its only a handful.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question