getModel and getBean series methods
getModel is used to receive the model object passed from the page form field. The form field name is named in the form of "modelName.attrName". In addition to getModel, a getBean method is also provided to support traditional Java Beans. The following is 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"); } }
If you want to avoid using the modelName prefix when passing parameters, you can use empty string Implemented as modelName:
getModel(Blog.class, “”); This is very useful for developing pure API projects.