map.resource

嵌套资源

 

很多时候资源还会包含一组别的资源。譬如说,我们可能允许别人给文章做评论,这时每个评论也

会是一项资源,评论的集合则关联到“文章”资源。

对于这种情况,Rails 提供了一种便捷而直观的方式来声明路由:

Download restful2/config/routes.rb

ActionController::Routing::Routes.draw do |map|

→ map.resources :articles do |article|

→ article.resources :comments

end

# ...

map.connect ':controller/:action/:id'

map.connect ':controller/:action/:id.:format'

end

  

更为简洁和常见写法如下:

map.resources :articles, :has_many => :comments

 

 

 

 

map.resources :articles, :shallow => true do |article|

article.resources :comments

end

这样就可以识别出下列路由:

/articles/1 => article_path(1)

/articles/1/comments => article_comments_path(1)

/comments/2 => comment_path(2)

转载于:https://www.cnblogs.com/evolution/archive/2012/12/03/2799569.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
package com.example.demo1.service; import com.example.demo1.mapper.*; import com.example.demo1.model.ResponseData; import com.example.demo1.model.ViewEvents; import com.example.demo1.util.ResponseDataUtil; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.util.ReflectionUtils; import java.lang.reflect.Method; import java.util.HashMap; import java.util.List; @Service public class service { @Resource com.example.demo1.mapper.SolutionAttrMapper SolutionAttrMapper; @Resource com.example.demo1.mapper.ViewAttrMapper ViewAttrMapper; @Resource com.example.demo1.mapper.TableFieldsMapper TableFieldsMapper; @Resource SolutionViewsMapper SolutionViewsMapper; @Resource com.example.demo1.mapper.ViewEventsMapper ViewEventsMapper; @Resource com.example.demo1.method.common Common; public ResponseData solutionCloud(String solution, String view, String event) { switch (event) { case "tech": // 取数 HashMap<String, Object> map = new HashMap<>(1); map.put("SolutionAttr", SolutionAttrMapper.selectByPrimaryKey(solution)); map.put("SolutionViews", SolutionViewsMapper.selectBySolution(solution)); map.put("ViewAttr", ViewAttrMapper.selectByPrimaryKey(view)); map.put("TableFields", TableFieldsMapper.selectByView(view)); // 事件 List<ViewEvents> ViewEvents = ViewEventsMapper.selectbyView(view); for (ViewEvents ViewEvent : ViewEvents) { ResponseData responseData = Common.fields_sort(ViewEvent.getImport1()); if (ViewEvent.getEvent().substring(1) == "_") { //内置事件 String methodName = ViewEvent.getMethod(); String import1 = ViewEvent.getImport1(); Method method1 = ReflectionUtils.findMethod(Common.getClass(), methodName); Object result1 = ReflectionUtils.invokeMethod(method1, Common,import1); } } return ResponseDataUtil.buildSuccess(map); case "data": // return new ResponseEntity(SolutionAttrMapper.selectByPrimaryKey(solution), HttpStatus.OK); } return null; } }
最新发布
06-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值