-
Notifications
You must be signed in to change notification settings - Fork 29
Controller
Brian Zou edited this page Nov 17, 2018
·
8 revisions
Add controllers files to this path:
source/app/controller/
module app.controller.UserController;
/*
import hunt framework package
*/
import hunt.framework;
class HelloController : Controller
{
// must be here
mixin MakeController;
@Action
string world()
{
return "Hello world!";
}
}
Controller have two property request and response,look: Request and Response。
- return
string
@Action string showString()
{
return "Hello world.";
}
- return int、float
@Action int showInt()
{
return 2018;
}
- don't return
@Action void showString()
{
// do nothing;
}
- return
bool
@Action bool showBool()
{
return true;
}
- return
Response
@Action Response showResponse()
{
return new Response("Hello world.");
}
- rerturn
JsonResponse
@Action JsonResponse testJson2()
{
JSONValue company;
company["name"] = "Putao";
JsonResponse res = new JsonResponse(company);
return res;
}
- return custom Response object
RedirectResponse
@Action RedirectResponse testRedirect()
{
RedirectResponse r = new RedirectResponse("https://www.putao.com/");
return r;
}