springboot使用mongodb

大家好,我是烤鸭:

这是一篇关于springboot项目中使用mongodb。

环境:

      jdk 1.8

        springboot 1.5.6.RELEASE

        maven 3.5 

1. mongodb在springboot中的配置

    springboot集成这个三方插件就是简单,只需要引入依赖,在properties或者yml中

添加相应的参数配置就好了。

    (1)  引入依赖

         以maven为例:

         其中mongodb两个依赖包:

        <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-mongodb</artifactId><version>1.5.6.RELEASE</version></dependency><dependency><groupId>org.mongodb</groupId><artifactId>mongodb-driver</artifactId><version>3.4.2</version></dependency>

 (2)properties或者yml配置(我这次没用到这个配置,是在工具类代码中直接写的)

            以yml为例:

spring:data:mongodb:host: 127.0.0.1port: 27017username: musicpassword: musicdatabase: music

            这里几个参数就是:

            IP地址,端口号,用户名,密码,数据库。

2.   mongodb的使用

  (1)创建想存到mongo中的实体映射类,继承Document类

                我这里是想存一些歌曲。

                MusicInfo.java:

package com.test.test.test.bean;import org.bson.BsonDocument;
import org.bson.BsonDocumentWrapper;
import org.bson.Document;
import org.bson.codecs.configuration.CodecRegistry;
import org.bson.types.ObjectId;import java.io.Serializable;/*** Created by */
public class MusicInfo extends Document implements Serializable {private Integer returnId;private Integer id;private String mid;private String desc;private String name;private String singerName;private String fileHash;private String hqHash;private String albumId;private String type;   //平台标识private String keyword; //查询关键字/*** 无参构造=*/public MusicInfo() {super();}/*** 全参构造,添加到Map中*/public MusicInfo(Integer returnId, Long id, String mid, String desc, String name, String singerName, String fileHash, String hqHash, String albumId, String type) {super();this.append("returnId", returnId).append("id", id).append("mid", mid).append("desc", desc).append("name", name).append("singerName", singerName).append("fileHash", fileHash).append("albumId", albumId).append("type", type).append("keyword",keyword);}public MusicInfo(String keyword) {super();this.append("keyword", keyword);}/*** 该方法用于collection的update*/public void setUpdate(MusicInfo musicInfo) {this.append("$set", musicInfo);}/*** mongo 中的_id** @return*/public ObjectId get_Id() {return this.getObjectId("_id");}public void set_Id(ObjectId id) {this.append("_id", id);}public Integer getReturnId() {//return returnId;return this.getInteger("returnId");}public void setReturnId(Integer returnId) {//this.returnId = returnId;this.append("returnId", returnId);}public Integer getId() {Integer integer = this.getInteger("id");return integer;//return id;}public void setId(Integer id) {//this.id = id;this.append("id", id);}public String getMid() {return this.getString("mid");//return mid;}public void setMid(String mid) {//this.mid = mid;this.append("mid", mid);}public String getDesc() {return this.getString("desc");// return desc;}public void setDesc(String desc) {//this.desc = desc;this.append("desc", desc);}public String getName() {return this.getString("name");// return name;}public void setName(String name) {this.append("name", name);// this.name = name;}public String getSingerName() {return this.getString("singerName");// return singerName;}public void setSingerName(String singerName) {this.append("singerName", singerName);//this.singerName = singerName;}public String getFileHash() {return this.getString("fileHash");//return fileHash;}public void setFileHash(String fileHash) {this.append("fileHash", fileHash);// this.fileHash = fileHash;}public String getHqHash() {return this.getString("hqHash");//return hqHash;}public void setHqHash(String hqHash) {this.append("hqHash", hqHash);// this.hqHash = hqHash;}public String getAlbumId() {return this.getString("albumId");//return albumId;}public void setAlbumId(String albumId) {this.append("albumId", albumId);// this.albumId = albumId;}public String getType() {return this.getString("type");//return albumId;}public void setType(String type) {this.append("type", type);// this.albumId = albumId;}public String getKeyword() {return this.getString("keyword");//return albumId;}public void setKeyword(String keyword) {this.append("keyword", keyword);// this.albumId = albumId;}public <TDocument> BsonDocument toBsonDocument(Class<TDocument> documentClass, CodecRegistry codecRegistry) {// TODO Auto-generated method stubreturn new BsonDocumentWrapper<MusicInfo>(this, codecRegistry.get(MusicInfo.class));}@Overridepublic String toString() {return "MusicInfo[" +"_id='" + this.get_Id() + '\'' +"albumId='" + this.getAlbumId() + '\'' +", returnId=" + this.getReturnId() +", id=" + this.getId() +", mid='" + this.getMid() + '\'' +", desc='" + this.getDesc() + '\'' +", name='" + this.getName() + '\'' +", singerName='" + this.getSingerName() + '\'' +", fileHash='" + this.getFileHash() + '\'' +", hqHash='" + this.getHqHash() + '\'' +", type='" + this.getType() + '\'' +']';}
}	

