两个模型命名为“帖子”和“评论”,我想建立像/post/123/comment/8和CommentsController处理所有RESTful操作的RESTful路由。
我试过了
route("/posts/{post_id}/comments/*").to(CommentsController.class);和
route("/posts/{post_id}/comments/*").to(CommentsController.class).get().post().put().delete(); 并且没有一个有效:(
发布于 2019-02-20 10:59:31
您需要的不是AvctiveWeb框架中的一组RESTful路由:http://javalite.io/routing#restful-routing。
您要做的是定义一些自定义路由。但并不是说它们不是基于REST的。
下面是一个有效的示例:
路由:
public class RouteConfig extends AbstractRouteConfig{
public void init(AppContext appContext) {
route("/posts/{post_id}/comments/{comment_id}").to(CommentsController.class).action("index").get();
}
}控制器:
public class CommentsController extends AppController {
public void index(){
respond("index, post:" + param("post_id") + ", comment: " + param("comment_id"));
}
}然后点击这个:
http://localhost:8080/posts/123/comments/456
并观察:
index, post:123, comment: 456
https://stackoverflow.com/questions/54764345
复制相似问题