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 ...
最新文章
- 【c++】13.必须用指针取值的情况.md
- 第四期直播分享预告-高薪offer指南
- android studio创建文件,如何在Android Studio中创建File Templates
- Cmake 中相关具体介绍(包括Cmakelist.txt文件的编写等等)
- windows无法移动修复此计算机,无法安装Windows 10移动创作者更新[修复] | MOS86
- 如何安装mysql 5.6_如何安装MySQL 5.6?
- mysql 解决慢sql_MySQL被慢sql hang住了,用shell脚本快速清除不断增长的慢sql的办法...
- excel下拉列表多选框_移动Excel列表框项目
- uni-app开始时间结束时间(结束时间大于开始时间)picker编写
- Prometheus的函数和计算公式
- [唐诗]杳杳寒山道-寒山
- 基于GAN的语音转换技术及语音合成TTS
- 基于nginx-http-flv-module提供摄像头hls flv回放流服务
- swift学习笔记_iOS开发(一)
- 网卡地址能查计算机位置吗,如何通过网卡地址查找到丢失的电脑
- Type-C接口手机你还只知道可正反随意插?这些神操作赶紧来看看
- 工智能是实现教育生态重构的有效手段,将改变教育的时空场景和供给水平
- android培训总结范文,android开发培训心得总结
- 英语口语247之每日十句口语
- 离开学校怎样自学修炼成为一名网页设计师(四)
热门文章
- 为什么我的论文没人引用?
- 2021-11-12Date类
- 机器人学习--Turtelbot3学习--如何使用cartographer建图
- tcc读写文本txt文件
- linux多线程求和_谈一谈C++中的多线程(上)
- mysql怎么实现事务序列化_一文快速搞懂MySQL InnoDB事务ACID实现原理(转)
- python程序编译之后、找不到生成的pyc文件_为什么主要的可运行的Python脚本没有被编译为pyc文件,如模块?...
- vs中imshow函数报错_opencv编程:8 imshow不显示图像和waitkey函数
- erlang虚拟机精要(1)-运行时系统简介
- 黄海广老师《机器学习》慕课第二轮1月14日开课了!