前段时间,学习Monorail和IBatis.Net,写了个小网站,呵呵,查看
demo
有一个很强烈的感觉就是使用monorail更像是自己是在写网站,也许能体会到一些php开发者的乐趣。。这是以前用WebForm感受不到的,WebForm开发更像Winform。
Monorail和IBatis.Net架构,前期的一些配置还是比较繁琐的,基本的目录结构是这样的
![](/images/cnblogs_com/teebye/dir.JPG)
大家都知道,Monorail是MVC,他的官方Sample中大致上是Content、Controller、Components、Views、Model这样的目录结构;Content目录中放我们的Js image和css文件。。Controller目录里只我们的控制器,View是我们的定义好的模板文件,Components里是一些自定义组件文件。
为了使用Ibatisnet,我只好把model拿到外面,变成了和Web同级的目录,这就是上图看到的Entity。。
上图中的的Business、Dao、Entity都是可以利用工具自动生成的。
下载这个工具。
下面说说配置文件,还是先看目录结构
Maps目录里Ibatisnet使用的sql语句的config文件,config目录里面放的都是配置文件,全部有
components.config里面是注册我们自定义的component,内容如下。每个comonent id对应的cs代码文件都在在Components目录下面。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<components>
<component id="DisplayTopWebsiteComponent" type="GTTOLCOM.Web.Components.DisplayTopWebsiteComponent, GTTOLCOM.Web"></component>
<component id="HeaderComponent" type="GTTOLCOM.Web.Components.HeaderComponent, GTTOLCOM.Web"></component>
<component id="DisplayNoticeComponent" type="GTTOLCOM.Web.Components.DisplayNoticeComponent, GTTOLCOM.Web"></component>
<component id="FooterComponent" type="GTTOLCOM.Web.Components.FooterComponent, GTTOLCOM.Web"></component>
<component id="DisplayCategoryComponent" type="GTTOLCOM.Web.Components.DisplayCategoryComponent, GTTOLCOM.Web"></component>
<component id="DisplaySiteInfoComponent" type="GTTOLCOM.Web.Components.DisplaySiteInfoComponent, GTTOLCOM.Web"></component>
<component id="DisplayPathLinksComponent" type="GTTOLCOM.Web.Components.DisplayPathLinksComponent, GTTOLCOM.Web"></component>
<component id="DisplayNavListComponent" type="GTTOLCOM.Web.Components.DisplayNavListComponent, GTTOLCOM.Web"></component>
<component id="DisplaySubmitAttentionComponent" type="GTTOLCOM.Web.Components.DisplaySubmitAttentionComponent, GTTOLCOM.Web"></component>
<component id="DisplayAddSiteInfoComponent" type="GTTOLCOM.Web.Components.DisplayAddSiteInfoComponent, GTTOLCOM.Web"></component>
<component id="DisplayUserPathLinksComponent" type="GTTOLCOM.Web.Components.DisplayUserPathLinksComponent, GTTOLCOM.Web"></component>
<component id="DisplayRssComponent" type="GTTOLCOM.Web.Components.DisplayRssComponent, GTTOLCOM.Web"></component>
<component id="DisplayTagListComponent" type="GTTOLCOM.Web.Components.DisplayTagListComponent, GTTOLCOM.Web"></component>
<component id="DisplayAllCommentsComponent" type="GTTOLCOM.Web.Components.DisplayAllCommentsComponent, GTTOLCOM.Web"></component>
<component id="DisplaySpecialSiteComponent" type="GTTOLCOM.Web.Components.DisplaySpecialSiteComponent, GTTOLCOM.Web"></component>
<component id="DisplayAddUrlsToolComponent" type="GTTOLCOM.Web.Components.DisplayAddUrlsToolComponent, GTTOLCOM.Web"></component>
</components>
![](/Images/OutliningIndicators/None.gif)
</configuration>
Controlloer.config文件内容
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
![](/Images/OutliningIndicators/None.gif)
<components>
<component id="home.controller"
type="GTTOLCOM.Web.Controllers.HomeController, GTTOLCOM.Web" />
<component id="layout.controller"
type="GTTOLCOM.Web.Controllers.LayoutController, GTTOLCOM.Web" />
<component id="sitemanager.controller"
type="GTTOLCOM.Web.Controllers.SiteManagerController, GTTOLCOM.Web" />
<component id="Browse.controller"
type="GTTOLCOM.Web.Controllers.BrowseController, GTTOLCOM.Web" />
<component id="Account.controller"
type="GTTOLCOM.Web.Controllers.AccountController, GTTOLCOM.Web" />
<component id="FriendLinks.controller"
type="GTTOLCOM.Web.Controllers.FriendLinksController, GTTOLCOM.Web" />
<component id="Comments.controller"
type="GTTOLCOM.Web.Controllers.CommentsController, GTTOLCOM.Web" />
</components>
![](/Images/OutliningIndicators/None.gif)
</configuration>
![](/Images/OutliningIndicators/None.gif)
facilities.config的内容
<?xml version="1.0" encoding="utf-8"?>
<configuration>
![](/Images/OutliningIndicators/None.gif)
<facilities>
<facility id="rails" type="Castle.MonoRail.WindsorExtension.MonoRailFacility, Castle.MonoRail.WindsorExtension" />
![](/Images/OutliningIndicators/None.gif)
<facility
id="atm"
type="Castle.Facilities.AutomaticTransactionManagement.TransactionFacility, Castle.Facilities.AutomaticTransactionManagement" />
![](/Images/OutliningIndicators/None.gif)
<facility
id="ibatis"
type="Castle.Facilities.IBatisNetIntegration.IBatisNetFacility, Castle.Facilities.IBatisNetIntegration">
<sqlMap id="sqlServerSqlMap" config="config/sqlMap.config" />
</facility>
<facility id="loggingfacility" configfile="config/log4net.config" loggingapi="log4net" type="Castle.Facilities.Logging.LoggingFacility, Castle.Facilities.Logging">
</facility>
![](/Images/OutliningIndicators/None.gif)
</facilities>
![](/Images/OutliningIndicators/None.gif)
</configuration>
log4Net.config内容
![](/Images/OutliningIndicators/ContractedBlock.gif)
Code
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<log4net>
<!-- Define some output appenders -->
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="log.txt" />
<param name="AppendToFile" value="true" />
<param name="MaxSizeRollBackups" value="2" />
<param name="MaximumFileSize" value="100KB" />
<param name="RollingStyle" value="Size" />
<param name="StaticLogFileName" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="Header" value="[Header]\r\n" />
<param name="Footer" value="[Footer]\r\n" />
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] <%X{auth}> - %m%n" />
![](/Images/OutliningIndicators/None.gif)
</layout>
![](/Images/OutliningIndicators/None.gif)
</appender>
<!-- OFF, FATAL, ERROR, WARN, INFO, DEBUG, ALL -->
<!-- Set root logger level to ERROR and its appenders -->
<root>
<level value="DEBUG" />
<appender-ref ref="RollingLogFileAppender" />
<appender-ref ref="ConsoleAppender" />
</root>
![](/Images/OutliningIndicators/None.gif)
<!-- Print only messages of level DEBUG or above in the packages -->
<logger name="IBatisNet.DataMapper.Configuration.Cache.CacheModel">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataMapper.Configuration.Statements.PreparedStatementFactory">
<level value="OFF" />
</logger>
<logger name="IBatisNet.DataMapper.Commands.IPreparedCommand">
<level value="OFF" />
</logger>
<logger name="IBatisNet.DataMapper.LazyLoadInterceptor">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataMapper.LazyLoadProxyFactory">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataAccess.DaoSession">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataMapper.SqlMapSession">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.Common.Transaction.TransactionScope">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataAccess.Configuration.DaoProxy">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataMapper.Commands.DefaultPreparedCommand">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.Common.Utilities.ConfigWatcherHandler">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataMapper.Configuration.Cache.CacheModel">
<level value="DEBUG" />
</logger>
</log4net>
</configuration>
providers.configd内容
![](/Images/OutliningIndicators/ContractedBlock.gif)
providers.config
<?xml version="1.0" encoding="utf-8"?>
<providers
xmlns="http://ibatis.apache.org/providers"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
![](/Images/OutliningIndicators/None.gif)
<clear/>
<provider
name="sqlServer1.0"
description="Microsoft SQL Server, provider V1.0.3300.0 in framework .NET V1.0"
enabled="false"
assemblyName="System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" connectionClass="System.Data.SqlClient.SqlConnection"
commandClass="System.Data.SqlClient.SqlCommand"
parameterClass="System.Data.SqlClient.SqlParameter"
parameterDbTypeClass="System.Data.SqlDbType"
parameterDbTypeProperty="SqlDbType"
dataAdapterClass="System.Data.SqlClient.SqlDataAdapter"
commandBuilderClass="System.Data.SqlClient.SqlCommandBuilder"
usePositionalParameters="false"
useParameterPrefixInSql="true"
useParameterPrefixInParameter="true"
parameterPrefix="@"
allowMARS="false"
/>
<provider
name="sqlServer1.1"
description="Microsoft SQL Server, provider V1.0.5000.0 in framework .NET V1.1"
enabled="false"
default="true"
assemblyName="System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
connectionClass="System.Data.SqlClient.SqlConnection"
commandClass="System.Data.SqlClient.SqlCommand"
parameterClass="System.Data.SqlClient.SqlParameter"
parameterDbTypeClass="System.Data.SqlDbType"
parameterDbTypeProperty="SqlDbType"
dataAdapterClass="System.Data.SqlClient.SqlDataAdapter"
commandBuilderClass="System.Data.SqlClient.SqlCommandBuilder"
usePositionalParameters="false"
useParameterPrefixInSql="true"
useParameterPrefixInParameter="true"
parameterPrefix="@"
allowMARS="false"
/>
<provider
name="sqlServer2.0"
enabled="true"
description="Microsoft SQL Server, provider V2.0.0.0 in framework .NET V2.0"
assemblyName="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
connectionClass="System.Data.SqlClient.SqlConnection"
commandClass="System.Data.SqlClient.SqlCommand"
parameterClass="System.Data.SqlClient.SqlParameter"
parameterDbTypeClass="System.Data.SqlDbType"
parameterDbTypeProperty="SqlDbType"
dataAdapterClass="System.Data.SqlClient.SqlDataAdapter"
commandBuilderClass=" System.Data.SqlClient.SqlCommandBuilder"
usePositionalParameters = "false"
useParameterPrefixInSql = "true"
useParameterPrefixInParameter = "true"
parameterPrefix="@"
allowMARS="false"
/>
<provider name="OleDb1.1"
description="OleDb, provider V1.0.5000.0 in framework .NET V1.1"
enabled="false"
assemblyName="System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
connectionClass="System.Data.OleDb.OleDbConnection"
commandClass="System.Data.OleDb.OleDbCommand"
parameterClass="System.Data.OleDb.OleDbParameter"
parameterDbTypeClass="System.Data.OleDb.OleDbType"
parameterDbTypeProperty="OleDbType"
dataAdapterClass="System.Data.OleDb.OleDbDataAdapter"
commandBuilderClass="System.Data.OleDb.OleDbCommandBuilder"
usePositionalParameters="true"
useParameterPrefixInSql="false"
useParameterPrefixInParameter="false"
parameterPrefix=""
allowMARS="false"
/>
<provider name="OleDb2.0"
description="OleDb, provider V2.0.0.0 in framework .NET V2"
enabled="false"
assemblyName="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
connectionClass="System.Data.OleDb.OleDbConnection"
commandClass="System.Data.OleDb.OleDbCommand"
parameterClass="System.Data.OleDb.OleDbParameter"
parameterDbTypeClass="System.Data.OleDb.OleDbType"
parameterDbTypeProperty="OleDbType"
dataAdapterClass="System.Data.OleDb.OleDbDataAdapter"
commandBuilderClass="System.Data.OleDb.OleDbCommandBuilder"
usePositionalParameters="true"
useParameterPrefixInSql="false"
useParameterPrefixInParameter="false"
parameterPrefix=""
allowMARS="false"
/>
<provider
name="Odbc1.1"
description="Odbc, provider V1.0.5000.0 in framework .NET V1.1"
enabled="false"
assemblyName="System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
connectionClass="System.Data.Odbc.OdbcConnection"
commandClass="System.Data.Odbc.OdbcCommand"
parameterClass="System.Data.Odbc.OdbcParameter"
parameterDbTypeClass="System.Data.Odbc.OdbcType"
parameterDbTypeProperty="OdbcType"
dataAdapterClass="System.Data.Odbc.OdbcDataAdapter"
commandBuilderClass="System.Data.Odbc.OdbcCommandBuilder"
usePositionalParameters="true"
useParameterPrefixInSql="false"
useParameterPrefixInParameter="false"
parameterPrefix="@"
allowMARS="false"
/>
<provider
name="Odbc2.0"
description="Odbc, provider V2.0.0.0 in framework .NET V2"
enabled="false"
assemblyName="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
connectionClass="System.Data.Odbc.OdbcConnection"
commandClass="System.Data.Odbc.OdbcCommand"
parameterClass="System.Data.Odbc.OdbcParameter"
parameterDbTypeClass="System.Data.Odbc.OdbcType"
parameterDbTypeProperty="OdbcType"
dataAdapterClass="System.Data.Odbc.OdbcDataAdapter"
commandBuilderClass="System.Data.Odbc.OdbcCommandBuilder"
usePositionalParameters="true"
useParameterPrefixInSql="false"
useParameterPrefixInParameter="false"
parameterPrefix="@"
allowMARS="false"
/>
<provider
name="oracle9.2"
description="Oracle, Oracle provider V9.2.0.401"
enabled="false"
assemblyName="Oracle.DataAccess, Version=9.2.0.401, Culture=neutral, PublicKeyToken=89b483f429c47342" connectionClass="Oracle.DataAccess.Client.OracleConnection"
commandClass="Oracle.DataAccess.Client.OracleCommand"
parameterClass="Oracle.DataAccess.Client.OracleParameter"
parameterDbTypeClass="Oracle.DataAccess.Client.OracleDbType"
parameterDbTypeProperty="OracleDbType"
dataAdapterClass="Oracle.DataAccess.Client.OracleDataAdapter"
commandBuilderClass="Oracle.DataAccess.Client.OracleCommandBuilder"
usePositionalParameters="false"
useParameterPrefixInSql="true"
useParameterPrefixInParameter="false"
parameterPrefix=":"
useDeriveParameters="false"
allowMARS="false"
/>
<provider
name="oracle10.1"
description="Oracle, oracle provider V10.1.0.301"
enabled="false"
assemblyName="Oracle.DataAccess, Version=10.1.0.301, Culture=neutral, PublicKeyToken=89b483f429c47342" connectionClass="Oracle.DataAccess.Client.OracleConnection"
commandClass="Oracle.DataAccess.Client.OracleCommand"
parameterClass="Oracle.DataAccess.Client.OracleParameter"
parameterDbTypeClass="Oracle.DataAccess.Client.OracleDbType"
parameterDbTypeProperty="OracleDbType"
dataAdapterClass="Oracle.DataAccess.Client.OracleDataAdapter"
commandBuilderClass="Oracle.DataAccess.Client.OracleCommandBuilder"
usePositionalParameters="true"
useParameterPrefixInSql="true"
useParameterPrefixInParameter="true"
parameterPrefix=":"
useDeriveParameters="false"
allowMARS="false"
/>
<provider
name="oracleClient1.0"
description="Oracle, Microsoft provider V1.0.5000.0"
enabled="false"
assemblyName="System.Data.OracleClient, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" connectionClass="System.Data.OracleClient.OracleConnection"
commandClass="System.Data.OracleClient.OracleCommand"
parameterClass="System.Data.OracleClient.OracleParameter"
parameterDbTypeClass="System.Data.OracleClient.OracleType"
parameterDbTypeProperty="OracleType"
dataAdapterClass="System.Data.OracleClient.OracleDataAdapter"
commandBuilderClass="System.Data.OracleClient.OracleCommandBuilder"
usePositionalParameters="false"
useParameterPrefixInSql="true"
useParameterPrefixInParameter="false"
parameterPrefix=":"
allowMARS="false"
/>
<provider
name="ByteFx"
description="MySQL, ByteFx provider V0.7.6.15073"
enabled="false"
assemblyName="ByteFX.MySqlClient, Version=0.7.6.15073, Culture=neutral, PublicKeyToken=f2fef6fed1732fc1" connectionClass="ByteFX.Data.MySqlClient.MySqlConnection"
commandClass="ByteFX.Data.MySqlClient.MySqlCommand"
parameterClass="ByteFX.Data.MySqlClient.MySqlParameter"
parameterDbTypeClass="ByteFX.Data.MySqlClient.MySqlDbType"
parameterDbTypeProperty="MySqlDbType"
dataAdapterClass="ByteFX.Data.MySqlClient.MySqlDataAdapter"
commandBuilderClass="ByteFX.Data.MySqlClient.MySqlCommandBuilder"
usePositionalParameters="false"
useParameterPrefixInSql="true"
useParameterPrefixInParameter="true"
parameterPrefix="@"
allowMARS="false"
/>
<provider
name="MySql"
description="MySQL, MySQL provider 1.0.7.30072"
enabled="false"
assemblyName="MySql.Data, Version=1.0.7.30072, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionClass="MySql.Data.MySqlClient.MySqlConnection"
commandClass="MySql.Data.MySqlClient.MySqlCommand"
parameterClass="MySql.Data.MySqlClient.MySqlParameter"
parameterDbTypeClass="MySql.Data.MySqlClient.MySqlDbType"
parameterDbTypeProperty="MySqlDbType"
dataAdapterClass="MySql.Data.MySqlClient.MySqlDataAdapter"
commandBuilderClass="MySql.Data.MySqlClient.MySqlCommandBuilder"
usePositionalParameters="false"
useParameterPrefixInSql="true"
useParameterPrefixInParameter="true"
parameterPrefix="?"
allowMARS="false"
/>
<provider name="SQLite3"
description="SQLite, SQLite.NET provider V0.21.1869.3794"
enabled="false"
assemblyName="SQLite.NET, Version=0.21.1869.3794, Culture=neutral, PublicKeyToken=c273bd375e695f9c"
connectionClass="Finisar.SQLite.SQLiteConnection"
commandClass="Finisar.SQLite.SQLiteCommand"
parameterClass="Finisar.SQLite.SQLiteParameter"
parameterDbTypeClass="System.Data.DbType, System.Data"
parameterDbTypeProperty="DbType"
dataAdapterClass="Finisar.SQLite.SQLiteDataAdapter"
commandBuilderClass="Finisar.SQLite.SQLiteCommandBuilder"
usePositionalParameters="false"
useParameterPrefixInSql="true"
useParameterPrefixInParameter="true"
parameterPrefix="@"
setDbParameterPrecision="false"
setDbParameterScale="false"
allowMARS="false"
/>
<provider
name="Firebird1.7"
description="Firebird, Firebird SQL .NET provider V1.7.0.33200"
enabled="false"
assemblyName="FirebirdSql.Data.Firebird, Version=1.7.0.33200, Culture=neutral, PublicKeyToken=fa843d180294369d" connectionClass="FirebirdSql.Data.Firebird.FbConnection"
commandClass="FirebirdSql.Data.Firebird.FbCommand"
parameterClass="FirebirdSql.Data.Firebird.FbParameter"
parameterDbTypeClass="FirebirdSql.Data.Firebird.FbDbType"
parameterDbTypeProperty="FbDbType"
dataAdapterClass="FirebirdSql.Data.Firebird.FbDataAdapter"
commandBuilderClass="FirebirdSql.Data.Firebird.FbCommandBuilder"
usePositionalParameters="false"
useParameterPrefixInSql="true"
useParameterPrefixInParameter="true"
parameterPrefix="@"
allowMARS="false"
/>
<provider
name="PostgreSql0.99.1.0"
description="PostgreSql, Npgsql provider V0.99.1.0"
enabled="false"
assemblyName="Npgsql, Version=0.99.1.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7"
connectionClass="Npgsql.NpgsqlConnection"
commandClass="Npgsql.NpgsqlCommand"
parameterClass="Npgsql.NpgsqlParameter"
parameterDbTypeClass="NpgsqlTypes.NpgsqlDbType"
parameterDbTypeProperty="NpgsqlDbType"
dataAdapterClass="Npgsql.NpgsqlDataAdapter"
commandBuilderClass="Npgsql.NpgsqlCommandBuilder"
usePositionalParameters="false"
useParameterPrefixInSql="true"
useParameterPrefixInParameter="true"
parameterPrefix=":"
allowMARS="true"
/>
<provider
name="iDb2.10"
description="IBM DB2 Provider, V 10.0"
enabled="false"
assemblyName="IBM.Data.DB2.iSeries, Version=10.0.0.0,Culture=neutral, PublicKeyToken=9cdb2ebfb1f93a26, Custom=null" connectionClass="IBM.Data.DB2.iSeries.iDB2Connection"
commandClass="IBM.Data.DB2.iSeries.iDB2Command"
parameterClass="IBM.Data.DB2.iSeries.iDB2Parameter"
parameterDbTypeClass="IBM.Data.DB2.iSeries.iDB2DbType"
parameterDbTypeProperty="iDB2DbType"
dataAdapterClass="IBM.Data.DB2.iSeries.iDB2DataAdapter"
commandBuilderClass="IBM.Data.DB2.iSeries.iDB2CommandBuilder"
usePositionalParameters="true"
useParameterPrefixInSql="false"
useParameterPrefixInParameter="false"
parameterPrefix=""
allowMARS="false"
/>
<provider
name="Informix"
description="Informix NET Provider, 2.81.0.0"
enabled="false"
assemblyName="IBM.Data.Informix, Version=2.81.0.0, Culture=neutral, PublicKeyToken=7c307b91aa13d208"
connectionClass="IBM.Data.Informix.IfxConnection"
commandClass="IBM.Data.Informix.IfxCommand"
parameterClass="IBM.Data.Informix.IfxParameter"
parameterDbTypeClass="IBM.Data.Informix.IfxType"
parameterDbTypeProperty="IfxType"
dataAdapterClass="IBM.Data.Informix.IfxDataAdapter"
commandBuilderClass="IBM.Data.Informix.IfxCommandBuilder"
usePositionalParameters = "true"
useParameterPrefixInSql = "false"
useParameterPrefixInParameter = "false"
useDeriveParameters="false"
allowMARS="false"
/>
</providers>
sqlMap.config内容
![](/Images/OutliningIndicators/ContractedBlock.gif)
sqlMap.config
<?xml version="1.0" encoding="utf-8"?>
<sqlMapConfig
xmlns="http://ibatis.apache.org/dataMapper"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<settings>
<setting useStatementNamespaces="false"/>
<setting cacheModelsEnabled="true"/>
<setting useReflectionOptimizer="true"/>
</settings>
<!--database providers-->
<providers resource="config/providers.config"/>
<database>
<provider name="sqlServer2.0"/>
<dataSource name="GTTOLCOM" connectionString="data source=TEE\SQLEXPRESS;database=SiteDir;user id=sa;password=123;connection reset=false;connection lifetime=5; min pool size=1; max pool size=100"/>
</database>
![](/Images/OutliningIndicators/None.gif)
<!--设置sqlmap,所有实体的数据库操作-->
![](/Images/OutliningIndicators/None.gif)
<sqlMaps>
<sqlMap resource="Maps/TbBgClass.config"/>
<sqlMap resource="Maps/TbComment.config"/>
<sqlMap resource="Maps/TbInfo.config"/>
<sqlMap resource="Maps/TbMenu.config"/>
<sqlMap resource="Maps/TbSiteConfig.config"/>
<sqlMap resource="Maps/TbUser.config"/>
<sqlMap resource="Maps/TbAdSite.config"/>
<sqlMap resource="Maps/TbFriendLinks.config"/>
<sqlMap resource="Maps/TbKey.config"/>
</sqlMaps>
</sqlMapConfig>
![](/Images/OutliningIndicators/None.gif)
Web.config
![](/Images/OutliningIndicators/ContractedBlock.gif)
Web.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
![](/Images/OutliningIndicators/None.gif)
<configSections>
<sectionGroup name="blowery.web">
<section name="httpCompress" type="blowery.Web.HttpCompress.SectionHandler, blowery.Web.HttpCompress"/>
</sectionGroup>
![](/Images/OutliningIndicators/None.gif)
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
<sectionGroup name="iBATIS">
<section name="logging" type="IBatisNet.Common.Logging.ConfigurationSectionHandler, IBatisNet.Common" />
![](/Images/OutliningIndicators/None.gif)
</sectionGroup>
<section name="monorail"
type="Castle.MonoRail.Framework.Configuration.MonoRailSectionHandler, Castle.MonoRail.Framework" />
<section name="castle"
type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor" />
</configSections>
![](/Images/OutliningIndicators/None.gif)
<!--
For more on MonoRail configuration see
http://www.castleproject.org/monorail/documentation/v1rc3/index.html
-->
<monorail smtpHost=""
smtpUsername=""
smtpPassword=""
useWindsorIntegration="true">
<controllers>
<assembly>GTTOLCOM.Web</assembly>
</controllers>
<viewEngines viewPathRoot="Views">
<add
xhtml="false"
type="Castle.MonoRail.Framework.Views.NVelocity.NVelocityViewEngine, Castle.MonoRail.Framework.Views.NVelocity" />
</viewEngines>
![](/Images/OutliningIndicators/None.gif)
<routing>
<rule>
<pattern>(/home/parentdirectory/)(\w+)/index.html$</pattern>
<replace><![CDATA[ /browse/index.castle?d=$2 ]]></replace>
</rule>
<rule>
<pattern>(/home/subdirectory/)(\w+)/index.html$</pattern>
<replace><![CDATA[ /browse/index.castle?sid=$2 ]]></replace>
</rule>
<rule>
<pattern>(/home/)(\w+)/(\w+)/index.html$</pattern>
<replace><![CDATA[ /browse/index.castle?le=$2&BID=$3 ]]></replace>
</rule>
<rule>
<pattern>(/home/)(\w+)/index.html$</pattern>
<replace><![CDATA[ /home/search.castle?search=$2 ]]></replace>
</rule>
<rule>
<pattern>(/home/)(\w+)(.)html$</pattern>
<replace><![CDATA[ /home/new.castle?list=$2 ]]></replace>
</rule>
<rule>
<pattern>(/home/ru/)(w{3}\.\w+\.\w{1,3})/index.html$</pattern>
<replace><![CDATA[ /browse/returnurl.castle?ru=$2 ]]></replace>
</rule>
<rule>
<pattern>(/home/datail/i/)(\d+)/index.html$</pattern>
<replace><![CDATA[ /browse/datail.castle?i=$2 ]]></replace>
</rule>
<rule>
<pattern>(/home/links/)(w{3}\.\w+\.\w{1,3})/index.html$</pattern>
<replace><![CDATA[ /friendlinks/index.castle?ul=$2 ]]></replace>
</rule>
<rule>
<pattern>(/home/comments/)(w{3}\.\w+\.\w{1,3})/index.html$</pattern>
<replace><![CDATA[ /comments/index.castle?ul=$2 ]]></replace>
</rule>
<rule>
<pattern>(/home/comments/all/)(w{3}\.\w+\.\w{1,3})/index.html$</pattern>
<replace><![CDATA[ /comments/all.castle?ul=$2 ]]></replace>
</rule>
</routing>
</monorail>
<iBATIS>
<logging>
<logFactoryAdapter type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA,
IBatisNet.Common.Logging.Log4Net">
<arg key="configType" value="file" />
<arg key="configFile" value="config/log4Net.config" />
</logFactoryAdapter>
</logging>
</iBATIS>
<system.web>
<pages enableViewState="false"/>
<authentication mode="Forms"/>
<trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true"/>
<compilation defaultLanguage="c#" debug="false">
</compilation>
<httpHandlers>
<add verb="*" path="*.castle"
type="Castle.MonoRail.Framework.MonoRailHttpHandlerFactory, Castle.MonoRail.Framework" />
<!-- block direct user access to template files -->
<add verb="*" path="*.vm" type="System.Web.HttpForbiddenHandler"/>
<add verb="*" path="*.vm" type="System.Web.HttpForbiddenHandler" />
<add verb="*" path="*.njs" type="System.Web.HttpForbiddenHandler" />
<add verb="*" path="*.brail" type="System.Web.HttpForbiddenHandler" />
<add verb="*" path="*.brailjs" type="System.Web.HttpForbiddenHandler" />
</httpHandlers>
<httpModules>
<add name="routing" type="Castle.MonoRail.Framework.RoutingModule, Castle.MonoRail.Framework" />
<add name="CompressionModule" type="blowery.Web.HttpCompress.HttpModule, blowery.web.HttpCompress"/>
<!-- Remove unnecessary Http Modules for faster pipeline -->
<remove name="WindowsAuthentication" />
<remove name="PassportAuthentication" />
<remove name="UrlAuthorization" />
<remove name="FileAuthorization" />
</httpModules>
</system.web>
<appSettings>
<add key="defaultRssTtl" value="10"/>
<add key="rssTempDir" value="./cache/"/>
</appSettings>
<castle>
<include uri="file://config/facilities.config" />
<include uri="file://config/components.config" />
<include uri="file://config/controllers.config" />
</castle>
<!-- config section for my http module -->
<blowery.web>
<!--
Here's an example on how to change the algorithm or compression level
<compressionModule preferredAlgorithm="deflate|gzip" compressionLevel="high|normal|low"/>
so, to use deflate by default, and high compression, you would use the following line
-->
<httpCompress preferredAlgorithm="gzip" compressionLevel="high">
<!--excludedMimeTypes 包含的在此的Mime类型将不被压缩-->
<excludedMimeTypes>
<add type="image/jpeg"/>
<add type="image/gif"/>
</excludedMimeTypes>
<!--excludedPaths 包含的在此的aspx将不被压缩-->
<excludedPaths>
<add path="NoCompress.aspx"/>
</excludedPaths>
</httpCompress>
</blowery.web>
</configuration>
![](/Images/OutliningIndicators/None.gif)
ContainerBLL.cs和GlobalApplication.cs文件,这俩文件存放与Web根目录下面
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
GlobalApplication
using System;
using System.Web;
using Castle.Facilities.AutomaticTransactionManagement;
using Castle.Facilities.IBatisNetIntegration;
using Castle.Windsor;
using Castle.Windsor.Configuration;
using Castle.Windsor.Configuration.Interpreters;
using log4net;
using Castle.Facilities.Logging;
![](/Images/OutliningIndicators/None.gif)
using GTTOLCOM.Dao;
using GTTOLCOM.Dao.IDao;
using GTTOLCOM.Business;
namespace GTTOLCOM.Web
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
public class GlobalApplication : HttpApplication, IContainerAccessor
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
private static IWindsorContainer container;
public GlobalApplication()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
IContainerAccessor#region IContainerAccessor
![](/Images/OutliningIndicators/InBlock.gif)
public IWindsorContainer Container
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return container; }
}
![](/Images/OutliningIndicators/InBlock.gif)
#endregion
![](/Images/OutliningIndicators/InBlock.gif)
public void Application_OnStart()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
container = new WindsorContainer(new XmlInterpreter());
RegisterComponents();
}
![](/Images/OutliningIndicators/InBlock.gif)
public void Application_OnEnd()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
container.Dispose();
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 注册普通组件
/// </summary>
protected void RegisterComponents()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
container.AddComponent("TbBgClassDao", typeof(ITbBgClassDao), typeof(TbBgClassDao));
container.AddComponent("TbBgClassBLL", typeof(TbBgClassBLL));
![](/Images/OutliningIndicators/InBlock.gif)
container.AddComponent("TbCommentDao", typeof(ITbCommentDao), typeof(TbCommentDao));
container.AddComponent("TbCommentBLL", typeof(TbCommentBLL));
![](/Images/OutliningIndicators/InBlock.gif)
container.AddComponent("TbInfoDao", typeof(ITbInfoDao), typeof(TbInfoDao));
container.AddComponent("TbInfoBLL", typeof(TbInfoBLL));
![](/Images/OutliningIndicators/InBlock.gif)
container.AddComponent("ITbMenuDao", typeof(ITbMenuDao), typeof(TbMenuDao));
container.AddComponent("TbMenuBLL", typeof(TbMenuBLL));
![](/Images/OutliningIndicators/InBlock.gif)
container.AddComponent("TbSiteConfigDao", typeof(ITbSiteConfigDao), typeof(TbSiteConfigDao));
container.AddComponent("TbSiteConfigBLL", typeof(TbSiteConfigBLL));
![](/Images/OutliningIndicators/InBlock.gif)
container.AddComponent("TbUserDao", typeof(ITbUserDao), typeof(TbUserDao));
container.AddComponent("TbUserBLL", typeof(TbUserBLL));
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
}
}
}
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
ContainerBLL
using System;
using System.Web;
using Castle.Facilities.AutomaticTransactionManagement;
using Castle.Facilities.IBatisNetIntegration;
using Castle.Windsor;
using Castle.Windsor.Configuration;
using Castle.Windsor.Configuration.Interpreters;
using log4net;
using Castle.Facilities.Logging;
![](/Images/OutliningIndicators/None.gif)
using GTTOLCOM.Dao;
using GTTOLCOM.Dao.IDao;
using GTTOLCOM.Business;
![](/Images/OutliningIndicators/None.gif)
namespace GTTOLCOM.Web
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
public sealed class ContainerBLL
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
private static volatile GlobalApplication _global = null;
private static object _syncRoot = new Object();
private static void InitGlobalApplication()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
_global = new GlobalApplication();
}
private static GlobalApplication Instance()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (_global == null)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
lock (_syncRoot)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (_global == null) // double-check
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
InitGlobalApplication();
}
}
}
return _global;
}
public static GlobalApplication Get()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return Instance();
}
}
}
![](/Images/OutliningIndicators/None.gif)
using System;
using System.Web;
using Castle.Facilities.AutomaticTransactionManagement;
using Castle.Facilities.IBatisNetIntegration;
using Castle.Windsor;
using Castle.Windsor.Configuration;
using Castle.Windsor.Configuration.Interpreters;
using log4net;
using Castle.Facilities.Logging;
![](/Images/OutliningIndicators/None.gif)
using GTTOLCOM.Dao;
using GTTOLCOM.Dao.IDao;
using GTTOLCOM.Business;
namespace GTTOLCOM.Web
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
public class GlobalApplication : HttpApplication, IContainerAccessor
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
private static IWindsorContainer container;
public GlobalApplication()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
IContainerAccessor#region IContainerAccessor
![](/Images/OutliningIndicators/InBlock.gif)
public IWindsorContainer Container
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return container; }
}
![](/Images/OutliningIndicators/InBlock.gif)
#endregion
![](/Images/OutliningIndicators/InBlock.gif)
public void Application_OnStart()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
container = new WindsorContainer(new XmlInterpreter());
RegisterComponents();
}
![](/Images/OutliningIndicators/InBlock.gif)
public void Application_OnEnd()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
container.Dispose();
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 注册普通组件
/// </summary>
protected void RegisterComponents()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
container.AddComponent("TbBgClassDao", typeof(ITbBgClassDao), typeof(TbBgClassDao));
container.AddComponent("TbBgClassBLL", typeof(TbBgClassBLL));
![](/Images/OutliningIndicators/InBlock.gif)
container.AddComponent("TbCommentDao", typeof(ITbCommentDao), typeof(TbCommentDao));
container.AddComponent("TbCommentBLL", typeof(TbCommentBLL));
![](/Images/OutliningIndicators/InBlock.gif)
container.AddComponent("TbInfoDao", typeof(ITbInfoDao), typeof(TbInfoDao));
container.AddComponent("TbInfoBLL", typeof(TbInfoBLL));
![](/Images/OutliningIndicators/InBlock.gif)
container.AddComponent("ITbMenuDao", typeof(ITbMenuDao), typeof(TbMenuDao));
container.AddComponent("TbMenuBLL", typeof(TbMenuBLL));
![](/Images/OutliningIndicators/InBlock.gif)
container.AddComponent("TbSiteConfigDao", typeof(ITbSiteConfigDao), typeof(TbSiteConfigDao));
container.AddComponent("TbSiteConfigBLL", typeof(TbSiteConfigBLL));
![](/Images/OutliningIndicators/InBlock.gif)
container.AddComponent("TbUserDao", typeof(ITbUserDao), typeof(TbUserDao));
container.AddComponent("TbUserBLL", typeof(TbUserBLL));
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
}
}
}
![](/Images/OutliningIndicators/None.gif)