JFinal 是基于Java 语言的极速 WEB + ORM 开发框架,其核心设计目标是开发迅速、代码量少、学习简单、功能强大、轻量级、易扩展、Restful。在拥有Java语言所有优势的同时再拥有ruby、python等动态语言的开发效率!为您节约更多时间,去陪恋人、家人和朋友 ;)
以下是JFinal实现Blog管理的代码:
/**
* BlogController
*/
public class BlogController extends Controller {
public void index() {
setAttr("blogList", Blog.dao.find("select * from blog order by id asc"));
}
public void add() {
}
@Before(BlogValidator.class)
public void save() {
getModel(Blog.class).save();
}
public void edit() {
setAttr("blog", Blog.dao.findById(getParaToInt()));
}
@Before(BlogValidator.class)
public void update() {
getModel(Blog.class).update();
}
public void delete() {
Blog.dao.deleteById(getParaToInt());
}
}
/**
* Blog model.
*/
public class Blog extends Model<Blog> {
public static final Blog dao = new Blog();
}
/**
* BlogValidator.
*/
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);
}
}