Spring.Net 是一个很强大的框架,在java里非常的火,NHibernate也是从java里移植过来的.不过和Java下面的用法有所区别.下面我们以一个实例来说说他们在.net下的用法.
新建一个项目:名字叫SpringHiberate.
首先,我们修改我们的配置文件web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
</sectionGroup>
<section name="SpringOverrideProperty" type="System.Configuration.NameValueSectionHandler"/>
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<SpringOverrideProperty>
<add key="DbProvider.ConnectionString" value="Data Source=192.168.1.21;Database=FastSpring20;User ID=sa;Password=oilchem2007;Trusted_Connection=False"/>
<add key="SystemInit.IsDebug" value="true"/>
<add key="SystemInit.Level" value="4"/>
</SpringOverrideProperty>
<!-- Spirng.Net 配置 -->
<spring>
<context>
<resource uri="config://spring/objects"/>
<resource uri="assembly://SpringHiberate/SpringHiberate/spring_bean_dao.xml"/>
</context>
<objects xmlns="http://www.springframework.net"/>
</spring>
<appSettings/>
<connectionStrings/>
<system.web>
<compilation debug="true" />
<authentication mode="Windows" />
<httpModules>
<add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
</httpModules>
<httpHandlers>
<add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>
</httpHandlers>
</system.web>
</configuration>
然后我们添加一个Model类User.cs:
using System;
namespace SpringHiberate.dao.model
{
public class User
{
private Int32 |