Solved

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

Posted on 2016-08-11
4
48 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 15

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 15

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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:

929 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now