Nhibernate学习起步之many-to-one篇(转)

1.     学习目的:

通过进一步学习nhibernate基础知识,在实现单表CRUD的基础上,实现两表之间one-to-many的关系.

2.     开发环境+必要准备

开发环境: windows 2003,Visual studio .Net 2005,Sql server 2005 developer edition

必要准备: 学习上篇文章单表操作   

3. 对上篇文章中部分解释

 1)在User.hbm.xml中class节点中有一个lazy的属性,这个属性用于指定是否需要延迟加载(lazy loading),在官方文档中称为:lazy fecting.可以说延迟加载是nhibernate最好的特点,因为它可以在父类中透明的加载子类集合,这对于many-to-one的业务逻辑中,真是方便极了。但是有些时候,父类是不需要携带子类信息的。这时候如果也加载,无疑对性能是一种损失。在映射文件的class节点中可以通过配置lazy属性来指定是否支持延迟加载,这就更灵活多了。 

 2) 在User.hbm.xml中generate节点,代表的是主键的生成方式,上个例子中的”native”根据底层数据库的能力选择identity,hilo,sequence中的一个,比如在MS Sql中,使我们最经常使用的自动增长字段,每次加1. 

3) 在NHibernateHelper.cs中,创建Configuration对象的代码:new Configuration().Configure(@"E:\myproject\nhibernatestudy\simle1\NHibernateStudy1\NhibernateSample1\hibernate.cfg.xml");因为我是在单元测试中调试,所以将绝对路径的配置文件传递给构造函数。如果在windows app或者web app可以不用传递该参数。 

4. 实现步骤

 1)确定实现的业务需求:用户工资管理系统

 2) 打开上篇文章中的NHibernateStudy1解决方案。向项目NhibernateSample1添加类Salary;代码如下

ContractedBlock.gifExpandedBlockStart.gifSalary.cs
None.gifusing System;
None.gif
using System.Collections.Generic;
None.gif
using System.Text;
None.gif
None.gif
namespace NhibernateSample1
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    
public partial class Salary
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
int _id;
InBlock.gif        User _user;
InBlock.gif        
int _year;
InBlock.gif        
int _month;
InBlock.gif        
int _envy;
InBlock.gif        
decimal _money;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 工资编号
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public virtual int Id
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _id;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _id 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 雇员
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public virtual User Employee
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _user;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _user 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 年度
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public int Year
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _year;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _year 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 月份
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public int Month
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _month;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _month 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 季度
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public int Envy
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _envy;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _envy 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 工资
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public decimal Money
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _money;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _money 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

3) 更改User.cs,在User里面添加SalaryList属性:

ContractedBlock.gifExpandedBlockStart.gifUser.cs
 1None.gifprivate System.Collections.IList _salaryList;
 2ExpandedBlockStart.gifContractedBlock.gif /**//// <summary>
 3InBlock.gif        /// 工资列表
 4ExpandedBlockEnd.gif        /// </summary>

 5None.gif        public System.Collections.IList SalaryList
 6ExpandedBlockStart.gifContractedBlock.gif        dot.gif{
 7InBlock.gif            get
 8ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 9InBlock.gif                return _salaryList;
10ExpandedSubBlockEnd.gif            }

11InBlock.gif            set
12ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
13InBlock.gif                _salaryList = value;
14ExpandedSubBlockEnd.gif            }

15ExpandedBlockEnd.gif        }
4)修改User.hbm.xml,加入bag节点
ContractedBlock.gifExpandedBlockStart.gifUser.hbm.xml
None.gif<bag name="SalaryList" table="Salary" inverse="true" lazy="true" cascade="all">
None.gif      
<key column="Id"/>
None.gif      
<one-to-many class="NhibernateSample1.Salary,NhibernateSample1"></one-to-many>
None.gif    
</bag>

 5)编写类Salary的映射文件:Salary.hbm.xml
