你好,波总,最近有一个项目在向jfinal上迁移,但之前的项目是类似spring mvc这种路由结构,url路由可以是class和method级别的,但现在jfinal的path只能设置到class级别,如果要使用method级别只能使用actionKey来强制指定路由,这也像是一种解决办法。
但有一个问题是,不太美观,而且class级别的路由不能共用,比如说像这样
@Path("album/category")
public class AlbumCategoryController extends BaseController {
@Inject
private AlbumCategoryService albumCategorySrv;
public void index() {
render("index");
}
@Before(WebContextInterceptor.class)
public void list() {
setAttr(MyConstants.PAGE, albumCategorySrv.pageParent());
render("list");
}
@ActionKey("/album/category/parent/add")
public void addParent() {
Boolean flag = albumCategorySrv.saveParent(getModel(AlbumCategory.class));
renderJson(flag, "添加");
}
@ActionKey("/album/category/parent/edit/dialog")
public void editParentDialog() {
setAttr("CAT", albumCategorySrv.get(getInt("id")));
render("dialog/parent/edit");
}
@ActionKey("/album/category/edit")
public void editParent() {
AlbumCategory category = albumCategorySrv.get(getInt("id"));
if (Objects.isNull(category)) {
jsonFail("非法参数");
return;
}
Boolean flag = albumCategorySrv.update(getModel(AlbumCategory.class));
renderJson(flag, "编辑");
}这们会有很多重复的字符串,没有办法实现继承class级别的路由, 我现在想实现的是在method上只用写"child/add/dialog"这样就可以再加个class上的viewPath,自动组装成
"/album/category/child/add/dialog"
看了下源码,这些都是在actionHandler里面完成的,自定义一个actioinHandler是否可以解决这个问题呢?或者是有没有计划在新版本里面添加这个功能
ps. 好像找到解决方案了,自定义一个扩展
private Function<Routes, ActionMapping> actionMappingFunc = null;