1、先建立两个模板文件 :Manger.ttinclude、DBHelper.ttinclude

  1. Manger.ttinclude
  2.  
  3. <#@ assembly name="System.Core"#>
  4. <#@ assembly name="System.Data.Linq"#>
  5. <#@ assembly name="EnvDTE"#>
  6. <#@ assembly name="System.Xml"#>
  7. <#@ assembly name="System.Xml.Linq"#>
  8. <#@ import namespace="System"#>
  9. <#@ import namespace="System.CodeDom"#>
  10. <#@ import namespace="System.CodeDom.Compiler"#>
  11. <#@ import namespace="System.Collections.Generic"#>
  12. <#@ import namespace="System.Data.Linq"#>
  13. <#@ import namespace="System.Data.Linq.Mapping"#>
  14. <#@ import namespace="System.IO"#>
  15. <#@ import namespace="System.Linq"#>
  16. <#@ import namespace="System.Reflection"#>
  17. <#@ import namespace="System.Text"#>
  18. <#@ import namespace="System.Xml.Linq"#>
  19. <#@ import namespace="Microsoft.VisualStudio.TextTemplating"#>
  20. <#+
  21.  
  22. // Manager class records the various blocks so it can split them up
  23. class Manager {
  24. private class Block {
  25. public String Name;
  26. public int Start, Length;
  27. }
  28.  
  29. private Block currentBlock;
  30. private List<Block> files = new List<Block>();
  31. private Block footer = new Block();
  32. private Block header = new Block();
  33. private ITextTemplatingEngineHost host;
  34. private StringBuilder template;
  35. protected List<String> generatedFileNames = new List<String>();
  36.  
  37. public static Manager Create(ITextTemplatingEngineHost host, StringBuilder template) {
  38. return (host is IServiceProvider) ? new VSManager(host, template) : new Manager(host, template);
  39. }
  40.  
  41. public void StartNewFile(String name) {
  42. if (name == null)
  43. throw new ArgumentNullException("name");
  44. CurrentBlock = new Block { Name = name };
  45. }
  46.  
  47. public void StartFooter() {
  48. CurrentBlock = footer;
  49. }
  50.  
  51. public void StartHeader() {
  52. CurrentBlock = header;
  53. }
  54.  
  55. public void EndBlock() {
  56. if (CurrentBlock == null)
  57. return;
  58. CurrentBlock.Length = template.Length - CurrentBlock.Start;
  59. if (CurrentBlock != header && CurrentBlock != footer)
  60. files.Add(CurrentBlock);
  61. currentBlock = null;
  62. }
  63.  
  64. public virtual void Process(bool split) {
  65. if (split) {
  66. EndBlock();
  67. String headerText = template.ToString(header.Start, header.Length);
  68. String footerText = template.ToString(footer.Start, footer.Length);
  69. String outputPath = Path.GetDirectoryName(host.TemplateFile);
  70. files.Reverse();
  71. foreach(Block block in files) {
  72. String fileName = Path.Combine(outputPath, block.Name);
  73. String content = headerText + template.ToString(block.Start, block.Length) + footerText;
  74. generatedFileNames.Add(fileName);
  75. CreateFile(fileName, content);
  76. template.Remove(block.Start, block.Length);
  77. }
  78. }
  79. }
  80.  
  81. protected virtual void CreateFile(String fileName, String content) {
  82. if (IsFileContentDifferent(fileName, content))
  83. File.WriteAllText(fileName, content);
  84. }
  85.  
  86. public virtual String GetCustomToolNamespace(String fileName) {
  87. return null;
  88. }
  89.  
  90. public virtual String DefaultProjectNamespace {
  91. get { return null; }
  92. }
  93.  
  94. protected bool IsFileContentDifferent(String fileName, String newContent) {
  95. return !(File.Exists(fileName) && File.ReadAllText(fileName) == newContent);
  96. }
  97.  
  98. private Manager(ITextTemplatingEngineHost host, StringBuilder template) {
  99. this.host = host;
  100. this.template = template;
  101. }
  102.  
  103. private Block CurrentBlock {
  104. get { return currentBlock; }
  105. set {
  106. if (CurrentBlock != null)
  107. EndBlock();
  108. if (value != null)
  109. value.Start = template.Length;
  110. currentBlock = value;
  111. }
  112. }
  113.  
  114. private class VSManager: Manager {
  115. private EnvDTE.ProjectItem templateProjectItem;
  116. private EnvDTE.DTE dte;
  117. private Action<String> checkOutAction;
  118. private Action<IEnumerable<String>> projectSyncAction;
  119.  
  120. public override String DefaultProjectNamespace {
  121. get {
  122. return templateProjectItem.ContainingProject.Properties.Item("DefaultNamespace").Value.ToString();
  123. }
  124. }
  125.  
  126. public override String GetCustomToolNamespace(string fileName) {
  127. return dte.Solution.FindProjectItem(fileName).Properties.Item("CustomToolNamespace").Value.ToString();
  128. }
  129.  
  130. public override void Process(bool split) {
  131. if (templateProjectItem.ProjectItems == null)
  132. return;
  133. base.Process(split);
  134. projectSyncAction.EndInvoke(projectSyncAction.BeginInvoke(generatedFileNames, null, null));
  135. }
  136.  
  137. protected override void CreateFile(String fileName, String content) {
  138. if (IsFileContentDifferent(fileName, content)) {
  139. CheckoutFileIfRequired(fileName);
  140. File.WriteAllText(fileName, content);
  141. }
  142. }
  143.  
  144. internal VSManager(ITextTemplatingEngineHost host, StringBuilder template)
  145. : base(host, template) {
  146. var hostServiceProvider = (IServiceProvider) host;
  147. if (hostServiceProvider == null)
  148. throw new ArgumentNullException("Could not obtain IServiceProvider");
  149. dte = (EnvDTE.DTE) hostServiceProvider.GetService(typeof(EnvDTE.DTE));
  150. if (dte == null)
  151. throw new ArgumentNullException("Could not obtain DTE from host");
  152. templateProjectItem = dte.Solution.FindProjectItem(host.TemplateFile);
  153. checkOutAction = (String fileName) => dte.SourceControl.CheckOutItem(fileName);
  154. projectSyncAction = (IEnumerable<String> keepFileNames) => ProjectSync(templateProjectItem, keepFileNames);
  155. }
  156.  
  157. private static void ProjectSync(EnvDTE.ProjectItem templateProjectItem, IEnumerable<String> keepFileNames) {
  158. var keepFileNameSet = new HashSet<String>(keepFileNames);
  159. var projectFiles = new Dictionary<String, EnvDTE.ProjectItem>();
  160. var originalFilePrefix = Path.GetFileNameWithoutExtension(templateProjectItem.get_FileNames()) + ".";
  161. foreach(EnvDTE.ProjectItem projectItem in templateProjectItem.ProjectItems)
  162. projectFiles.Add(projectItem.get_FileNames(), projectItem);
  163.  
  164. // Remove unused items from the project
  165. foreach(var pair in projectFiles)
  166. if (!keepFileNames.Contains(pair.Key) && !(Path.GetFileNameWithoutExtension(pair.Key) + ".").StartsWith(originalFilePrefix))
  167. pair.Value.Delete();
  168.  
  169. // Add missing files to the project
  170. foreach(String fileName in keepFileNameSet)
  171. if (!projectFiles.ContainsKey(fileName))
  172. templateProjectItem.ProjectItems.AddFromFile(fileName);
  173. }
  174.  
  175. private void CheckoutFileIfRequired(String fileName) {
  176. var sc = dte.SourceControl;
  177. if (sc != null && sc.IsItemUnderSCC(fileName) && !sc.IsItemCheckedOut(fileName))
  178. checkOutAction.EndInvoke(checkOutAction.BeginInvoke(fileName, null, null));
  179. }
  180. }
  181. } #>
  1. DBHelper.ttinclude
    <#+
  2. public class DbHelper
  3. {
  4. #region GetDbTables
  5.  
  6. public static List<DbTable> GetDbTables(string connectionString, string database, string tables = null)
  7. {
  8.  
  9. if (!string.IsNullOrEmpty(tables))
  10. {
  11. tables = string.Format(" and obj.name in ('{0}')", tables.Replace(",", "','"));
  12. }
  13. #region SQL
  14. string sql = string.Format(@"SELECT
  15. obj.name tablename,
  16. schem.name schemname,
  17. idx.rows,
  18. CAST
  19. (
  20. CASE
  21. WHEN (SELECT COUNT(1) FROM sys.indexes WHERE object_id= obj.OBJECT_ID AND is_primary_key=1) >=1 THEN 1
  22. ELSE 0
  23. END
  24. AS BIT) HasPrimaryKey
  25. from {0}.sys.objects obj
  26. inner join {0}.dbo.sysindexes idx on obj.object_id=idx.id and idx.indid<=1
  27. INNER JOIN {0}.sys.schemas schem ON obj.schema_id=schem.schema_id
  28. where type='U' {1}
  29. order by obj.name", database, tables);
  30. #endregion
  31. DataTable dt = GetDataTable(connectionString, sql);
  32. return dt.Rows.Cast<DataRow>().Select(row => new DbTable
  33. {
  34. TableName = row.Field<string>("tablename"),
  35. SchemaName = row.Field<string>("schemname"),
  36. Rows = row.Field<int>("rows"),
  37. HasPrimaryKey = row.Field<bool>("HasPrimaryKey")
  38. }).ToList();
  39. }
  40. #endregion
  41.  
  42. #region GetDbColumns
  43.  
  44. public static List<DbColumn> GetDbColumns(string connectionString, string database, string tableName, string schema = "dbo")
  45. {
  46. #region SQL
  47. string sql = string.Format(@"
  48. WITH indexCTE AS
  49. (
  50. SELECT
  51. ic.column_id,
  52. ic.index_column_id,
  53. ic.object_id
  54. FROM {0}.sys.indexes idx
  55. INNER JOIN {0}.sys.index_columns ic ON idx.index_id = ic.index_id AND idx.object_id = ic.object_id
  56. WHERE idx.object_id =OBJECT_ID(@tableName) AND idx.is_primary_key=1
  57. )
  58. select
  59. colm.column_id ColumnID,
  60. CAST(CASE WHEN indexCTE.column_id IS NULL THEN 0 ELSE 1 END AS BIT) IsPrimaryKey,
  61. colm.name ColumnName,
  62. systype.name ColumnType,
  63. colm.is_identity IsIdentity,
  64. colm.is_nullable IsNullable,
  65. cast(colm.max_length as int) ByteLength,
  66. (
  67. case
  68. when systype.name='nvarchar' and colm.max_length>0 then colm.max_length/2
  69. when systype.name='nchar' and colm.max_length>0 then colm.max_length/2
  70. when systype.name='ntext' and colm.max_length>0 then colm.max_length/2
  71. else colm.max_length
  72. end
  73. ) CharLength,
  74. cast(colm.precision as int) Precision,
  75. cast(colm.scale as int) Scale,
  76. prop.value Remark
  77. from {0}.sys.columns colm
  78. inner join {0}.sys.types systype on colm.system_type_id=systype.system_type_id and colm.user_type_id=systype.user_type_id
  79. left join {0}.sys.extended_properties prop on colm.object_id=prop.major_id and colm.column_id=prop.minor_id
  80. LEFT JOIN indexCTE ON colm.column_id=indexCTE.column_id AND colm.object_id=indexCTE.object_id
  81. where colm.object_id=OBJECT_ID(@tableName)
  82. order by colm.column_id", database);
  83. #endregion
  84. SqlParameter param = new SqlParameter("@tableName", SqlDbType.NVarChar, ) { Value = string.Format("{0}.{1}.{2}", database, schema, tableName) };
  85. DataTable dt = GetDataTable(connectionString, sql, param);
  86. return dt.Rows.Cast<DataRow>().Select(row => new DbColumn()
  87. {
  88. ColumnID = row.Field<int>("ColumnID"),
  89. IsPrimaryKey = row.Field<bool>("IsPrimaryKey"),
  90. ColumnName = row.Field<string>("ColumnName"),
  91. ColumnType = row.Field<string>("ColumnType"),
  92. IsIdentity = row.Field<bool>("IsIdentity"),
  93. IsNullable = row.Field<bool>("IsNullable"),
  94. ByteLength = row.Field<int>("ByteLength"),
  95. CharLength = row.Field<int>("CharLength"),
  96. Scale = row.Field<int>("Scale"),
  97. Remark = row["Remark"].ToString()
  98. }).ToList();
  99. }
  100.  
  101. #endregion
  102.  
  103. #region GetDataTable
  104.  
  105. public static DataTable GetDataTable(string connectionString, string commandText, params SqlParameter[] parms)
  106. {
  107. using (SqlConnection connection = new SqlConnection(connectionString))
  108. {
  109. SqlCommand command = connection.CreateCommand();
  110. command.CommandText = commandText;
  111. command.Parameters.AddRange(parms);
  112. SqlDataAdapter adapter = new SqlDataAdapter(command);
  113.  
  114. DataTable dt = new DataTable();
  115. adapter.Fill(dt);
  116.  
  117. return dt;
  118. }
  119. }
  120.  
  121. #endregion
  122. }
  123.  
  124. #region DbTable
  125. /// <summary>
  126. /// 表结构
  127. /// </summary>
  128. public sealed class DbTable
  129. {
  130. /// <summary>
  131. /// 表名称
  132. /// </summary>
  133. public string TableName { get; set; }
  134. /// <summary>
  135. /// 表的架构
  136. /// </summary>
  137. public string SchemaName { get; set; }
  138. /// <summary>
  139. /// 表的记录数
  140. /// </summary>
  141. public int Rows { get; set; }
  142.  
  143. /// <summary>
  144. /// 是否含有主键
  145. /// </summary>
  146. public bool HasPrimaryKey { get; set; }
  147. }
  148. #endregion
  149.  
  150. #region DbColumn
  151. /// <summary>
  152. /// 表字段结构
  153. /// </summary>
  154. public sealed class DbColumn
  155. {
  156. /// <summary>
  157. /// 字段ID
  158. /// </summary>
  159. public int ColumnID { get; set; }
  160.  
  161. /// <summary>
  162. /// 是否主键
  163. /// </summary>
  164. public bool IsPrimaryKey { get; set; }
  165.  
  166. /// <summary>
  167. /// 字段名称
  168. /// </summary>
  169. public string ColumnName { get; set; }
  170.  
  171. /// <summary>
  172. /// 字段类型
  173. /// </summary>
  174. public string ColumnType { get; set; }
  175.  
  176. /// <summary>
  177. /// 数据库类型对应的C#类型
  178. /// </summary>
  179. public string CSharpType
  180. {
  181. get
  182. {
  183. return SqlServerDbTypeMap.MapCsharpType(ColumnType);
  184. }
  185. }
  186.  
  187. /// <summary>
  188. ///
  189. /// </summary>
  190. public Type CommonType
  191. {
  192. get
  193. {
  194. return SqlServerDbTypeMap.MapCommonType(ColumnType);
  195. }
  196. }
  197.  
  198. /// <summary>
  199. /// 字节长度
  200. /// </summary>
  201. public int ByteLength { get; set; }
  202.  
  203. /// <summary>
  204. /// 字符长度
  205. /// </summary>
  206. public int CharLength { get; set; }
  207.  
  208. /// <summary>
  209. /// 小数位
  210. /// </summary>
  211. public int Scale { get; set; }
  212.  
  213. /// <summary>
  214. /// 是否自增列
  215. /// </summary>
  216. public bool IsIdentity { get; set; }
  217.  
  218. /// <summary>
  219. /// 是否允许空
  220. /// </summary>
  221. public bool IsNullable { get; set; }
  222.  
  223. /// <summary>
  224. /// 描述
  225. /// </summary>
  226. public string Remark { get; set; }
  227. }
  228. #endregion
  229.  
  230. #region SqlServerDbTypeMap
  231.  
  232. public class SqlServerDbTypeMap
  233. {
  234. public static string MapCsharpType(string dbtype)
  235. {
  236. if (string.IsNullOrEmpty(dbtype)) return dbtype;
  237. dbtype = dbtype.ToLower();
  238. string csharpType = "object";
  239. switch (dbtype)
  240. {
  241. case "bigint": csharpType = "long"; break;
  242. case "binary": csharpType = "byte[]"; break;
  243. case "bit": csharpType = "bool"; break;
  244. case "char": csharpType = "string"; break;
  245. case "date": csharpType = "DateTime"; break;
  246. case "datetime": csharpType = "DateTime"; break;
  247. case "datetime2": csharpType = "DateTime"; break;
  248. case "datetimeoffset": csharpType = "DateTimeOffset"; break;
  249. case "decimal": csharpType = "decimal"; break;
  250. case "float": csharpType = "double"; break;
  251. case "image": csharpType = "byte[]"; break;
  252. case "int": csharpType = "int"; break;
  253. case "money": csharpType = "decimal"; break;
  254. case "nchar": csharpType = "string"; break;
  255. case "ntext": csharpType = "string"; break;
  256. case "numeric": csharpType = "decimal"; break;
  257. case "nvarchar": csharpType = "string"; break;
  258. case "real": csharpType = "Single"; break;
  259. case "smalldatetime": csharpType = "DateTime"; break;
  260. case "smallint": csharpType = "short"; break;
  261. case "smallmoney": csharpType = "decimal"; break;
  262. case "sql_variant": csharpType = "object"; break;
  263. case "sysname": csharpType = "object"; break;
  264. case "text": csharpType = "string"; break;
  265. case "time": csharpType = "TimeSpan"; break;
  266. case "timestamp": csharpType = "byte[]"; break;
  267. case "tinyint": csharpType = "byte"; break;
  268. case "uniqueidentifier": csharpType = "Guid"; break;
  269. case "varbinary": csharpType = "byte[]"; break;
  270. case "varchar": csharpType = "string"; break;
  271. case "xml": csharpType = "string"; break;
  272. default: csharpType = "object"; break;
  273. }
  274. return csharpType;
  275. }
  276.  
  277. public static Type MapCommonType(string dbtype)
  278. {
  279. if (string.IsNullOrEmpty(dbtype)) return Type.Missing.GetType();
  280. dbtype = dbtype.ToLower();
  281. Type commonType = typeof(object);
  282. switch (dbtype)
  283. {
  284. case "bigint": commonType = typeof(long); break;
  285. case "binary": commonType = typeof(byte[]); break;
  286. case "bit": commonType = typeof(bool); break;
  287. case "char": commonType = typeof(string); break;
  288. case "date": commonType = typeof(DateTime); break;
  289. case "datetime": commonType = typeof(DateTime); break;
  290. case "datetime2": commonType = typeof(DateTime); break;
  291. case "datetimeoffset": commonType = typeof(DateTimeOffset); break;
  292. case "decimal": commonType = typeof(decimal); break;
  293. case "float": commonType = typeof(double); break;
  294. case "image": commonType = typeof(byte[]); break;
  295. case "int": commonType = typeof(int); break;
  296. case "money": commonType = typeof(decimal); break;
  297. case "nchar": commonType = typeof(string); break;
  298. case "ntext": commonType = typeof(string); break;
  299. case "numeric": commonType = typeof(decimal); break;
  300. case "nvarchar": commonType = typeof(string); break;
  301. case "real": commonType = typeof(Single); break;
  302. case "smalldatetime": commonType = typeof(DateTime); break;
  303. case "smallint": commonType = typeof(short); break;
  304. case "smallmoney": commonType = typeof(decimal); break;
  305. case "sql_variant": commonType = typeof(object); break;
  306. case "sysname": commonType = typeof(object); break;
  307. case "text": commonType = typeof(string); break;
  308. case "time": commonType = typeof(TimeSpan); break;
  309. case "timestamp": commonType = typeof(byte[]); break;
  310. case "tinyint": commonType = typeof(byte); break;
  311. case "uniqueidentifier": commonType = typeof(Guid); break;
  312. case "varbinary": commonType = typeof(byte[]); break;
  313. case "varchar": commonType = typeof(string); break;
  314. case "xml": commonType = typeof(string); break;
  315. default: commonType = typeof(object); break;
  316. }
  317. return commonType;
  318. }
  319. }
  320. #endregion
  321.  
  322. #>

使用类,如果出现重复引用的,那就删掉重复的

  1. TextTemplate1.tt
  2.  
  3. <#@ template debug="false" hostspecific="true" language="C#" #>
  4.  
  5. <#@ assembly name="System.Configuration.dll" #>
  6. <#@ import namespace="System.Text" #>
  7.  
  8. <#@ assembly name="System.Data.dll" #>
  9. <#@ assembly name="System.Data.DataSetExtensions.dll" #>
  10. <#@ import namespace="System" #>
  11. <#@ import namespace="System.Xml" #>
  12. <#@ import namespace="System.Linq" #>
  13. <#@ import namespace="System.Data" #>
  14. <#@ import namespace="System.Data.SqlClient" #>
  15. <#@ import namespace="System.Collections.Generic" #>
  16. <#@ import namespace="System.IO" #>
  17.  
  18. <#@ assembly name="System.Core"#>
  19. <#@ assembly name="System.Data.Linq"#>
  20. <#@ assembly name="EnvDTE"#>
  21. <#@ assembly name="System.Xml"#>
  22. <#@ assembly name="System.Xml.Linq"#>
  23. <#@ import namespace="System"#>
  24. <#@ import namespace="System.CodeDom"#>
  25. <#@ import namespace="System.CodeDom.Compiler"#>
  26. <#@ import namespace="System.Collections.Generic"#>
  27. <#@ import namespace="System.Data.Linq"#>
  28. <#@ import namespace="System.Data.Linq.Mapping"#>
  29. <#@ import namespace="System.IO"#>
  30. <#@ import namespace="System.Linq"#>
  31. <#@ import namespace="System.Reflection"#>
  32. <#@ import namespace="System.Text"#>
  33. <#@ import namespace="System.Xml.Linq"#>
  34. <#@ import namespace="Microsoft.VisualStudio.TextTemplating"#>
  35. <#@ output extension=".txt" encoding="utf-8" #>
  36.  
  37. <#@ include file="$(ProjectDir)Comm\Manger.ttinclude" #>
  38. <#@ include file="$(ProjectDir)Comm\DbHelper.ttinclude" #>
  39.  
  40. <#
  41. for (int i = ; i < ; i++)
  42. {
  43. Write(i.ToString());
  44. #>
  45. i.ToString()<#= i+ #>
  46. <#
  47. }
  48.  
  49. #>

MVC ---- T4模板的小练习的更多相关文章

  1. T4 模板 : 一种提升ASP.NET MVC开发速度方法

    最近由于需要在框架中提供一些自定义模板的功能,找到了一篇博客,可惜似乎是翻译工具直接翻的,读不通顺,就试着自己翻译下,我不会完全翻译原文的句子,可能会对原文进行小范围的我认为更合适的句子并添加些注释, ...

  2. ASP.NET MVC+EF框架+EasyUI实现权限管理系列(12)-实现用户异步登录和T4模板

    原文:ASP.NET MVC+EF框架+EasyUI实现权限管理系列(12)-实现用户异步登录和T4模板 ASP.NET MVC+EF框架+EasyUI实现权限管系列 (开篇)   (1):框架搭建  ...

  3. MVC实用架构设计(三)——EF-Code First(3):使用T4模板生成相似代码

    前言 经过前面EF的<第一篇>与<第二篇>,我们的数据层功能已经较为完善了,但有不少代码相似度较高,比如负责实体映射的 EntityConfiguration,负责仓储操作的I ...

  4. 快速开发框架,及库存管理系统,基于easyui框架和C#语言MVC、EntityFrameWork、T4模板技术。

    快速开发框架,及库存管理系统,基于easyui框架和C#语言MVC.EntityFrameWork.T4模板技术. 产品界面如下图所示: 源码结构: 开放全部源码,如有需要请联系,QQ:1107141 ...

  5. [转]MVC实用架构设计(三)——EF-Code First(3):使用T4模板生成相似代码

    本文转自:http://www.cnblogs.com/guomingfeng/p/mvc-ef-t4.html 〇.目录 一.前言 二.工具准备 三.T4代码生成预热 (一) 单文件生成:Hello ...

  6. 23、ASP.NET MVC入门到精通——业务层和数据层父类及接口-T4模板

    本系列目录:ASP.NET MVC4入门到精通系列目录汇总 在上一篇中,我们已经把项目的基本框架搭起来了,这一篇我们就来实现业务层和数据层的父接口及父类. 1.我们先来定义一个业务层父接口IBaseB ...

  7. asp.net mvc 通过T4模板生成框架

    http://www.cnblogs.com/rdst/archive/2012/08/13/2637210.html http://www.kuqin.com/shuoit/20140716/341 ...

  8. MVC 之 T4模板简介

    个人网站地址:nee32.com 一.T4模板内容简介 为了更好地学习T4模板,我们安装一个插件tangible T4 Editor 在使用了EF生成实体类后,我们会发现一个.tt后缀的文件,它就是T ...

  9. Asp.net MVC企业级开发(09)---T4模板

    T4即为Text Template Transformation Toolkit,一种可以由自己去自定义规则的代码生成器.根据业务模型可生成任何形式的文本文件或供程序调用的字符串 在VS中T4模板是没 ...

随机推荐

  1. 【剑指offer】旋转数组的最小数字

    一.题目: 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转. 输入一个非减排序的数组的一个旋转,输出旋转数组的最小元素. 例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个 ...

  2. 万恶之源 - Python基础数据类型一

    整数 整数在Python中的关键字用int来表示; 整型在计算机中运于计算和比较 在32位机器上int的范围是:  -2**31-2**31-1,即-2147483648-2147483647 在64 ...

  3. 5分钟带你入门vuex(vue状态管理)

    如果你之前使用过vue.js,你一定知道在vue中各个组件之间传值的痛苦,在vue中我们可以使用vuex来保存我们需要管理的状态值,值一旦被修改,所有引用该值的地方就会自动更新,那么接下来我们就来学习 ...

  4. 优化Ubuntu 16.04系统的几件事

    安装完Ubuntu 16.04后,要更换为国内的软件源: sudo gedit /etc/apt/sources.list #用文本编辑器打开源列表 在文件开头添加下面的阿里云的软件源: deb ht ...

  5. Mybatis的多对多映射

    一.Mybatis的多对多映射 本例讲述使用mybatis开发过程中常见的多对多映射查询案例.只抽取关键代码和mapper文件中的关键sql和配置,详细的工程搭建和Mybatis详细的流程代码可参见& ...

  6. java map.entry

    我希望要一个ArrayList<Entry>,类似C++中的pair, 但是Map.Entry是个接口,不能实例化,可以像下面这样写 HashMap<Integer, Integer ...

  7. C#导出Excel总结

    一.asp.net中导出Execl的方法:在asp.net中导出Execl有两种方法,一种是将导出的文件存放在服务器某个文件夹下面,然后将文件地址输出在浏览器上:一种是将文件直接将文件输出流写给浏览器 ...

  8. hihocoder博弈游戏·Nim游戏·三

    在这一次游戏中Alice和Bob决定在原来的Nim游戏上增加一条规则:每一次行动时,不仅可以选择一堆取走任意数量的石子(至少取1颗,至多取出这一堆剩下的所有石子),还可以选择将一堆石子分成两堆石子,但 ...

  9. 【kafka学习之三】kafka集群运维

    kafka集群维护一.kafka集群启停#启动kafka/home/cluster/kafka211/bin/kafka-server-start.sh -daemon /home/cluster/k ...

  10. C/C++之Memcpy and memmove

    memcpy与memmove的目的都是将N个字节的源内存地址的内容拷贝到目标内存地址中. 但当源内存和目标内存存在重叠时,memcpy会出现错误,而memmove能正确地实施拷贝,但这也增加了一点点开 ...