ContractedBlock.gifExpandedBlockStart.gifSalary.hbm.xml
None.gif<?xml version="1.0" encoding="utf-8" ?>
None.gif
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
None.gif  
<class name="NhibernateSample1.Salary,NhibernateSample1" table="Salary" lazy="false">
None.gif    
<id name="Id" column="Id" unsaved-value="0">
None.gif      
<generator class="native" />
None.gif    
</id>
None.gif    
<property name="Year" column="Year" type="Int32" not-null="true"></property>
None.gif    
<property name="Month"  column="Month"  type="Int32" not-null="true"></property>
None.gif    
<property name="Envy"  column="Envy"  type="Int32" not-null="true"></property>
None.gif    
<property name="Money"  column="Money"  type="Decimal" not-null="true"></property>
None.gif    
<many-to-one name="Employee" column="Uid" not-null="true"></many-to-one>
None.gif  
</class>
None.gif
</hibernate-mapping>
6)编写CRUD
ContractedBlock.gifExpandedBlockStart.gifUserSalaryFixure.cs
None.gifusing System;
None.gif
using System.Collections.Generic;
None.gif
using System.Text;
None.gif
using System.Collections;
None.gif
using NHibernate;
None.gif
using NHibernate.Cfg;
None.gif
using NHibernate.Tool.hbm2ddl;
None.gif
None.gif
namespace NhibernateSample1
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    
public  class UserSalaryFixure
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
private ISessionFactory _sessions; 
InBlock.gif        
public void Configure()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Configuration cfg 
= GetConfiguration();      
InBlock.gif            _sessions 
= cfg.BuildSessionFactory();
ExpandedSubBlockEnd.gif        }

InBlock.gif        Configuration GetConfiguration()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
string cfgPath = @"E:\my project\nhibernate study\simle 1\NHibernateStudy1\NhibernateSample1\hibernate.cfg.xml";
InBlock.gif            Configuration cfg 
= new Configuration().Configure(cfgPath);
InBlock.gif            
return cfg;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public void ExportTables()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Configuration cfg 
= GetConfiguration();           
InBlock.gif            
new SchemaExport(cfg).Create(truetrue);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public User CreateUser(String name,string pwd)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            User u 
= new User();
InBlock.gif            u.Name 
= name;
InBlock.gif            u.Pwd 
= pwd;
InBlock.gif            u.SalaryList 
= new ArrayList();
InBlock.gif
InBlock.gif            ISession session 
= _sessions.OpenSession();
InBlock.gif
InBlock.gif            ITransaction tx 
= null;
InBlock.gif
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                tx 
= session.BeginTransaction();
InBlock.gif                session.Save(u);
InBlock.gif                tx.Commit();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (HibernateException e)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (tx != null) tx.Rollback();
InBlock.gif                
throw e;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                session.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
return u;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public Salary CreateSalary(User u, int year,int month,int envy,decimal money)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Salary item 
= new Salary();
InBlock.gif            item.Year 
= year;
InBlock.gif            item.Money 
= money;
InBlock.gif            item.Envy 
= envy;
InBlock.gif            item.Month 
= month;
InBlock.gif            item.Employee 
= u;
InBlock.gif            u.SalaryList.Add(item);
InBlock.gif            ISession session 
= _sessions.OpenSession();
InBlock.gif            ITransaction tx 
= null;
InBlock.gif
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                tx 
= session.BeginTransaction();
InBlock.gif                session.Update(u);
InBlock.gif                tx.Commit();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (HibernateException e)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (tx != null) tx.Rollback();
InBlock.gif                
throw e;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                session.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return item;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public Salary CreateSalary(int uid,int year, int month, int envy, decimal money)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Salary item 
= new Salary();
InBlock.gif            item.Year 
= year;
InBlock.gif            item.Money 
= money;
InBlock.gif            item.Envy 
= envy;
InBlock.gif            item.Month 
= month;
InBlock.gif            
InBlock.gif            ISession session 
= _sessions.OpenSession();
InBlock.gif            ITransaction tx 
= null;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                tx 
= session.BeginTransaction();
InBlock.gif                User u 
= (User)session.Load(typeof(User), uid);
InBlock.gif                item.Employee 
= u;
InBlock.gif                u.SalaryList.Add(item);
InBlock.gif                tx.Commit();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (HibernateException e)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (tx != null) tx.Rollback();
InBlock.gif                
throw e;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                session.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return item;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public Salary GetSalary(int salaryID)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ISession session 
= _sessions.OpenSession();
InBlock.gif            ITransaction tx 
= null;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                tx 
= session.BeginTransaction();
InBlock.gif                Salary item 
= (Salary)session.Load(typeof(Salary),
InBlock.gif                    salaryID);               
InBlock.gif                tx.Commit();
InBlock.gif                
return item;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (HibernateException e)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (tx != null) tx.Rollback();
InBlock.gif                
return null;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                session.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return null;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public User GetUser(int uid)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ISession session 
= _sessions.OpenSession();
InBlock.gif            ITransaction tx 
= null;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                tx 
= session.BeginTransaction();
InBlock.gif                User item 
= (User)session.Load(typeof(User),
InBlock.gif                    uid);
InBlock.gif                tx.Commit();
InBlock.gif                
return item;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (HibernateException e)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (tx != null) tx.Rollback();
InBlock.gif                
return null;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                session.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return null;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public void UpdateSalary(int salaryID, decimal money)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ISession session 
= _sessions.OpenSession();
InBlock.gif            ITransaction tx 
= null;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                tx 
= session.BeginTransaction();
InBlock.gif                Salary item 
= (Salary)session.Load(typeof(Salary),
InBlock.gif                    salaryID);
InBlock.gif                item.Money 
= money;
InBlock.gif                tx.Commit();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (HibernateException e)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (tx != null) tx.Rollback();
InBlock.gif                
throw e;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                session.Close();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public void Delete(int uid)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ISession session 
= _sessions.OpenSession();
InBlock.gif            ITransaction tx 
= null;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                tx 
= session.BeginTransaction();
InBlock.gif                Salary item 
= session.Load(typeof(Salary), uid) as Salary; ;
InBlock.gif                session.Delete(item);
InBlock.gif                tx.Commit();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (HibernateException e)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (tx != null) tx.Rollback();
InBlock.gif                
throw e;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                session.Close();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
7) 编写单元测试类:UnitTest1.cs
ContractedBlock.gifExpandedBlockStart.gifUnitTest1.cs
None.gifusing System;
None.gif
using System.Text;
None.gif
using System.Collections.Generic;
None.gif
using Microsoft.VisualStudio.TestTools.UnitTesting;
None.gif
using NhibernateSample1;
None.gif
None.gif
namespace TestProject1
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// UnitTest1 的摘要说明
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    [TestClass]
InBlock.gif    
public class UnitTest1
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
public UnitTest1()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// TODO: 在此处添加构造函数逻辑
InBlock.gif            
//
ExpandedSubBlockEnd.gif
        }

