还是讲一些项目中你可能遇到的问题,有的时候人总是不听话,想改变原有的东西。今天我就教你怎么样颠覆MVC传统的文件夹结构,即个性化你的目录。ok,开始。先看看我设计的目录
我的controller下有这么多文件夹。再看看我的views
看到了吧,按照系统分类我进行了详细的划分。
现在带你看看controller如何找到view,controller代码
InBlock.gif namespace Controllers
InBlock.gif{
InBlock.gif         public class CodeController:Controller
InBlock.gif        {
InBlock.gif                 public ActionResult Index()
InBlock.gif                {
InBlock.gif                        SpringContext.init();
InBlock.gif                        dynamic dyn = SpringContext.Context.GetObject( "DaoHelper") as dynamic;
InBlock.gif                        IList<SS_CODE> ilist = dyn.GetList();
InBlock.gif                         return View( "~/Views/System/Code/Index.aspx",ilist);
InBlock.gif                }
InBlock.gif        }
InBlock.gif}
如果不这样写,controller根本找不到view,因为你已经把视图的路径改了。这样还不行,我们还需要对route进行设置,打开Global.asax,把路由改为
InBlock.gif public static void RegisterRoutes(RouteCollection routes)
InBlock.gif                {
InBlock.gif                        routes.IgnoreRoute( "{resource}.axd/{*pathInfo}");
InBlock.gif
InBlock.gif                        routes.MapRoute(
InBlock.gif                                 "Default", // Route name
InBlock.gif                                 "System/{controller}/{action}/{id}", // URL with parameters
InBlock.gif                                 new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
InBlock.gif                        );
InBlock.gif                }
ok大功告成,运行结果如下
最后呢再看hibernate的过程中无意发现了个Expression,不知道Nhibernate里面有没有这些内容,估计不会差很多,贴出来大家看看。
Expression.gt:对应SQL条件中的"field > value "。如:Expression.gt("salary", new Integer(5000))
Expression.ge:对应SQL条件中的"field >= value"。
Expression.lt:对应SQL条件中的"field < value"。
Expression.le:对应SQL条件中的"field <= value"。
Expression.between:对应SQL条件中的"between"。
Expression.like:对应SQL条件中的"field like value"。
Expression.in:对应SQL条件中的"field in …"。
Expression.eqProperty:用于比较两个属性之间的值,对应SQL条件中的"field = field"。如:Expression.eqProperty("Employee.id", "Group.eid");
Expression.gtProperty:用于比较两个属性之间的值,对应SQL条件中的"field > field"。
Expression.geProperty:用于比较两个属性之间的值,对应SQL条件中的"field >= field"。
Expression.ltProperty:用于比较两个属性之间的值,对应SQL条件中的"field < field"。
Expression.leProperty:用于比较两个属性之间的值,对应SQL条件中的"field <= field"。
Expression.and:and关系组合。