日期:2014-05-20 浏览次数:20857 次
public class Admin extends Application { @Before static void checkAuthentification() { if(session.get("user") == null) login(); } public static void index() { List<User> users = User.findAll(); render(users); } ... }
public class Admin extends Application { @Before(unless="login") static void checkAuthentification() { if(session.get("user") == null) login(); } public static void index() { List<User> users = User.findAll(); render(users); } ... }
public class Admin extends Application { @Before(only={"login","logout"}) static void doSomething() { ... } ... }
public class Secure extends Controller { @Before static void checkAuthenticated() { if(!session.containsKey("user")) { unAuthorized(); } } }
@With(Secure.class) public class Admin extends Application { ... }
public class Admin extends Application { @After static void log() { Logger.info("Action executed ..."); } public static void index() { List<User> users = User.findAll(); render(users); } ... }
public class Admin extends Application { @Catch(IllegalStateException.class) public static void logIllegalState(Throwable throwable) { Logger.error("Illegal state %s…", throwable); } public static void index() { List<User> users = User.findAll(); if (users.size() == 0) { throw new IllegalStateException("Invalid database - 0 users"); } render(users); } }
public class Admin extends Application { @Finally static void log() { Logger.info("Response contains : " + response.out); } public static void index() { List<User> users = User.findAll(); render(users); } ... }