InBlock.gif        NhibernateSample1.UserSalaryFixure usf 
= new UserSalaryFixure();
ContractedSubBlock.gifExpandedSubBlockStart.gif        
其他测试属性#region 其他测试属性
InBlock.gif        
//
InBlock.gif        
// 您可以在编写测试时使用下列其他属性:
InBlock.gif        
//
InBlock.gif        
// 在运行类中的第一个测试之前使用 ClassInitialize 运行代码
InBlock.gif        
// [ClassInitialize()]
InBlock.gif        
// public static void MyClassInitialize(TestContext testContext) { }
InBlock.gif        
//
InBlock.gif        
// 在类中的所有测试都已运行之后使用 ClassCleanup 运行代码
InBlock.gif        
// [ClassCleanup()]
InBlock.gif        
// public static void MyClassCleanup() { }
InBlock.gif        
//
InBlock.gif        
// 在运行每个测试之前使用 TestInitialize 运行代码 
InBlock.gif        
// [TestInitialize()]
InBlock.gif        
// public void MyTestInitialize() { }
InBlock.gif        
//
InBlock.gif        
// 在运行每个测试之后使用 TestCleanup 运行代码
InBlock.gif        
// [TestCleanup()]
InBlock.gif        
// public void MyTestCleanup() { }
InBlock.gif        
//
ExpandedSubBlockEnd.gif
        #endregion

