同步操作将从 JFinal/JFinal 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
JFinal is an ultra-fast WEB + ORM framework based on the Java language. Its core design goals are rapid development, minimal code, simple learning, powerful functionality, lightweight, easy to expand, and Restful. While possessing all the advantages of the Java language, it also has the development efficiency of dynamic languages like ruby and python! Save more time for you to spend with your loved ones, family, and friends ;)
Join JFinal's ultra-fast WeChat official account development: JFinal
<dependency>
<groupId>com.jfinal</groupId>
<artifactId>jfinal</artifactId>
<version>5.1.1</version>
</dependency>
1. Controller (Supports Enjoy, JSP, JSON, etc., as well as custom view rendering)
@Before(BlogInterceptor.class)
public class BlogController extends Controller {
@Inject
BlogService service;
public void index() {
set("blogPage", service.paginate(getInt(0, 1), 10));
render("blog.html");
}
public void add() {
}
@Before(BlogValidator.class)
public void save() {
getModel(Blog.class).save();
redirect("/blog");
}
public void edit() {
set("blog", service.findById(getInt()));
}
@Before(BlogValidator.class)
public void update() {
getModel(Blog.class).update();
redirect("/blog");
}
public void delete() {
service.deleteById(getInt());
redirect("/blog");
}
}
2. All business and SQL are placed in the Service layer
public class BlogService {
private 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 (No XML, no annotations, no attributes)
public class Blog extends Model<Blog> {
}
4. Validator (API-guided validation, much more convenient than XML validation, code-checked to minimize errors)
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. Interceptor (Only for demonstration in this demo, this demo does not require this interceptor)
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());
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。