标签:
<%@ CodeTemplate Language="C#" TargetLanguage="Xml" ResponseEncoding="UTF-8" Description="Template description here." %>
声明该模板文件使用的模板语言
<%@ Property Name="assemblyname" Type="System.String" Default="SomeValue" Optional="True" Category="Strings" Description="This is a sample string property." %> <%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table that the mapping file is based on" %>
声明属性的作用是为了给用户自定义声明
<%@ Assembly Name="SchemaExplorer" %> <%@ Assembly Name="System.Data" %> <%@ Import Namespace="SchemaExplorer" %> <%@ Import Namespace="System.Data" %>
<script runat="template"> public string ToLowercase(string str) { str = str.ToLower(); return str; } </script>
script标签一般是用来声明方法
<?xml version="1.0" encoding="UTF-8" ?> <sqlMap namespace="<%=SourceTable.Name%>" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <alias> <typeAlias alias="<%=SourceTable.Name%>" type="<%=assemblyname%>.<%=SourceTable.Name%>, <%=assemblyname%>" /> </alias> <resultMaps> <resultMap id="SelectResult" class="<%=SourceTable.Name%>"> <%for(int i=0;i<SourceTable.Columns.Count;i++){%> <result property="<%=SourceTable.Columns[i].Name%>" column="<%=ToLowercase(SourceTable.Columns[i].Name)%>" /> <%}%> </resultMap> </resultMaps> <statements> <select id="Select<%=SourceTable.Name%>" parameterClass="int" resultMap="SelectResult"> Select <%for(int i=0;i<SourceTable.Columns.Count;i++){%> <%=ToLowercase(SourceTable.Columns[i].Name)%><%if(i<SourceTable.Columns.Count - 1){%>,<%}%> <%}%> From <%=SourceTable.Name%> <dynamic prepend="WHERE"> <isParameterPresent> <% if(SourceTable.HasPrimaryKey){ %> <%for(int i=0;i<SourceTable.PrimaryKey.MemberColumns.Count;i++){%> <%=ToLowercase(SourceTable.PrimaryKey.MemberColumns[i].Name)%>=#<%=SourceTable.PrimaryKey.MemberColumns[i].Name%># <%if(i<SourceTable.PrimaryKey.MemberColumns.Count-1){%>AND<%}%> <%}%> <% } %> </isParameterPresent> </dynamic> </select> <select id="BaseSelect<%=SourceTable.Name%>" parameterClass="int" resultMap="SelectResult"> Select <%for(int i=0;i<SourceTable.Columns.Count;i++){%> <%=ToLowercase(SourceTable.Columns[i].Name)%><%if(i<SourceTable.Columns.Count - 1){%>,<%}%> <%}%> From <%=SourceTable.Name%> </select> <select id="ChildSelect<%=SourceTable.Name%>" parameterClass="int" resultMap="SelectResult" extends="BaseSelect<%=SourceTable.Name%>"> </select> <insert id="Insert<%=SourceTable.Name%>" parameterClass="<%=SourceTable.Name%>"> Insert Into <%=SourceTable.Name%> ( <%for(int i=0;i<SourceTable.Columns.Count;i++){%> <%=ToLowercase(SourceTable.Columns[i].Name)%><%if(i<SourceTable.Columns.Count - 1){%>,<%}%> <%}%> )Values( <%for(int i=0;i<SourceTable.Columns.Count;i++){%> #<%=SourceTable.Columns[i].Name%>#<%if(i<SourceTable.Columns.Count - 1){%>,<%}%> <%}%> ) </insert> <update id="Update<%=SourceTable.Name%>" parameterClass="<%=SourceTable.Name%>"> Update <%=SourceTable.Name%> Set <%for(int i=0;i<SourceTable.Columns.Count;i++){%> <%=ToLowercase(SourceTable.Columns[i].Name)%>=#<%=SourceTable.Columns[i].Name%>#<%if(i<SourceTable.Columns.Count - 1){%>,<%}%> <%}%> <dynamic prepend="WHERE"> <isParameterPresent> <% if(SourceTable.HasPrimaryKey){ %> <%for(int i=0;i<SourceTable.PrimaryKey.MemberColumns.Count;i++){%> <%=ToLowercase(SourceTable.PrimaryKey.MemberColumns[i].Name)%>=#<%=SourceTable.PrimaryKey.MemberColumns[i].Name%>#<%if(i<SourceTable.PrimaryKey.MemberColumns.Count-1){%>AND<%}%> <%}%> <% } %> </isParameterPresent> </dynamic> </update> <delete id="Delete<%=SourceTable.Name%>" parameterClass="int"> Delete From <%=SourceTable.Name%> <dynamic prepend="WHERE"> <isParameterPresent> <% if(SourceTable.HasPrimaryKey){ %> <%for(int i=0;i<SourceTable.PrimaryKey.MemberColumns.Count;i++){%> <%=ToLowercase(SourceTable.PrimaryKey.MemberColumns[i].Name)%>=#<%=SourceTable.PrimaryKey.MemberColumns[i].Name%>#<%if(i<SourceTable.PrimaryKey.MemberColumns.Count-1){%>AND<%}%> <%}%> <% } %> </isParameterPresent> </dynamic> </delete> </statements> </sqlMap>
声明输出的内容
标签:
原文地址:http://www.cnblogs.com/ilooking/p/4681573.html