InBlock.gif
InBlock.gif        [TestMethod]
InBlock.gif        
public void Test1()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            usf.Configure();
InBlock.gif            usf.ExportTables();
InBlock.gif            User u 
= usf.CreateUser(Guid.NewGuid().ToString(), "ds");
InBlock.gif            Assert.IsTrue(u.Id
>0);
InBlock.gif            Salary s 
= usf.CreateSalary(u, 200731, (decimal)8000.00);
InBlock.gif            Assert.IsTrue(s.Id 
> 0);
InBlock.gif            Salary s1 
= usf.CreateSalary(u.Id, 200731, (decimal)7500);
InBlock.gif            Assert.IsTrue(s1.Id
>0);
InBlock.gif            usf.UpdateSalary(s1.Id, (
decimal)6000);
InBlock.gif            s1 
= usf.GetSalary(s1.Id);
InBlock.gif            Assert.IsTrue(s1.Money 
== (decimal)6000);
InBlock.gif            usf.Delete(s1.Id);
InBlock.gif            s1 
= usf.GetSalary(s1.Id);
InBlock.gif            Assert.IsNull(s1);
InBlock.gif            User u1 
= usf.GetUser(1);
InBlock.gif            Assert.IsTrue(u1.SalaryList.Count
>0);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
加载测试元数据,直到Test()通过。
总结:通过进一步学习nhiberate,发现ORM框架真是非常强大。今天先到这里。明天继续。
项目文件:/Files/jillzhang/simple2.rar

转载于:https://www.cnblogs.com/erichzhou/archive/2007/03/29/692949.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/411952.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[vue] 你了解什么是函数式组件吗?

[vue] 你了解什么是函数式组件吗&#xff1f; 函数式组件&#xff1a;需要提供一个render方法&#xff0c; 接受一个参数&#xff08;createElement函数&#xff09;&#xff0c; 方法内根据业务逻辑&#xff0c;通过createElement创建vnodes&#xff0c;最后return vnodescre…

列表元素的几种统计方法总结(嵌套列表)

&#xff08;1&#xff09;列表中的count方法(速度慢) #嵌套列表类型的统计 l [[1,2,3,4,5],[1,2,3,4,5],[5,6,7,8,9]] dictionary {} s set(l) for i in s:dict[i] l.count(i)&#xff08;2&#xff09;字典&#xff08;速度慢&#xff09; l [[1,2,3,4,5],[1,2,3,4,5],[5…

SQL Server数据库优化方案

SQL Server数据库优化方案 查询速度慢的原因很多&#xff0c;常见如下几种&#xff1a;1、没有索引或者没有用到索引(这是查询慢最常见的问题&#xff0c;是程序设计的缺陷)2、I/O吞吐量小&#xff0c;形成了瓶颈效应。3、没有创建计算列导致查询不优化。4、内存不足5、网络速度…

[vue] vue的:class和:style有几种表示方式?

[vue] vue的:class和:style有几种表示方式&#xff1f; :class 绑定变量 绑定对象 绑定一个数组 绑定三元表达式 :style 绑定变量 绑定对象 绑定函数返回值 绑定三元表达式个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷…

关于如何清除某个特定网站的缓存---基于Chrome浏览器

1、清除浏览器缓存 直接在浏览器设置里面清除浏览器的缓存会清除所有网站的缓存信息&#xff0c;这在某些时候是非常不方便的&#xff0c;毕竟不只有测试网站&#xff0c;还会有一些我们不想清除的信息也会被清除掉&#xff1b; 2、通过F12功能去清除浏览器缓存 转载于:https:/…

php中for循环流程图,PHP for循环

PHP for循环可以用来遍历一组指定的次数的代码。如果迭代次数已知&#xff0c;则应优先考虑使用for循环&#xff0c;否则使用while循环。for循环的语法for(initialization; condition; increment/decrement){ //code to be executed }for循环流程图示例代码-<?php for($n1;…

山西DotNet俱乐部网站改版成功

山西DotNet俱乐部改版成功网址为:http://www.dotnet.sx.cn或http://www.xy8.cn欢迎大家光临! 转载于:https://www.cnblogs.com/axzxs2001/archive/2007/04/05/700983.html

[vue] vue的is这个特性你有用过吗?主要用在哪些方面?

[vue] vue的is这个特性你有用过吗&#xff1f;主要用在哪些方面&#xff1f; vue中is的属性引入是为了解决dom结构中对放入html的元素有限制的问题<ul><li ismy-component></li> </ul>个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放…

Spring中AOP切面编程学习笔记

注解方式实现aop我们主要分为如下几个步骤&#xff1a;  1.在切面类&#xff08;为切点服务的类&#xff09;前用Aspect注释修饰&#xff0c;声明为一个切面类。  2.用Pointcut注释声明一个切点&#xff0c;目的是为了告诉切面&#xff0c;谁是它的服务对象。&#xff08;此…

Good Web

Good Web http://www.jxue.com/job/resume/ Englishhttp://www.jxue.com/zt/06zt/resume/http://www.cnrencai.com/ Jobposted on 2007-04-10 00:18 Steveson 阅读(...) 评论(...) 编辑 收藏 转载于:https://www.cnblogs.com/Steveson/archive/2007/04/10/706450.h…

asp.net 生命周期中的时间流程

一、初始化 当页面被提交请求第一个方法永远是构造函数。您可以在构造函数里面初始一些自定义属性或对象&#xff0c;不过这时候因为页面还没有被完全初始化所以多少会有些限制。特别地&#xff0c;您需要使用HttpContext对象。当前可以使用的对象包括QueryString, Form以及Coo…

[vue] 怎么配置使vue2.0+支持TypeScript写法?

[vue] 怎么配置使vue2.0支持TypeScript写法&#xff1f; 配置ts-loader&#xff0c;tsconfig增加类型扩展&#xff0c;让ts识别vue文件vue文件中script里面换成ts写法&#xff0c; 需要增加几个ts扩展的package&#xff0c; 比如vue-property-decorator个人简介 我是歌谣&…

PHP迸发,PHP 开发 「十宗罪」

前言本文翻译自 10 Things Not To Do In PHP 7。全文列出了十条我们在 PHP7 开发中应注意避免的 反模式&#xff0c;觉得很有参考意义故翻译成中文供大家学习借鉴。1. 不要使用 mysql_ 函数在 PHP7 中&#xff0c;mysql_ 系列函数已经完全从核心代码中移除&#xff0c;你应该用…

元组、字典、集合的常用方法

一、元组类型 1、定义 t1 () print(t1, type(t1)) # 参数为for可以循环的对象(可迭代对象) t2 tuple("123") print(t2, type(t2)) t3 tuple([1, 2, 3]) print(t3, type(t3)) t4 tuple((7, 8, 9)) print(t4, type(t4)) # 思考:如何定义一个只有一个值的元组 # &qu…

(转)看盘ABC:看盘七大指标

(转&#xff09;看盘ABC&#xff1a;看盘七大指标 投资大师巴菲特说过一句话&#xff1a;投资是一场马拉松赛&#xff0c;获得冠军的前提是要跑完全程。在这场马拉松赛中&#xff0c;您能跑完全程吗&#xff1f;以往无数股民的经历表明&#xff0c;中途惨败出局者不计其数。为…

[vue] 说说组件的命名规范

[vue] 说说组件的命名规范 定义组件名有两种方式&#xff1a; 1.kebab-case&#xff08;短横线分隔命名&#xff09;&#xff0c;引用时必须也采用kebab-case&#xff1b; 2.PascalCase&#xff08;首字母大写命名&#xff09;&#xff0c;引用时既可以采用PascalCase也可以使…

php梯度区间计算,快速计算梯度的魔法--反向传播算法

2.1 计算梯度的数值方法第一次实验我留的一个课后作业里问你是否能够想出一个求解梯度的办法&#xff0c;其实不难想到一种简单的办法就是使用“数值法”计算梯度。办法很简单&#xff0c;就是对于损失函数中的一个初始取值为a0的参数a,先计算当前的损失函数值J0,再保持其他参数…

SpringCloud的学习记录(1)

最近一段时间重新学习一边SpringCloud&#xff0c;这里简单记录一下。 我用的是IntelliJ IDEA开发工具, SpringBoot的版本是2.1.3.RELEASE。 1. 构建Maven项目 整个的SpringCloud的项目是在Maven项目中的&#xff0c;这个Maven只做容纳其他项目使用, 比如后面Fegin/Config/Zipk…

[转]URLRewriter使用通配符

网上有很多写这个组件使用的文章&#xff0c;如何使用我就不细述了&#xff0c;有关在 ASP.NET 中执行 URL 重写的文章请看下面链接:http://www.microsoft.com/china/msdn/library/webservices/asp.net/URLRewriting.mspx?mfrtrue 我这里要说的是其中几个很容易被忽视的小细节…

[vue] 在vue中使用this应该注意哪些问题?

[vue] 在vue中使用this应该注意哪些问题&#xff1f; vue中使用匿名函数&#xff0c;会出现this指针改变。 解决方法 1.使用箭头函数 2.定义变量绑定this至vue对象个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷。欢迎大…