(2)  创建歌曲对应操作mongodb的注册类

        实现  CollectibleCodec接口

        MusicInfoCodec.java:

package com.test.test.test.bean;import org.bson.*;
import org.bson.assertions.Assertions;
import org.bson.codecs.*;
import org.bson.codecs.configuration.CodecRegistry;import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;import static java.util.Arrays.asList;
import static org.bson.codecs.configuration.CodecRegistries.fromProviders;/*** Created by .***/
public class MusicInfoCodec implements CollectibleCodec<MusicInfo> {private static final String ID_FIELD_NAME = "_id";private static final CodecRegistry DEFAULT_REGISTRY = fromProviders(asList(new ValueCodecProvider(),new BsonValueCodecProvider(),new DocumentCodecProvider()));private static final BsonTypeClassMap DEFAULT_BSON_TYPE_CLASS_MAP = new BsonTypeClassMap();private final CodecRegistry registry;private final BsonTypeClassMap bsonTypeClassMap;private final IdGenerator idGenerator;private final Transformer valueTransformer;public MusicInfoCodec() {this(DEFAULT_REGISTRY, DEFAULT_BSON_TYPE_CLASS_MAP);}public MusicInfoCodec(final CodecRegistry registry, final BsonTypeClassMap bsonTypeClassMap) {this(registry, bsonTypeClassMap, null);}public MusicInfoCodec(final CodecRegistry registry, final BsonTypeClassMap bsonTypeClassMap, final Transformer valueTransformer) {this.registry = Assertions.notNull("registry", registry);this.bsonTypeClassMap = Assertions.notNull("bsonTypeClassMap", bsonTypeClassMap);this.idGenerator = Assertions.notNull("idGenerator", new ObjectIdGenerator());this.valueTransformer = valueTransformer != null ? valueTransformer : new Transformer() {@Overridepublic Object transform(final Object value) {return value;}};}@Overridepublic boolean documentHasId(final MusicInfo document) {return document.containsKey(ID_FIELD_NAME);}@Overridepublic BsonValue getDocumentId(final MusicInfo document) {if (!documentHasId(document)) {throw new IllegalStateException("The document does not contain an _id");}Object id = document.get(ID_FIELD_NAME);if (id instanceof BsonValue) {return (BsonValue) id;}BsonDocument idHoldingDocument = new BsonDocument();BsonWriter writer = new BsonDocumentWriter(idHoldingDocument);writer.writeStartDocument();writer.writeName(ID_FIELD_NAME);writeValue(writer, EncoderContext.builder().build(), id);writer.writeEndDocument();return idHoldingDocument.get(ID_FIELD_NAME);}@Overridepublic MusicInfo generateIdIfAbsentFromDocument(final MusicInfo document) {if (!documentHasId(document)) {document.put(ID_FIELD_NAME, idGenerator.generate());}return document;}@Overridepublic void encode(final BsonWriter writer, final MusicInfo document, final EncoderContext encoderContext) {writeMap(writer, document, encoderContext);}@Overridepublic MusicInfo decode(final BsonReader reader, final DecoderContext decoderContext) {MusicInfo document = new MusicInfo();reader.readStartDocument();while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) {String fieldName = reader.readName();document.put(fieldName, readValue(reader, decoderContext));}reader.readEndDocument();return document;}@Overridepublic Class<MusicInfo> getEncoderClass() {return MusicInfo.class;}private void beforeFields(final BsonWriter bsonWriter, final EncoderContext encoderContext, final Map<String, Object> document) {if (encoderContext.isEncodingCollectibleDocument() && document.containsKey(ID_FIELD_NAME)) {bsonWriter.writeName(ID_FIELD_NAME);writeValue(bsonWriter, encoderContext, document.get(ID_FIELD_NAME));}}private boolean skipField(final EncoderContext encoderContext, final String key) {return encoderContext.isEncodingCollectibleDocument() && key.equals(ID_FIELD_NAME);}@SuppressWarnings({"unchecked", "rawtypes"})private void writeValue(final BsonWriter writer, final EncoderContext encoderContext, final Object value) {if (value == null) {writer.writeNull();} else if (Iterable.class.isAssignableFrom(value.getClass())) {writeIterable(writer, (Iterable<Object>) value, encoderContext.getChildContext());} else if (Map.class.isAssignableFrom(value.getClass())) {writeMap(writer, (Map<String, Object>) value, encoderContext.getChildContext());} else {Codec codec = registry.get(value.getClass());encoderContext.encodeWithChildContext(codec, writer, value);}}private void writeMap(final BsonWriter writer, final Map<String, Object> map, final EncoderContext encoderContext) {writer.writeStartDocument();beforeFields(writer, encoderContext, map);for (final Map.Entry<String, Object> entry : map.entrySet()) {if (skipField(encoderContext, entry.getKey())) {continue;}writer.writeName(entry.getKey());writeValue(writer, encoderContext, entry.getValue());}writer.writeEndDocument();}private void writeIterable(final BsonWriter writer, final Iterable<Object> list, final EncoderContext encoderContext) {writer.writeStartArray();for (final Object value : list) {writeValue(writer, encoderContext, value);}writer.writeEndArray();}private Object readValue(final BsonReader reader, final DecoderContext decoderContext) {BsonType bsonType = reader.getCurrentBsonType();if (bsonType == BsonType.NULL) {reader.readNull();return null;} else if (bsonType == BsonType.ARRAY) {return readList(reader, decoderContext);} else if (bsonType == BsonType.BINARY) {byte bsonSubType = reader.peekBinarySubType();if (bsonSubType == BsonBinarySubType.UUID_STANDARD.getValue() || bsonSubType == BsonBinarySubType.UUID_LEGACY.getValue()) {return registry.get(UUID.class).decode(reader, decoderContext);}}return valueTransformer.transform(registry.get(bsonTypeClassMap.get(bsonType)).decode(reader, decoderContext));}private List<Object> readList(final BsonReader reader, final DecoderContext decoderContext) {reader.readStartArray();List<Object> list = new ArrayList<Object>();while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) {list.add(readValue(reader, decoderContext));}reader.readEndArray();return list;}}

      (3)  MongoService:

            (用于增删改查,这里只用到了查询和插入方法)

/*** Created by */
@Service
public class MongoService {/*** 数据插入MongoDB(初版)* @param Codec 用户将bson转化为Object的类* @param musicInfos 需要存储的实体集合* @param dbName 选择的db*///insertMongo(KeyEnum.TYPE_XIAMI.getKey(),keyword,resultContent);public  void insertMongo(CollectibleCodec Codec,List<MusicInfo> musicInfos,String dbName){String colName = "songlist";MongoUtil instance = MongoUtil.instance;CodecRegistry registry  = CodecRegistries.fromCodecs(Codec);MongoDatabase database = MongoUtil.instance.getDB(dbName);if(instance.getCollection(dbName, colName) ==null ){instance.createCollection(dbName, colName);}MongoCollection<MusicInfo> music = database.withCodecRegistry(registry).getCollection(colName, MusicInfo.class);musicInfos.forEach(item->{MusicInfo first = music.find(item, MusicInfo.class).first();if(null != first){return;}music.insertOne(item);});}public MongoService() {}/**** @param Codec 用户将bson转化为Object的类* @param musicInfo 封装查询条件的实体* @param dbName 选择的db* @return List<MusicInfo>*/public List<MusicInfo> getSongFromMongo(CollectibleCodec Codec,MusicInfo musicInfo,String dbName){String colName = "songlist";MongoUtil instance = MongoUtil.instance;CodecRegistry registry  = CodecRegistries.fromCodecs(Codec);MongoDatabase database = MongoUtil.instance.getDB(dbName);if(instance.getCollection(dbName, colName) ==null ){instance.createCollection(dbName, colName);}MongoCollection<MusicInfo> music = database.withCodecRegistry(registry).getCollection(colName, MusicInfo.class);ArrayList<MusicInfo> musicInfos = new ArrayList<>();Block<MusicInfo> block = new Block<MusicInfo>() {public void apply(MusicInfo t) {musicInfos.add(t);}};music.find(musicInfo,MusicInfo.class).forEach(block);return musicInfos;}public static void main(String[] args) {//查询
//        List<MusicInfo> musicInfoMongos = new MongoService().getSongFromMongo(new MusicInfoCodec(), new MusicInfo("小幸运"), "music";
//        for (int i = 0; i < musicInfoMongos.size(); i++) {
//            MusicInfo musicInfo =  musicInfoMongos.get(i);
//            System.out.println("mongo__"+musicInfo.getName());
//        }}
}

        (4) MongoUtil

        用于mongoClient 客户端的连接

package com.test.test.test.utils;import com.mongodb.BasicDBObject;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoClientOptions.Builder;
import com.mongodb.WriteConcern;
import com.mongodb.client.*;
import com.mongodb.client.model.Filters;
import com.mongodb.client.result.DeleteResult;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.bson.types.ObjectId;import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;import static com.mongodb.client.model.Filters.*;
import static com.mongodb.client.model.Projections.*;
import static com.mongodb.client.model.Sorts.ascending;
/*** Created by .*/
public enum MongoUtil {/*** 定义一个枚举的元素,它代表此类的一个实例*/instance;private static MongoClient mongoClient;static {System.out.println("===============MongoDBUtil初始化========================");String ip = "127.0.0.1";int port =27017;instance.mongoClient = new MongoClient(ip, port);// 大部分用户使用mongodb都在安全内网下,但如果将mongodb设为安全验证模式,就需要在客户端提供用户名和密码:// boolean auth = db.authenticate(myUserName, myPassword);Builder options = new MongoClientOptions.Builder();options.cursorFinalizerEnabled(true);// options.autoConnectRetry(true);// 自动重连true// options.maxAutoConnectRetryTime(10); // the maximum auto connect retry timeoptions.connectionsPerHost(300);// 连接池设置为300个连接,默认为100options.connectTimeout(30000);// 连接超时,推荐>3000毫秒options.maxWaitTime(5000); //options.socketTimeout(0);// 套接字超时时间,0无限制options.threadsAllowedToBlockForConnectionMultiplier(5000);// 线程队列数,如果连接线程排满了队列就会抛出“Out of semaphores to get db”错误。options.writeConcern(WriteConcern.SAFE);//options.build();}// ------------------------------------共用方法---------------------------------------------------/*** 获取DB实例 - 指定DB** @param dbName* @return*/public MongoDatabase getDB(String dbName) {if (dbName != null && !"".equals(dbName)) {MongoDatabase database = mongoClient.getDatabase(dbName);return database;}return null;}//mongoDatabase.createCollection("test");public void createCollection(String dbName, String collName){try{mongoClient.getDatabase(dbName).createCollection(collName);}catch(Exception e){System.err.println(e.getClass().getName() + ": " + e.getMessage() );}}/*** 获取collection对象 - 指定Collection** @param collName* @return*/public MongoCollection<Document> getCollection(String dbName, String collName) {if (null == collName || "".equals(collName)) {return null;}if (null == dbName || "".equals(dbName)) {return null;}MongoCollection<Document> collection = mongoClient.getDatabase(dbName).getCollection(collName);return collection;}/*** 查询DB下的所有表名*/public List<String> getAllCollections(String dbName) {MongoIterable<String> colls = getDB(dbName).listCollectionNames();List<String> _list = new ArrayList<String>();for (String s : colls) {_list.add(s);}return _list;}/*** 获取所有数据库名称列表** @return*/public MongoIterable<String> getAllDBNames() {MongoIterable<String> s = mongoClient.listDatabaseNames();return s;}/*** 删除一个数据库*/public void dropDB(String dbName) {getDB(dbName).drop();}/*** 查找对象 - 根据主键_id** @param collection* @param id* @return*/public Document findById(MongoCollection<Document> collection, String id) {Document myDoc = collection.find(Filters.eq("_id", id)).first();return myDoc;}/** 统计数 */public int getCount(MongoCollection<Document> coll) {int count = (int) coll.count();return count;}/** 条件查询 */public MongoCursor<Document> find(MongoCollection<Document> coll, Bson filter) {return coll.find(filter).iterator();}/** 分页查询 */public MongoCursor<Document> findByPage(MongoCollection<Document> coll, Bson filter, int pageNo, int pageSize) {Bson orderBy = new BasicDBObject("_id", 1);return coll.find(filter).sort(orderBy).skip((pageNo - 1) * pageSize).limit(pageSize).iterator();}/*** 通过ID删除** @param coll* @param id* @return*/public int deleteById(MongoCollection<Document> coll, String id) {int count = 0;ObjectId _id = null;try {_id = new ObjectId(id);} catch (Exception e) {return 0;}Bson filter = Filters.eq("_id", _id);DeleteResult deleteResult = coll.deleteOne(filter);count = (int) deleteResult.getDeletedCount();return count;}/*** FIXME** @param coll* @param id* @param newdoc* @return*/public Document updateById(MongoCollection<Document> coll, String id, Document newdoc) {ObjectId _idobj = null;try {_idobj = new ObjectId(id);} catch (Exception e) {return null;}Bson filter = Filters.eq("_id", _idobj);// coll.replaceOne(filter, newdoc); // 完全替代coll.updateOne(filter, new Document("$set", newdoc));return newdoc;}public void dropCollection(String dbName, String collName) {getDB(dbName).getCollection(collName).drop();}/*** 关闭Mongodb*/public void close() {if (mongoClient != null) {mongoClient.close();mongoClient = null;}}/*** 测试入口** @param args* @throws CloneNotSupportedException*/public static void main(String[] args) {String dbName = "music";String collName = "songlist";MongoCollection<Document> coll = MongoUtil.instance.getCollection(dbName, collName);ListIndexesIterable<Document> list = coll.listIndexes();//查询所有索引for (Document document : list) {System.out.println("---"+document.toJson());}}}

(5) MongoService的使用: 

@Autowired
private MongoService mongoService;public void insertMongo(){List<MusicInfo> musicInfos = new ArrayList<>();mongoService.insertMongo(new MusicInfoCodec(),monicInfos, "music");
}

上一张成功的图:



最后安利一个mongodb的PC图形化客户端:

Robo 3T

Robo 3T官网


                

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

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

相关文章

eclipse搜索框太小

解决方式&#xff1a; Window>Preferences>DevStyle>Inline Search 把 use the inline search 取消勾选

fileinput 加 ftp 加 nginx 加 SpringBoot上传文件

亲测可用 准备linux服务器 https://www.cnblogs.com/shuaifing/p/8268949.html 搭建ftp https://www.cnblogs.com/shuaifing/p/8260532.html Springboot整合fileinput 上传文件https://www.cnblogs.com/shuaifing/p/8274906.html 页面 引入 jquery boostrap fileinput.min.js…

Centos7安装Hadoop教程

一&#xff1a;安装SSH 1&#xff0c;执行下面的命令安装ssh yum install openssh-clients yum install openssh-server 2&#xff0c;执行如下命令测试一下 SSH 是否可用&#xff08;SSH首次登陆提示 yes/no 信息&#xff0c;输入 yes 即可&#xff0c;然后按照提示输入 root…

elasticsearch 6.x (一) 部署 windows入门 spingboot连接

大家好&#xff0c;我是烤鸭&#xff1a;今天分享的是 elasticsearch 6.x 部署 windows服务器。环境&#xff1a;win10elasticsearch-6.2.4springboot 2.0.0.RELEASE1. 官网下载elasticsearch这个是最新版本的es下载地址。https://www.elastic.co/downloads/elasticsearch选择z…

Programming Assignment 5: Burrows–Wheeler Data Compression

Programming Assignment 5: Burrows–Wheeler Data Compression 1. 题目阅读 实现Burrows-Wheeler数据压缩算法。这个革命性的算法产生了gzip和pkzip&#xff0c;并且相对容易实现&#xff0c;还不受任何专利保护。它构成了unix压缩实用程序bzip2的基础。 这个算法由以下三种算…

elasticsearch 6.x (二) linux部署 kibana x-pack 安装

大家好&#xff0c;我是烤鸭&#xff1a; 环境&#xff1a;linux Cent OS 7.3elasticsearch-6.2.4 1. 下载elasticsearch https://www.elastic.co/downloads/elasticsearch 上面的网址直接下载的话&#xff0c;实在太慢了。官方还提供了另一种方式。 https://www.elastic.co…

Kali Linux ——在无网络情况下安装无线网卡驱动

1、背景&#xff1a; 今日刚刚开始学习kali linux&#xff0c;众所周知&#xff0c;安装完成后&#xff0c;系统是没有无线网卡驱动的&#xff0c;这就对学生党造成相当的困扰&#xff1a;校园网要连接有线是需要认证客户端的&#xff0c;而认证客户端只有windows端&#xff0c…

HADOOP_HOME and hadoop.home.dir are unset 报错处理

一般是windows才会出现这个问题 请看下面的解决方案&#xff1a; 第一步&#xff1a;下载winutils-master.zip Gitee地址&#xff1a;https://gitee.com/nkuhyx/winutils.git 蓝奏云&#xff1a;https://www.lanzoux.com/i55ccnc Github地址&#xff1a;https://github.com/cda…

elasticsearch 6.x (三) linux 集群多节点部署

大家好&#xff0c;我是烤鸭&#xff1a;关于集群内单个节点部署&#xff0c;请参考上一篇文章。elasticsearch 6.x linux部署(二) kibana x-pack 安装环境&#xff1a;linux Cent OS 7.3elasticsearch-6.2.41. 下载多个es安装每个安装步骤都是一样的。2. 修改配置文件(重…

springboot-devtools idea或eclipse 热加载

大家好&#xff0c;我是烤鸭&#xff1a;今天分享一下springboot项目的热加载。第二种方式在eclipse和idea中都可以。虽然会有一些小坑。 方式有两种&#xff1a; 1. springloaded(无效) <!-- https://mvnrepository.com/artifact/org.springframework/springloaded -->…

springboot mybatis 热加载mapper.xml文件(最简单)

大家好&#xff0c;我是烤鸭: 今天介绍一下springboot mybatis 热加载mapper.xml文件。 本来不打算写的&#xff0c;看到网上比较流行的方式都比较麻烦&#xff0c;想着简化一下。 网上流行的版本。 https://www.cnblogs.com/oskyhg/p/8587701.html 总结一下需要&#xff1a;my…

vue cli vue 3.x

vue cli & vue 3.x https://cli.vuejs.org/dev-guide/ui-api.html#ui-api https://cli.vuejs.org/zh/guide/#cli vue cli & how to select the option in cmd ? vue cli & 选中 option a select all & i select all 1,2,3,4,5,6,7,8,9,0 分别对应 order 转载…

jenkins svn/git sonarqube scanner 代码集成测试

大家好&#xff0c;我是烤鸭&#xff1a;今天分享一个代码检测工具sonar&#xff0c;在jenkins集成的时候使用。 环境:sonarqube 7.1jenkins 2.12xsonarqube scanner &#xff08;官网最新版3.2.0.1227&#xff09;1. jenkins svn/git 搭建项目https://blog.csdn.net/Angry…

射频与微波测量之S参数

转自&#xff1a;https://www.cnblogs.com/lyh523329053/p/9128577.html S参数 S散射也叫散射参数。是微波传输中的一组重要参数。由于我们很难在高频率时测量电流或电压&#xff0c;因此我们要测量散射参数或 S 参数。这些参数用来表征RF 元件或网络的电气属性或性能&#xff…

JAVA构造对象的几种方式(构建器、构造器)

大家好&#xff0c;我是烤鸭&#xff1a;今天说一下初始化对象的几种方式&#xff1a;1. 多参数构造器2. 构建器3. 构造器后 get/set方法举个例子:这里有个机构entity&#xff0c;提供一个默认构造器 package com.xxx.xxx.modules.sys.entity;/*** 机构Entity* versi…

Django框架(十二)-- Djang与Ajax

一、什么是Ajax AJAX&#xff08;Asynchronous Javascript And XML&#xff09;翻译成中文就是“异步Javascript和XML”。即使用Javascript语言与服务器进行异步交互&#xff0c;传输的数据为XML&#xff08;当然&#xff0c;传输的数据不只是XML,现在更多使用json数据&#xf…

javascript 将table导出 Excel ,可跨行跨列

原文地址&#xff1a;https://www.cnblogs.com/hailexuexi/p/10795887.html <script language"JavaScript" type"text/javascript">//jQuery HTML导出Excel文件(兼容IE及所有浏览器)function HtmlExportToExcel(tableid,file_name) {var filename fi…

wampserver 搭建 php环境 运行方法

大家好&#xff0c;我是烤鸭&#xff1a;今天分享的是如何用wamp 运行 php代码。1. wampserver下载&#xff1a;下载地址&#xff1a;https://sourceforge.net/projects/wampserver/files/WampServer%203/WampServer%203.0.0/Addons/Php/wampserver3_x64_addon_php7.2.7.exe…

java php des加密 byte数组16进制 DESTools

大家好&#xff0c;我是烤鸭:今天分享的是java 和 php des 加密。因为接口对接&#xff0c;难免不同语言&#xff0c;加密又是必不可少的。作为接口的提供方&#xff0c;必须把加密规则写好&#xff0c;最好有不同语言的加密demo。1. java版本的des加密解密工具类DESTools.j…

高可用Eureka注册中心配置说明(双机部署)

目 录 1. 高可用EureKa注册中心示意图 2. Eureka实例相互注册配置 3. 微服务注册到Eureka配置 4. 启动步骤及配置成功检查 5. 说明事项 1. 高可用EureKa注册中心示意图 Spring Cloud的Eureka Server的高可用实际上就是将自己作为服务向其他服注册中心注册自己&#xff0c;形成…