May 14, 2021 JFinal manual
GetModel is used to receive model objects passed through the page form field, the form domain name is named "modelName.attrName". I n addition to getModel, a getBean method is available to support traditional Java Beans. Here's a simple example:
// 定义Model,在此为Blog
public class Blog extends Model<Blog> {
public static final Blog me = new Blog();
}
// 在页面表单中采用modelName.attrName形式为作为表单域的name
<form action="/blog/save" method="post">
<input name="blog.title" type="text">
<input name="blog.content" type="text">
<input value="提交" type="submit">
</form>
public class BlogController extends Controller {
public void save() {
// 页面的modelName正好是Blog类名的首字母小写
Blog blog = getModel(Blog.class);
// 如果表单域的名称为 "otherName.title"可加上一个参数来获取 blog = getModel(Blog.class, "otherName");
}
}
In the above code, the form field uses "blog.title", "blog.content" as the name property of the form field, "blog" is the first letter of the class file name "Blog" is lowercase, "title" is the title field of the blog database table, if you want the form field to use the intended modelName, only need to add a number of parameters to getModel to determine, for example: getModel ( Blog.class, ”otherName”)。
If you want to avoid using the modelName prefix when passing ginseng, you can use an empty string as modelName to do this:
getModel(Blog.class, “”); This is useful for developing a pure API project.