Solved

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

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

803 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