Spring.Web.Mvc 注入(控制器属性注入)
1.web.config配置
<?xml version="1.0" encoding="utf-8"?>
<!--
有关如何配置 ASP.NET 应用程序的详细信息,请访问
http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.MvcContextHandler, Spring.Web.Mvc"/>
</sectionGroup>
</configSections>
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
<spring>
<context>
<resource uri="~/Config/Controllers.xml"/>
</context>
</spring>
<appSettings>
<add key="webpages:Version" value="3.0.0.0"/>
<add key="webpages:Enabled" value="false"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2"/>
<httpRuntime targetFramework="4.5.2"/>
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
</configuration>
2.根目录添加lib文件夹(spring.core spring.web.mvc Common.Logging.dll Common.Logging.Log4Net.dll)
程序集引用添加这4个东西
3.mvcapplication 注册路由重写 继承SpringMvcApplication
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Spring.Web.Mvc;
namespace WebApplication12
{
public class MvcApplication :SpringMvcApplication
{
protected override void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
//protected void Application_Start()
//{
// AreaRegistration.RegisterAllAreas();
// RouteConfig.RegisterRoutes(RouteTable.Routes);
//}
}
}
3.根目录下新建Config文件夹 里面添加Controllers.xml(右键属性 始终复制 我的迷信)
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
<object type="WebApplication12.Controllers.HomeController, WebApplication12" singleton="false" >
<property name="Message1" value="海贼王的乱入" />
</object>
<!--集合注入-->
<object type="WebApplication12.Controllers.HomeController, WebApplication12" singleton="false" >
<property name="Message" >
<list element-type="System.String">
<value>B0 Stage</value>
<value>B1 Stage</value>
<value>B2 Stage</value>
<value>B3 Stage</value>
<value>B4 Stage</value>
<value>B5 Stage</value>
<value>B6 Stage</value>
</list>
</property>
</object>
</objects>
4.控制器添加Message属性之后用于注入
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WebApplication12.Controllers
{
public class HomeController : Controller
{
public string Message { get; set; }
// GET: Home
public ActionResult Index()
{
ViewData["Message"] = Message;
return View();
}
}
}
4.视图调用
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
<h1>@ViewData["Message"]</h1>
</div>
</body>
</html>
Spring.Web.Mvc 注入(控制器属性注入)的更多相关文章
- Asp.netCore 3.1控制器属性注入and异步事务Aop by AutoFac
Aspect Oriented Programming(AOP)是较为热门的一个话题.AOP,国内我们都习惯称之为:面向切面编程 下面直接code 干货展示:(一般人我还不告诉,嘻嘻) 1:导入相关的 ...
- ASP.NETCore 3.0 Autofac替换及控制器属性注入及全局容器使用
1.Autofac基础使用 参考: https://www.cnblogs.com/li150dan/p/10071079.html 2.ASP.NETCore 3.0 Autofac 容器替换 需要 ...
- Spring REST实践之Spring Web MVC
Spring概要 Spring Framework提供了依赖注入模型和面向切面编程,简化了基础型代码的编写工作以及更好的能够与其它框架和技术整合起来.Spring Framework由data acc ...
- Spring Web MVC框架简介
Web MVC framework框架 Spring Web MVC框架简介 Spring MVC的核心是`DispatcherServlet`,该类作用非常多,分发请求处理,配置处理器映射,处理视图 ...
- Spring Web MVC(一)
[toc] 概述 Spring的web框架围绕DispatcherServlet设计. DispatcherServlet的作用是将请求分发到不同的处理器. Spring的web框架包括可配置的处理器 ...
- Spring Web MVC(三)之注解
[toc] spring web mvc 基于注解的优化 我写的注解是按照spring web的部件分类写的,这样的话比较方便查看,大家感觉有用的话可以分享个别人,希望对对更多的人有帮助.毕竟零基础开 ...
- 12.Spring——Web MVC框架
1.Spring Web MVC 框架 2.Spring MVC Hello World 例子 1.Spring Web MVC 框架 Spring web MVC 框架提供了模型-视 ...
- Spring官方文档翻译——15.1 介绍Spring Web MVC框架
Part V. The Web 文档的这一部分介绍了Spring框架对展现层的支持(尤其是基于web的展现层) Spring拥有自己的web框架--Spring Web MVC.在前两章中会有介绍. ...
- spring web mvc第一天
spring web mvc 感觉就是高大上啊!啥都是配置文件就能够了.所以第一步就是弄清楚配置文件使用和总体框架的流程! Spring web mvc最重要的当然是Controller,也就是首先 ...
随机推荐
- LeetCode Next Closest Time
原题链接在这里:https://leetcode.com/problems/next-closest-time/description/ 题目: Given a time represented in ...
- phpredis的使用
phpredis的具体使用方法可以参照:https://github.com/phpredis/phpredis
- 提示“load System.Core failed”
Could not load file or assembly 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec8 ...
- Python脚本MAC上双击执行,如何设置?
1.在文件首行添加如下代码: 如果你想使用默认python版本执行当前的脚本,即python2,则需要添加 #!/usr/bin/env python # -*- coding: utf-8 -*- ...
- Cocoa Pod使用总结
1. 背景 CocoaPod是Swift,Objective-C语言编写的Cocoa项目的依赖管理工具.简单点说就是它管理了很多的Swift和Objective-C的库,然后通过CocoaPod可以比 ...
- 遍历listmap 遍历map
package excel; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import j ...
- dirname 和 basename
dirname 和 basename 命令 [root@localhost /]# cat /tmp/a.sh dirname $0 #获取脚本所在的路径 basename $0 ...
- unittest框架+ HTMLTestRunner 出报告时,展示控制台信息 不同展示的参数写法 加verbosity
加verbosity参数 没有加的时候展示: 参考: 来源: https://www.cnblogs.com/tomweng/p/6609937.html 介绍: HTMLTestRunner 是 ...
- java练习,,,从键盘输入次数,输出最大值,和
总结:你的关注,是我的动力 package com.b; import java.util.Scanner; public class YUIO { public static void main(S ...
- 1092 To Buy or Not to Buy
题意:给出两个字符串s1和s2(长度不超过1000),问s1是否包含s2中的所有字符,若包含,则输出Yes,并输出s1中多余的字符个数:若不完全包含,则输出No,并输出缺少的个数. 思路:定义数组in ...