• 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
  • 相关阅读:
    系统操作日志设计代码实现
    SQL SERVER 存储过程复习
    IGrab信息采集系统流程图(初稿)
    收藏几段SQL语句和存储过程
    SQL Server联机丛书:存储过程及其创建
    使用dynamic来简化反射实现,并且提高了性能
    你必须知道的C#的25个基础概念(附演示)
    弹窗插件
    dede 搜索时出现“SphinxClient类找不到”解决
    开启includes模块运行shtml
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/2521312.html
Copyright © 2020-2023  润新知