NHibernate + Spring.Net 增删改查例子
下载NHibernate + Spring.Net 增删改查例子
开发环境:VS2005(SP1)+SQL2005,如果是用VS2005运行此例子,需确保已经打了 VS2005 SP1的补丁 ,如是VS2008及以上版本则不用。
说明:
1.此例子的源码一部分来自 http://www.cnblogs.com/eicesoft/archive/2008/02/19/1073756.html ,增加了修改、删除和查询的功能,增加了sql文件,删除了web.config中的connectionString。
2.运行此例子前,需要先修改spring_bean_dao.xml中的ConnectionString为你自己sql server的设置,然后运行sql文件夹下的table.sql文件创建表。
3.此例子只是简单的增删改查,没有实现复杂的如搜索等功能。
欢迎留言共通探讨。^_^
这篇文章纯粹是一个HelloWorld,希望能帮到大家。至于配置里需要注意的地方可参考其他文章,这里仅列出可用的项目代码及下载。
开发环境:VS2005(打了SP1的补丁)
步骤一:新建一个控制台项目
步骤二:引用Spring.Core.dll
步骤三:新建App.config代码如下:
<? xml version="1.0" encoding="utf-8" ?> < configuration > < configSections > < sectionGroup name ="spring" > < section name ="context" type ="Spring.Context.Support.ContextHandler, Spring.Core" /> </ sectionGroup > </ configSections > < spring > < context > < resource uri ="file://spring.xml.config" /> </ context > </ spring > </ configuration >
步骤四:新建spring.xml.config(这个名字可自定,如需改名,则在App.config的rescource里也需一并修改),代码如下:
<? xml version="1.0" encoding="utf-8" ?> < objects xmlns ="http://www.springframework.net" > < object id ="hello" type ="SpringNetDemo.Hello" > < property name ="HelloWord" value ="Hello!你能看到这个证明你成功了!" /> </ object > </ objects >
步骤五:修改项目原来的Program.cs文件:
using System; using System.Collections.Generic; using System.Text; using Spring.Context; using Spring.Context.Support; namespace SpringNetDemo { public class Hello { private string helloword; public string HelloWord { get { return this .helloword; } set { this .helloword = value; } } } public class Program { static void Main( string [] args) { IApplicationContext context = ContextRegistry.GetContext(); Hello hello = (Hello)context.GetObject( " hello " ); Console.Write(hello.HelloWord); Console.Read(); } } }
说明:这里的hello.HelloWord就是Spring.Net通过xml的配置实现注入的。有问题的可以留言。
点击这里下载所有代码
决定要做一个电子商务网站,一直以来都觉得自己美工很烂,那先从美工入手吧!
折腾了2天之后,有了最初的效果,在线demo请点击: http://byyee.com/software/shoppingmall/
网站用的是国外空间,如果访问不了,下面有截图。大家给提点建议。谢谢。
接下来我打算用PetShop的架构+NHibernate来架构这个网站,敬请期待......
分类: Spring.Net
分类: asp.net , Spring.Net , NHibernate
作者: Leo_wl
出处: http://www.cnblogs.com/Leo_wl/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
版权信息查看更多关于NHibernate + Spring.Net 增删改查例子的详细内容...