java - RequestMapping with annotation vs parameter -


i thinking general requestmapping question. without choosing specific mvc framework, comparing annotation based request mapping simple parameter checker mapping, better?

lets want create web service, should handle example "add" , "remove" operation.

using annotations this:

@path("/add") public void add(string addable) {}  @path("/remove") public void remove(string deletable) {} 

using parameter this:

@path("/operation") public void dooperation(operation op) {     string type = op.gettype();     if ("add".equals(type)) {         add(op);     } else if ("remove".equals(type)) {         remove(op);     } } 

in second example, lets operation object built json object. idea have general operation, has type parameter , calling same request (/operation in case) , actual request type inside json object.

i know first 1 looks better, there other reason why better solution? has better performance or else?

  • there shouldn't significant performance difference.
  • the first code more readable
  • you have pass parameter time second solution

your question can simplified case:

class {  methoda()  methodb() }  class b {  methodc(operation) {     check operation there , invoke needed method.  } } 

you go class b in cases don't want give direct access other methods or if want make work before invoking methoda() or methodb(). example, authenticate user.

in mvc frameworks have other tools that.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -