C# XML反序列化与序列化举例:XmlSerializer
- using System;
- using System.IO;
- using System.Xml.Serialization;
- namespace XStream
- {
- /// <summary>
- /// <remarks>Xml序列化与反序列化</remarks>
- /// <creator>zhangdapeng</creator>
- /// </summary>
- public class XmlSerializeUtil
- {
- #region 反序列化
- /// <summary>
- /// 反序列化
- /// </summary>
- /// <param name="type">类型</param>
- /// <param name="xml">XML字符串</param>
- /// <returns></returns>
- public static object Deserialize(Type type, string xml)
- {
- using (StringReader sr = new StringReader(xml))
- {
- XmlSerializer xmldes = new XmlSerializer(type);
- return xmldes.Deserialize(sr);
- }
- }
- /// <summary>
- /// 反序列化
- /// </summary>
- /// <param name="type"></param>
- /// <param name="xml"></param>
- /// <returns></returns>
- public static object Deserialize(Type type, Stream stream)
- {
- XmlSerializer xmldes = new XmlSerializer(type);
- return xmldes.Deserialize(stream);
- }
- #endregion
- #region 序列化
- /// <summary>
- /// 序列化
- /// </summary>
- /// <param name="type">类型</param>
- /// <param name="obj">对象</param>
- /// <returns></returns>
- public static string Serializer(Type type, object obj)
- {
- MemoryStream Stream = new MemoryStream();
- XmlSerializer xml = new XmlSerializer(type);
- //序列化对象
- xml.Serialize(Stream, obj);
- Stream.Position = 0;
- StreamReader sr = new StreamReader(Stream);
- string str = sr.ReadToEnd();
- sr.Dispose();
- Stream.Dispose();
- return str;
- }
- #endregion
- }
- }
using System;
using System.IO;
using System.Xml.Serialization; namespace XStream
{
/// <summary>
/// <remarks>Xml序列化与反序列化</remarks>
/// <creator>zhangdapeng</creator>
/// </summary>
public class XmlSerializeUtil
{
#region 反序列化
/// <summary>
/// 反序列化
/// </summary>
/// <param name="type">类型</param>
/// <param name="xml">XML字符串</param>
/// <returns></returns>
public static object Deserialize(Type type, string xml)
{
using (StringReader sr = new StringReader(xml))
{
XmlSerializer xmldes = new XmlSerializer(type);
return xmldes.Deserialize(sr);
}
}
/// <summary>
/// 反序列化
/// </summary>
/// <param name="type"></param>
/// <param name="xml"></param>
/// <returns></returns>
public static object Deserialize(Type type, Stream stream)
{
XmlSerializer xmldes = new XmlSerializer(type);
return xmldes.Deserialize(stream);
}
#endregion #region 序列化
/// <summary>
/// 序列化
/// </summary>
/// <param name="type">类型</param>
/// <param name="obj">对象</param>
/// <returns></returns>
public static string Serializer(Type type, object obj)
{
MemoryStream Stream = new MemoryStream();
XmlSerializer xml = new XmlSerializer(type);
//序列化对象
xml.Serialize(Stream, obj);
Stream.Position = 0;
StreamReader sr = new StreamReader(Stream);
string str = sr.ReadToEnd(); sr.Dispose();
Stream.Dispose(); return str;
} #endregion
}
}
这个类是个实体类
- using System.Collections.Generic;
- using System.Xml.Serialization;
- namespace XStream
- {
- /// <summary>
- /// <creator>zhangdapeng</creator>
- /// </summary>
- [XmlRoot("skycenter")]
- public class AdsbEntity
- {
- private string _type;
- [XmlAttribute("type")]
- public string Type
- {
- get { return _type; }
- set { _type = value; }
- }
- private string _source;
- [XmlAttribute("source")]
- public string Source
- {
- get { return _source; }
- set { _source = value; }
- }
- private string _reality;
- [XmlAttribute("reality")]
- public string Reality
- {
- get { return _reality; }
- set { _reality = value; }
- }
- private string _rcvTime;
- [XmlAttribute("rcvTime")]
- public string RcvTime
- {
- get { return _rcvTime; }
- set { _rcvTime = value; }
- }
- private Head _head;
- //属性的定义
- [XmlElement("head")]
- public Head Head
- {
- set //设定属性
- {
- _head = value;
- }
- get //从属性获取值
- {
- return _head;
- }
- }
- private List<Unit> data = new List<Unit>();
- [XmlArray("data")]
- [XmlArrayItem("unit")]
- public List<Unit> Unit
- {
- get { return data; }
- }
- public void addUnit(Unit e)
- {
- data.Add(e);
- }
- private string _msg;
- public string msg
- {
- get { return _msg; }
- set { _msg = value; }
- }
- }
- }
using System.Collections.Generic;
using System.Xml.Serialization; namespace XStream
{
/// <summary>
/// <creator>zhangdapeng</creator>
/// </summary>
[XmlRoot("skycenter")]
public class AdsbEntity
{
private string _type; [XmlAttribute("type")]
public string Type
{
get { return _type; }
set { _type = value; }
}
private string _source;
[XmlAttribute("source")]
public string Source
{
get { return _source; }
set { _source = value; }
}
private string _reality;
[XmlAttribute("reality")]
public string Reality
{
get { return _reality; }
set { _reality = value; }
}
private string _rcvTime;
[XmlAttribute("rcvTime")]
public string RcvTime
{
get { return _rcvTime; }
set { _rcvTime = value; }
}
private Head _head;
//属性的定义
[XmlElement("head")]
public Head Head
{
set //设定属性
{
_head = value;
}
get //从属性获取值
{
return _head;
}
} private List<Unit> data = new List<Unit>(); [XmlArray("data")]
[XmlArrayItem("unit")]
public List<Unit> Unit
{
get { return data; }
}
public void addUnit(Unit e)
{
data.Add(e);
} private string _msg; public string msg
{
get { return _msg; }
set { _msg = value; }
} }
}
- using System.Xml.Serialization;
- namespace XStream
- {
- /// <summary>
- /// <creator>zhangdapeng</creator>
- /// </summary>
- public class Head
- {
- private string _datagramId;
- [XmlElement("datagramId")]
- public string DatagramId
- {
- set
- {
- _datagramId = value;
- }
- get
- {
- return _datagramId;
- }
- }
- private string _priority;
- [XmlElement("priority")]
- public string Priority
- {
- get { return _priority; }
- set { _priority = value; }
- }
- private string _an;
- [XmlElement("an")]
- public string An
- {
- get { return _an; }
- set { _an = value; }
- }
- private string _fi;
- [XmlElement("fi")]
- public string Fi
- {
- get { return _fi; }
- set { _fi = value; }
- }
- private string _rcvAddress;
- [XmlElement("rcvAddress")]
- public string RcvAddress
- {
- get { return _rcvAddress; }
- set { _rcvAddress = value; }
- }
- private string _sndAddress;
- [XmlElement("sndAddress")]
- public string SndAddress
- {
- get { return _sndAddress; }
- set { _sndAddress = value; }
- }
- private string _bepTime;
- [XmlElement("bepTime")]
- public string BepTime
- {
- get { return _bepTime; }
- set { _bepTime = value; }
- }
- private string _smi;
- [XmlElement("smi")]
- public string Smi
- {
- get { return _smi; }
- set { _smi = value; }
- }
- private string _dsp;
- [XmlElement("dsp")]
- public string Dsp
- {
- get { return _dsp; }
- set { _dsp = value; }
- }
- private string _rgs;
- [XmlElement("rgs")]
- public string Rgs
- {
- get { return _rgs; }
- set { _rgs = value; }
- }
- private string _msn;
- [XmlElement("msn")]
- public string Msn
- {
- get { return _msn; }
- set { _msn = value; }
- }
- private string _datagramType;
- [XmlElement("datagramType")]
- public string DatagramType
- {
- get { return _datagramType; }
- set { _datagramType = value; }
- }
- private string _icao24;
- [XmlElement("icao24")]
- public string Icao24
- {
- get { return _icao24; }
- set { _icao24 = value; }
- }
- private string _callcode;
- [XmlElement("callcode")]
- public string Callcode
- {
- get { return _callcode; }
- set { _callcode = value; }
- }
- }
- }
using System.Xml.Serialization; namespace XStream
{
/// <summary>
/// <creator>zhangdapeng</creator>
/// </summary>
public class Head
{ private string _datagramId;
[XmlElement("datagramId")]
public string DatagramId
{
set
{
_datagramId = value;
}
get
{
return _datagramId;
}
} private string _priority;
[XmlElement("priority")]
public string Priority
{
get { return _priority; }
set { _priority = value; }
} private string _an;
[XmlElement("an")]
public string An
{
get { return _an; }
set { _an = value; }
} private string _fi;
[XmlElement("fi")]
public string Fi
{
get { return _fi; }
set { _fi = value; }
} private string _rcvAddress;
[XmlElement("rcvAddress")]
public string RcvAddress
{
get { return _rcvAddress; }
set { _rcvAddress = value; }
} private string _sndAddress;
[XmlElement("sndAddress")]
public string SndAddress
{
get { return _sndAddress; }
set { _sndAddress = value; }
} private string _bepTime;
[XmlElement("bepTime")]
public string BepTime
{
get { return _bepTime; }
set { _bepTime = value; }
} private string _smi;
[XmlElement("smi")]
public string Smi
{
get { return _smi; }
set { _smi = value; }
} private string _dsp;
[XmlElement("dsp")]
public string Dsp
{
get { return _dsp; }
set { _dsp = value; }
} private string _rgs;
[XmlElement("rgs")]
public string Rgs
{
get { return _rgs; }
set { _rgs = value; }
} private string _msn;
[XmlElement("msn")]
public string Msn
{
get { return _msn; }
set { _msn = value; }
} private string _datagramType;
[XmlElement("datagramType")]
public string DatagramType
{
get { return _datagramType; }
set { _datagramType = value; }
} private string _icao24;
[XmlElement("icao24")]
public string Icao24
{
get { return _icao24; }
set { _icao24 = value; }
} private string _callcode;
[XmlElement("callcode")]
public string Callcode
{
get { return _callcode; }
set { _callcode = value; }
} }
}
- using System.Xml.Serialization;
- namespace XStream
- {
- /// <summary>
- /// <creator>zhangdapeng</creator>
- /// </summary>
- [XmlRootAttribute("unit")]
- public class Unit
- {
- private string _name;
- [XmlAttribute("name")]
- public string Name
- {
- get { return _name; }
- set { _name = value; }
- }
- private string _name_value;
- [XmlTextAttribute]
- public string Name_value
- {
- get { return _name_value; }
- set { _name_value = value; }
- }
- }
- }
using System.Xml.Serialization; namespace XStream
{
/// <summary>
/// <creator>zhangdapeng</creator>
/// </summary>
[XmlRootAttribute("unit")]
public class Unit
{
private string _name; [XmlAttribute("name")]
public string Name
{
get { return _name; }
set { _name = value; }
} private string _name_value; [XmlTextAttribute]
public string Name_value
{
get { return _name_value; }
set { _name_value = value; }
}
}
}
主类:
- using System;
- using System.Xml;
- namespace XStream
- {
- /// <summary>
- /// <creator>zhangdapeng</creator>
- /// </summary>
- class Program
- {
- static void Main(string[] args)
- {
- string path = System.AppDomain.CurrentDomain.BaseDirectory;
- XmlDocument xmlDoc = new XmlDocument();
- xmlDoc.Load(@path+"../../test.xml");
- Console.WriteLine(xmlDoc.OuterXml);
- AdsbEntity ad = XmlSerializeUtil.Deserialize(typeof(AdsbEntity), xmlDoc.OuterXml) as AdsbEntity;
- Console.WriteLine(ad.Head.DatagramId);
- Console.WriteLine(ad.Head.Fi);
- string xml = XmlSerializeUtil.Serializer(typeof(AdsbEntity), ad);
- Console.WriteLine(xml);
- Console.ReadKey();
- }
- }
- }
using System;
using System.Xml; namespace XStream
{
/// <summary>
/// <creator>zhangdapeng</creator>
/// </summary>
class Program
{
static void Main(string[] args)
{ string path = System.AppDomain.CurrentDomain.BaseDirectory;
XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(@path+"../../test.xml");
Console.WriteLine(xmlDoc.OuterXml); AdsbEntity ad = XmlSerializeUtil.Deserialize(typeof(AdsbEntity), xmlDoc.OuterXml) as AdsbEntity;
Console.WriteLine(ad.Head.DatagramId);
Console.WriteLine(ad.Head.Fi); string xml = XmlSerializeUtil.Serializer(typeof(AdsbEntity), ad);
Console.WriteLine(xml); Console.ReadKey(); }
}
}
原始输入:test.xml文件
- <?xml version="1.0" encoding="UTF-8"?>
- <skycenter type="ADSBResult" source="ADSB" reality="T" rcvTime="2014-02-25 07:23:31">
- <head>
- <!--报文id 注:空节点-->
- <datagramId>127</datagramId>
- <!--priority 注:空节点-->
- <priority>18</priority>
- <!--机尾号-->
- <an>B-5662</an>
- <!--航班号-->
- <fi>HU7782</fi>
- <!--接收地址 注:空节点-->
- <rcvAddress>1</rcvAddress>
- <!--发送地址 注:空节点-->
- <sndAddress>1</sndAddress>
- <!--bepTime 注:空节点-->
- <bepTime>1</bepTime>
- <!--SMI 注:空节点-->
- <smi>1</smi>
- <!--DSP服务商 注:空节点-->
- <dsp>1</dsp>
- <!--地面站-->
- <rgs>PEK</rgs>
- <!--流水号 注:空节点-->
- <msn>1</msn>
- <!--报文类型,都是POS 注:空节点-->
- <datagramType>1</datagramType>
- <!--ICAO24位地址码-->
- <icao24>7808a3</icao24>
- <!--呼号-->
- <callcode>CHH7782</callcode>
- </head>
- <data>
- <!--纬度 看前面的字母“N”或“S”,格式“DDMMSS.SS”-->
- <unit name="LAT">N31414709</unit>
- <!--经度 看前面的字母“E”或“W”,格式“DDDMMSS.SS”-->
- <unit name="LON">E118463546</unit>
- <!--气压高度,单位是米-->
- <unit name="ALT">396.24</unit>
- <!--计算空速 单位海里每小时-->
- <unit name="CAS">127.00</unit>
- <!--航向 正北是0°,顺时针,0到360°-->
- <unit name="VEC">58.18</unit>
- <!--收到报文的UTC时间 hh24mmss-->
- <unit name="UTC">072331</unit>
- </data>
- <msg>11</msg>
- </skycenter>
<?xml version="1.0" encoding="UTF-8"?>
<skycenter type="ADSBResult" source="ADSB" reality="T" rcvTime="2014-02-25 07:23:31">
<head>
<!--报文id 注:空节点-->
<datagramId>127</datagramId>
<!--priority 注:空节点-->
<priority>18</priority>
<!--机尾号-->
<an>B-5662</an>
<!--航班号-->
<fi>HU7782</fi>
<!--接收地址 注:空节点-->
<rcvAddress>1</rcvAddress>
<!--发送地址 注:空节点-->
<sndAddress>1</sndAddress>
<!--bepTime 注:空节点-->
<bepTime>1</bepTime>
<!--SMI 注:空节点-->
<smi>1</smi>
<!--DSP服务商 注:空节点-->
<dsp>1</dsp>
<!--地面站-->
<rgs>PEK</rgs>
<!--流水号 注:空节点-->
<msn>1</msn>
<!--报文类型,都是POS 注:空节点-->
<datagramType>1</datagramType>
<!--ICAO24位地址码-->
<icao24>7808a3</icao24>
<!--呼号-->
<callcode>CHH7782</callcode>
</head>
<data>
<!--纬度 看前面的字母“N”或“S”,格式“DDMMSS.SS”-->
<unit name="LAT">N31414709</unit>
<!--经度 看前面的字母“E”或“W”,格式“DDDMMSS.SS”-->
<unit name="LON">E118463546</unit>
<!--气压高度,单位是米-->
<unit name="ALT">396.24</unit>
<!--计算空速 单位海里每小时-->
<unit name="CAS">127.00</unit>
<!--航向 正北是0°,顺时针,0到360°-->
<unit name="VEC">58.18</unit>
<!--收到报文的UTC时间 hh24mmss-->
<unit name="UTC">072331</unit>
</data>
<msg>11</msg>
</skycenter>
结果:
- </pre><pre class="html" name="code"><?xml version="1.0" encoding="UTF-8"?>
- <skycenter type="ADSBResult" source="ADSB" reality="T" rcvTime="2014-02-25 07:23:31">
- <head>
- <!--报文id 注:空节点-->
- <datagramId>127</datagramId>
- <!--priority 注:空节点-->
- <priority>18</priority>
- <!--机尾号-->
- <an>B-5662</an>
- <!--航班号-->
- <fi>HU7782</fi>
- <!--接收地址 注:空节点-->
- <rcvAddress>1</rcvAddress>
- <!--发送地址 注:空节点-->
- <sndAddress>1</sndAddress>
- <!--bepTime 注:空节点-->
- <bepTime>1</bepTime>
- <!--SMI 注:空节点-->
- <smi>1</smi>
- <!--DSP服务商 注:空节点-->
- <dsp>1</dsp>
- <!--地面站-->
- <rgs>PEK</rgs>
- <!--流水号 注:空节点-->
- <msn>1</msn>
- <!--报文类型,都是POS 注:空节点-->
- <datagramType>1</datagramType>
- <!--ICAO24位地址码-->
- <icao24>7808a3</icao24>
- <!--呼号-->
- <callcode>CHH7782</callcode>
- </head>
- <data>
- <!--纬度 看前面的字母“N”或“S”,格式“DDMMSS.SS”-->
- <unit name="LAT">N31414709</unit>
- <!--经度 看前面的字母“E”或“W”,格式“DDDMMSS.SS”-->
- <unit name="LON">E118463546</unit>
- <!--气压高度,单位是米-->
- <unit name="ALT">396.24</unit>
- <!--计算空速 单位海里每小时-->
- <unit name="CAS">127.00</unit>
- <!--航向 正北是0°,顺时针,0到360°-->
- <unit name="VEC">58.18</unit>
- <!--收到报文的UTC时间 hh24mmss-->
- <unit name="UTC">072331</unit>
- </data>
- <msg>11</msg>
- </skycenter>
- 127
- HU7782
- <?xml version="1.0"?>
- <skycenter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http
- ://www.w3.org/2001/XMLSchema" type="ADSBResult" source="ADSB" reality="T" rcvTim
- e="2014-02-25 07:23:31">
- <head>
- <datagramId>127</datagramId>
- <priority>18</priority>
- <an>B-5662</an>
- <fi>HU7782</fi>
- <rcvAddress>1</rcvAddress>
- <sndAddress>1</sndAddress>
- <bepTime>1</bepTime>
- <smi>1</smi>
- <dsp>1</dsp>
- <rgs>PEK</rgs>
- <msn>1</msn>
- <datagramType>1</datagramType>
- <icao24>7808a3</icao24>
- <callcode>CHH7782</callcode>
- </head>
- <data>
- <unit name="LAT">N31414709</unit>
- <unit name="LON">E118463546</unit>
- <unit name="ALT">396.24</unit>
- <unit name="CAS">127.00</unit>
- <unit name="VEC">58.18</unit>
- <unit name="UTC">072331</unit>
- </data>
- <msg>11</msg>
- </skycenter>
</pre><pre class="html" name="code"><?xml version="1.0" encoding="UTF-8"?>
<skycenter type="ADSBResult" source="ADSB" reality="T" rcvTime="2014-02-25 07:23:31">
<head>
<!--报文id 注:空节点-->
<datagramId>127</datagramId>
<!--priority 注:空节点-->
<priority>18</priority>
<!--机尾号-->
<an>B-5662</an>
<!--航班号-->
<fi>HU7782</fi>
<!--接收地址 注:空节点-->
<rcvAddress>1</rcvAddress>
<!--发送地址 注:空节点-->
<sndAddress>1</sndAddress>
<!--bepTime 注:空节点-->
<bepTime>1</bepTime>
<!--SMI 注:空节点-->
<smi>1</smi>
<!--DSP服务商 注:空节点-->
<dsp>1</dsp>
<!--地面站-->
<rgs>PEK</rgs>
<!--流水号 注:空节点-->
<msn>1</msn>
<!--报文类型,都是POS 注:空节点-->
<datagramType>1</datagramType>
<!--ICAO24位地址码-->
<icao24>7808a3</icao24>
<!--呼号-->
<callcode>CHH7782</callcode>
</head>
<data>
<!--纬度 看前面的字母“N”或“S”,格式“DDMMSS.SS”-->
<unit name="LAT">N31414709</unit>
<!--经度 看前面的字母“E”或“W”,格式“DDDMMSS.SS”-->
<unit name="LON">E118463546</unit>
<!--气压高度,单位是米-->
<unit name="ALT">396.24</unit>
<!--计算空速 单位海里每小时-->
<unit name="CAS">127.00</unit>
<!--航向 正北是0°,顺时针,0到360°-->
<unit name="VEC">58.18</unit>
<!--收到报文的UTC时间 hh24mmss-->
<unit name="UTC">072331</unit>
</data>
<msg>11</msg>
</skycenter> 127
HU7782
<?xml version="1.0"?>
<skycenter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http
://www.w3.org/2001/XMLSchema" type="ADSBResult" source="ADSB" reality="T" rcvTim
e="2014-02-25 07:23:31">
<head>
<datagramId>127</datagramId>
<priority>18</priority>
<an>B-5662</an>
<fi>HU7782</fi>
<rcvAddress>1</rcvAddress>
<sndAddress>1</sndAddress>
<bepTime>1</bepTime>
<smi>1</smi>
<dsp>1</dsp>
<rgs>PEK</rgs>
<msn>1</msn>
<datagramType>1</datagramType>
<icao24>7808a3</icao24>
<callcode>CHH7782</callcode>
</head>
<data>
<unit name="LAT">N31414709</unit>
<unit name="LON">E118463546</unit>
<unit name="ALT">396.24</unit>
<unit name="CAS">127.00</unit>
<unit name="VEC">58.18</unit>
<unit name="UTC">072331</unit>
</data>
<msg>11</msg>
</skycenter>
出处:http://blog.csdn.net/philosophyatmath/article/details/28593153
C# XML反序列化与序列化举例:XmlSerializer的更多相关文章
- C# XML反序列化与序列化举例:XmlSerializer(转)
using System; using System.IO; using System.Xml.Serialization; namespace XStream { /// <summary&g ...
- <经验杂谈>C#/.Net中xml的Serialization序列化与DeSerializetion反序列化
1.先讲概念:.Net Framework提供了对应的System.Xml.Seriazliation.XmlSerializer负责把对象序列化到XML,和从XML中反序列化为对象.Serializ ...
- .NET(C#):觉察XML反序列化中的未知节点
原文 www.cnblogs.com/mgen/archive/2011/12/12/2284554.html 众所周知XML是可以扩展的,XML的元素可以靠名称识别而不是只按照未知识别.在 XML反 ...
- android-pull方式解析xml文件以及XML文件的序列化
android解析XML ---------------------------基础要像磐石 在android平台上可以使用SAX.DOM和自带的Pull解析器解析xml文件,本文主要介绍使用pull ...
- Xml反序列化记录
1.概述 公司项目遇到一个需要对接webservice的,webservice大部分用的都是xml来传输的,这里记录一下xml反序列化遇到的问题 2.xml工具类 xml序列化: public sta ...
- 让Visual Studio 2013为你自动生成XML反序列化的类
Visual Sutdio 2013增加了许多新功能,其中很多都直接提高了对代码编辑的便利性.如: 1. 在代码编辑界面的右侧滚动条上显示不同颜色的标签,让开发人员可以对所编辑文档的修改.查找.定位情 ...
- wp8.1 Study11:APP里文件读写和使用XML和Json序列化
一.文件读写 1.基本操作(使用FileIO API) 这个方法在上一个stduy已经学过,那么贴出来复习下,代码如下: private async void writeTextToLocalStor ...
- 自动生成XML反序列化的类
原文地址:http://www.cnblogs.com/jaxu/p/3632077.html Visual Sutdio 2013增加了许多新功能,其中很多都直接提高了对代码编辑的便利性.如: ...
- XML反序列化遇到数字型节点值为空导致反序列化异常
实体类: [XmlRoot("stream")] public class _30320DuisiFukuanQueryResponseModel : ResponseModelB ...
随机推荐
- 根据GUID获取设备信息
#include <windows.h> #include <setupapi.h> #include <objbase.h> #include <initg ...
- 获取文件的MD5值,比较两个文件是否完全相同
代码: public class MD5Test { public static void main(String[] args) { String s1 = MD5Test.MD5Operation ...
- SpringBoot整合集成redis
Redis安装:https://www.cnblogs.com/zwcry/p/9505949.html 1.pom.xml <project xmlns="http://maven. ...
- 【HackerRank】Pairs
题目链接:Pairs 完全就是Two Sum问题的变形!Two Sum问题是要求数组中和正好等于K的两个数,这个是求数组中两个数的差正好等于K的两个数.总结其实就是“骑驴找马”的问题:即当前遍历ar[ ...
- Python编程-编码、变量、数据类型
一.Python和其他语言对比 C语言最接近机器语言,因此运行效率是最高的,但需要编译. JAVA更适合企业应用. PHP适合WEB页面应用. PYTHON语言更加简洁,丰富的类库,使初学者更易实现应 ...
- JS以指定格式获取当前日期
//获取当前时间,格式YYYY-MM-DD function getNowFormatDate() { var date = new Date(); var seperator1 = "-& ...
- LVS 介绍
LVS 介绍 说明: LVS是Linux Virtual Server的简称 LVS是一个实现负载均衡的开源软件项目 LVS效率要高于Nginx LVS工作在ISO的第4层(传输层) LVS架构有三层 ...
- MySQL数据库基本操作(二)
表结构操作 ( ALTER TABLE) 添加单列: ALTER TABLE tb1_name ADD [COLUNM] col_name column_definition [FIRST|AFTER ...
- centOS安装apache服务器
# yum install httpd 启动 systemctl start httpd 重启 systemctl restart httpd 停止 systemctl stop httpd
- 关于发邮件报错535 Error:authentication failed&553 authentication is required
553 authentication is required:这个错误的意思是你必须需要认证. 也就是说,你连接smtp服务器的时候必须使用密码来连接:下面代码红色那句 代码: @Override p ...