java - Get request parameter with Play Framework? -



java - Get request parameter with Play Framework? -

i learning play framework , understand can map request such /manager/user as:

/manage/:user controllers.application.some(user:string)

how map request /play/video?video_id=1sh1?

you have @ to the lowest degree 2 possibilities, let's phone call them approach1 , approach2.

in first approach can declare routes param default value. 0 candidate, easiest build status on top of it. it's typesafe, , pre-validates itself. recommend solution @ beginning. second approach reads params straight request string need parse integer , additionally validate if required.

routes:

get /approach1 controllers.application.approach1(video_id: int ?=0) /approach2 controllers.application.approach2

actions:

public static result approach1(int video_id) { if (video_id == 0) homecoming badrequest("wrong video id"); homecoming ok("1: display video no. " + video_id); } public static result approach2() { int video_id = 0; if (form().bindfromrequest().get("video_id") != null) { seek { video_id = integer.parseint(form().bindfromrequest().get("video_id")); } grab (exception e) { logger.error("int not parsed..."); } } if (video_id == 0) homecoming badrequest("wrong video id"); homecoming ok("2: display video no. " + video_id); }

ps: lol realized want utilize string identifier... anyway both approaches similar :)

java playframework-2.0

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -