【发布时间】:2011-08-13 20:49:19
【问题描述】:
我正在寻找 Spring MVC's url mapping using annotations 的 C# 等价物,即我可以用 Java 编写:
@Controller
@RequestMapping("/some-friendly-url/")
class MyController
{
@RequestMapping(value = "/{type}/more-seo-stuff/{color}", method = RequestMethod.GET)
public List<SomeDTO> get(@PathVariable String type,
@PathVariable String color,
int perPage) {
...
}
@RequestMapping(method = RequestMethod.POST)
public String post(@RequestBody SomeDTO somethingNew) {
...
}
}
它实际上比这个简单的例子更强大,任何熟悉这个概念的人都知道。
我试图搜索如何使用 ASP.MVC 3 或 MonoRail 实现相同的目标,这两个框架似乎都基于 RoR 的约定优于配置“//”理念,而且很难实现上面有它们,并且需要控制器类之外的大量定制路由条目,只有一小部分功能可通过属性获得。 Spring.NET 似乎也没有解决这个问题,因为 ASP.MVC 的路由功能已经足够了。
在 C# 世界中是否有任何东西可以提供这种类型的功能?我正要开始考虑写一些自己的东西来解决这个问题,但我希望不必这样做。
编辑: 终于在 NuGet 上找到了“AttributeRouting”项目:https://github.com/mccalltd/AttributeRouting/wiki/1.-Getting-Started。完美运行。不支持 Spring MVC 提供的全部功能,但支持其中的大部分。
Akos Lukacs 还指出了 ITCloud 下面的另一个不错的库。然而,不幸的是,NuGet 上没有。
【问题讨论】:
-
猜猜找到了:stackoverflow.com/questions/894779/… :-)
-
我在 NuGet 上找不到 ITCloud 库,但后来我有了在 NuGet 和 walla 上搜索的想法:github.com/mccalltd/AttributeRouting/wiki/1.-Getting-Started
标签: c# .net asp.net-mvc spring-mvc castle-monorail