我在UserModule类中添加了如下代码:
package net.wendal.nutzbook.module;
import javax.servlet.http.HttpSession;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Fail;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;
import net.wendal.nutzbook.bean.User;
@IocBean
@At("/user")
@Ok("json")
@Fail("http:500")
public class UserModule {
@Inject
protected Dao dao;
@At
public int count() {
return dao.count(User.class);
}
@At
public Object login(@Param("username") String name, @Param("password") String password, HttpSession session) {
User user = dao.fetch(User.class, Cnd.where("name", "=", name).and("password", "=", password));
if (user == null) {
return false;
} else {
session.setAttribute("me", user.getId());
return true;
}
}
@At
@Ok(">>:/")
public void logout(HttpSession session) {
session.invalidate();
}
}
启动tomcat时,
[DEBUG] 19:30:27.638 org.nutz.mvc.impl.UrlMappingImpl.print(UrlMappingImpl.java:146) - '/user/count' >> (UserModule.java:27).count : int | @Ok(json ) @Fail(http:500) | by 0 Filters | (I:UTF-8/O:UTF-8)
[DEBUG] 19:30:27.643 org.nutz.mvc.impl.UrlMappingImpl.print(UrlMappingImpl.java:146) - '/user/login' >> (UserModule.java:31).login : Object | @Ok(json ) @Fail(http:500) | by 0 Filters | (I:UTF-8/O:UTF-8)
[INFO ] 19:30:27.643 org.nutz.mvc.impl.NutLoading.evalUrlMapping(NutLoading.java:220) - Found 2 module methods