Fetch the repository succeeded.
This action will force synchronization from JFinal/JFinal, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
JFinal 是基于 Java 语言的极速 WEB + ORM 框架,其核心设计目标是开发迅速、代码量少、学习简单、功能强大、轻量级、易扩展、Restful。在拥有Java语言所有优势的同时再拥有ruby、python等动态语言的开发效率!为您节约更多时间,去陪恋人、家人和朋友 ;)
JFinal 极速开发微信公众号欢迎你的加入: JFinal
1. 控制器(支持JFinal Template、JSP、Velocity、JSON等等以及自定义视图渲染)
@Before(BlogInterceptor.class)
public class BlogController extends Controller {
static BlogService service = new BlogService();
public void index() {
setAttr("blogPage", service.paginate(getParaToInt(0, 1), 10));
render("blog.html");
}
public void add() {
}
@Before(BlogValidator.class)
public void save() {
getModel(Blog.class).save();
redirect("/blog");
}
public void edit() {
setAttr("blog", service.findById(getParaToInt()));
}
@Before(BlogValidator.class)
public void update() {
getModel(Blog.class).update();
redirect("/blog");
}
public void delete() {
service.deleteById(getParaToInt());
redirect("/blog");
}
}
2.Service所有业务与sql全部放在Service层
public class BlogService {
private static final Blog dao = new Blog().dao();
public Page<Blog> paginate(int pageNumber, int pageSize) {
return dao.paginate(pageNumber, pageSize, "select *", "from blog order by id asc");
}
public Blog findById(int id) {
return dao.findById(id);
}
public void deleteById(int id) {
dao.deleteById(id);
}
}
3.Model(无xml、无annotaion、无attribute)
public class Blog extends Model<Blog> {
}
4.Validator(API引导式校验,比xml校验方便N倍,有代码检查不易出错)
public class BlogValidator extends Validator {
protected void validate(Controller controller) {
validateRequiredString("blog.title", "titleMsg", "请输入Blog标题!");
validateRequiredString("blog.content", "contentMsg", "请输入Blog内容!");
}
protected void handleError(Controller controller) {
controller.keepModel(Blog.class);
}
}
5.拦截器(在此demo中仅为示例,本demo不需要此拦截器)
public class BlogInterceptor implements Interceptor {
public void intercept(Invocation inv) {
System.out.println("Before invoking " + inv.getActionKey());
inv.invoke();
System.out.println("After invoking " + inv.getActionKey());
}
}
Sign in for post a comment
Comments ( 0 )