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>
转载于:https://www.cnblogs.com/kexb/p/4823236.html
Spring.Web.Mvc 注入(控制器属性注入)相关推荐
- Spring Web MVC是什么
2.1.Spring Web MVC是什么 Spring Web MVC是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将web层进行职 ...
- Spring Web MVC详解
Spring Web MVC详解 原创 2016年03月23日 10:55:57 标签: 421 编辑 删除 2.1.Spring Web MVC是什么 Spring Web MVC是一种基于Java ...
- Spring Web MVC(一)
概述 Spring Web MVC框架的特点 五大核心组件 编程步骤 五大核心组件 DispatcherServlet前端控制器 WebApplicationContext中特殊的bean 处理过程 ...
- 【Spring Web MVC】Spring Web MVC 注解开发环境搭建
为什么80%的码农都做不了架构师?>>> 1.创建maven项目 创建一个名为:springwebmvc-first的maven项目 2.添加依赖包 要使用springWebM ...
- 初试 spring web mvc
作为一名code需要了解更多的知识,编程方面的东西太多了,是个逐渐积累的过程.最近学习一下spring web mvc,写下我个人的一些经验. 1.准备jar包.spring mvc 已经到了版本4, ...
- Spring Boot——2分钟构建spring web mvc REST风格HelloWorld
Spring Boot--2分钟构建spring web mvc REST风格HelloWorld 之前有一篇<5分钟构建spring web mvc REST风格HelloWorld>介 ...
- Spring Web MVC (Spring MVC) 的相关例题及解析
MVC.web MVC.Spring MVC 和 Spring Web MVC的联系与区别: 1.MVC 是一种架构分层模式 2.web MVC 是指在 web 领域下实践的 MVC,因为 web 领 ...
- core控制器属性注入的用处_了解ASP.NET Core 依赖注入,看这篇就够了
DI在.NET Core里面被提到了一个非常重要的位置, 这篇文章主要再给大家普及一下关于依赖注入的概念,身边有工作六七年的同事还个东西搞不清楚.另外再介绍一下.NET Core的DI实现以及对实例 ...
- core控制器属性注入的用处_理解 ASP.NET Core 依赖注入
DI在.NET Core里面被提到了一个非常重要的位置,介绍一下.NET Core的DI实现以及对实例生命周期的管理,在控制台以及Mvc下如何使用DI,以及如何把默认的Service Contain ...
最新文章
- linux traceroute 命令 查看路由表
- Java--获取request中所有参数的方法
- python tuple list_草根学Python(三)List 和 Tuple
- vue 打包上线后字体图标不显示
- 【图像处理】——实现二值图像的轮廓边界跟踪以及轮廓面积周长的求解(connectedComponentsWithStats()函数和connectedComponents()函数)
- 网络安全-使用HTTP动词篡改的认证旁路
- php preview,preview.php
- 垃圾收集(GC)中如何确定哪些内存是垃圾
- FastReport.Net使用:[1]屏蔽打印对话框
- java材质_教程 - JAVA版材质包制作教程 | MineBBS 我的世界中文论坛
- 详细介绍如何使用MATLAB中的机器人工具箱建立机器人模型(DH法建模)(机械臂)
- Kent Beck揭秘Facebook开发部署流程
- python允许无止境的循环_A-level Computer Science 计算机科学学习笔记/经验分享/教程 (12.6):PHP...
- Unity3D自动旋转屏幕
- cmd返回上一级和根目录
- 针对学校出现猪流感而做的一个简单的小软件(更新版)
- MPP大规模并行计算数据库与分布式数据库的区别
- win10系统如何开启telnet
- 计算机学院档案馆教育部,我系本科生团队参加全国高校档案学专业大学生创新性课外科技作品展...
- IDEA 的Surround With (例如try/catch)快捷键
热门文章
- Android(六)——Android第一周学习
- MySQL(三)——函数、事务(ACID)、索引、权限管理和备份、数据库三大范式
- java自定义异常返回_Java自定义异常
- 获取map第一个的key和value_谁要是再敢用Map传参,我过去就是一JIO
- 意外的服务器响应_响应式系统reactive system初探
- Python-OpenCV--USB摄像头采集图像并保存到指定文件夹
- mac 设置默认python为python3
- Windows下C/C++获取当前系统时间
- 吴恩达深度学习笔记8-Course3-Week1【机器学习策略(ML Strategy)1】
- 汇编解析(3)-nasm基础、物理地址