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,也就是首先 ...
随机推荐
- LG5055 【模板】可持久化文艺平衡树
题意 您需要写一种数据结构,来维护一个序列,其中需要提供以下操作(对于各个以往的历史版本): 在第 pp 个数后插入数 xx . 删除第 pp 个数. 翻转区间 [l,r][l,r],例如原序列是 { ...
- test20181219 奇怪的函数
题意 奇怪的函数 [问题描述] 使得x^x达到或超过n位数字的最小正整数x是多少? [文件输入] 输入一个正整数n(n<=2*10^9). [文件输出] 输出使得x^x达到n位数字的最小正整数x ...
- 内联元素inline-block空隙问题
1.产生的原因 当我们使用"display:inline-block"把块集元素转换为内联元素时,每两个内联元素之间有一定的空隙,既不是margin也不是padding,最终发现是 ...
- spring mvc加了@produces注解后报406
问题背景:调用http的post接口返回一个String类型的字符串时中文出现乱码,定位出问题后在@RequestMapping里加produces注解produces = "applica ...
- jenkin执行权限问题
jenkins执行报错 stderr: Permission denied, please try again. Permission denied, please try again. Permis ...
- python 数据库查询结果转对象
#coding:utf-8 from json import dumps, loads, JSONEncoder, JSONDecoder import pickle from app.model.J ...
- FTP mget without prompt
# ftp 192.168.100.2Connected to 192.168.100.2.220 Microsoft FTP ServiceName (192.168.100.2:root): ja ...
- 分布式开发框架Pebble使用说明
简介 Pebble定位为一个好用.可靠.高性能.易扩展的分布式开发框架,支持多种使用方式: 使用完整的pebble框架 独立使用各pebble子模块 在其他框架中嵌入pebble框架. Pebble具 ...
- java代码求输入的三个数的最大值
package com.c2; import java.util.Random; import java.util.Scanner; //输入10个数,找出最大一个数,并打印出来. public cl ...
- 在工作表左侧中添加TreeView控件
开发环境基于VSTO:visual studio 2010,VB .Net,excel 2007,文档级别的定制程序. 需求是在sheet的左侧停靠System.Windows.Forms.TreeV ...