rabbitmq进阶一

上一篇文章有讲到rabbitmq的安装、web管理端和springboot简单集成rabbitmq

本文重点介绍rabbitmq相关api的使用

按照官网常用的五种模式的顺序:HelloWorld、Work queues、Publish/Subscribe、Routing、Topics

模式简单介绍

HelloWorld

一个生产者,一个队列,一个消费者。

一个demo,实际很少使用。

Work queues

在多个消费者之间分配任务,竞争消费模式。

Publish/Subscribe

发布订阅模式,同时向多个消费者发送消息。

Routing

选择性的接收消息

Topics

基于表达式接收消息

模式具体使用(rabbitmqclient)

HelloWorld

创建maven项目并且引入依赖

    <dependencies><dependency><groupId>com.rabbitmq</groupId><artifactId>amqp-client</artifactId><version>5.9.0</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.13.2</version></dependency></dependencies>

创建工具类,用于处理连接和信道的创建,以及他们的关闭

package org.cc;import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;import java.io.IOException;
import java.util.concurrent.TimeoutException;public class ConnectionUtils {public static Connection createConnection() throws IOException, TimeoutException {ConnectionFactory connectionFactory = new ConnectionFactory();
//        connectionFactory.setHost("localhost");//默认主机:localhost
//        connectionFactory.setPort(5672);//默认端口5672
//        connectionFactory.setUsername("guest");//默认用户名:guest
//        connectionFactory.setPassword("guest");//默认密码:guest
//        connectionFactory.setVirtualHost("/");//默认虚拟主机:/return connectionFactory.newConnection();}public static void closeConnection(Connection connection, Channel channel) throws IOException, TimeoutException {channel.close();connection.close();}
}

创建消费者

package org.cc;import com.rabbitmq.client.*;
import org.junit.Test;import java.io.IOException;
import java.util.concurrent.TimeoutException;public class HelloWorldConsumer {@Testpublic void sendMsg() throws IOException, TimeoutException {Connection connection = ConnectionUtils.createConnection();Channel channel = connection.createChannel();/*声明一个名称是my helloworld queue,持久化,非独享,非自动删除的队列durable – 是否持久化,为true时重启rabbitmq服务,会保留原有的队列exclusive – 是否独享,为true时连接一旦断开,会自动删除队列autoDelete 是否自动删除,为true时一旦队列被消费,会自动删除队列*///若队列已存在,这些参数必须与队列一致,若队列不存在则创建channel.queueDeclare("my helloworld queue",true,false,false,null);channel.basicConsume("my helloworld queue",true,new DefaultConsumer(channel){@Overridepublic void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {System.out.println("helloworld consumer接收到消息:"+new String(body));}});System.in.read();//保持消费者一直监听队列}
}

创建生产者

package org.cc;import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;public class HelloWorldProducer {@Testpublic void sendMsg() throws IOException, TimeoutException {Connection connection = ConnectionUtils.createConnection();Channel channel = connection.createChannel();/*声明一个名称是my helloworld queue,持久化,非独享,非自动删除的队列durable – 是否持久化,为true时重启rabbitmq服务,会保留原有的队列exclusive – 是否独享,为true时连接一旦断开,会自动删除队列autoDelete 是否自动删除,为true时一旦队列被消费,会自动删除队列*///若队列已存在,这些参数必须与队列一致,若队列不存在则创建channel.queueDeclare("my helloworld queue",true,false,false,null);channel.basicPublish("","my helloworld queue",null,"helloworld消息内容".getBytes(StandardCharsets.UTF_8));ConnectionUtils.closeConnection(connection,channel);}
}

 若要保证rabbitmq重启后消息仍然存在,生产者发送消息时需要设置props参数

channel.basicPublish("","my helloworld queue", MessageProperties.PERSISTENT_TEXT_PLAIN,"helloworld消息内容".getBytes(StandardCharsets.UTF_8));

 开启手动ack,消费者接收到消息时,需要手动发送ack确认后消息才会真正从队列中删除

        channel.basicConsume("my helloworld queue",false,new DefaultConsumer(channel){@Overridepublic void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {System.out.println("helloworld consumer接收到消息:"+new String(body));channel.basicAck(envelope.getDeliveryTag(),false);}});

Work queues

创建消费者,与上面helloworld模式代码基本一致,将原有的创建消费者的代码重复一遍

package org.cc;import com.rabbitmq.client.*;
import org.junit.Test;import java.io.IOException;
import java.util.concurrent.TimeoutException;public class HelloWorldConsumer {@Testpublic void sendMsg() throws IOException, TimeoutException {Connection connection = ConnectionUtils.createConnection();Channel channel = connection.createChannel();/*声明一个名称是my helloworld queue,持久化,非独享,非自动删除的队列durable – 是否持久化,为true时重启rabbitmq服务,会保留原有的队列exclusive – 是否独享,为true时连接一旦断开,会自动删除队列autoDelete 是否自动删除,为true时一旦队列被消费,会自动删除队列*///若队列已存在,这些参数必须与队列一致,若队列不存在则创建channel.queueDeclare("my helloworld queue",true,false,false,null);channel.basicConsume("my helloworld queue",true,new DefaultConsumer(channel){@Overridepublic void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {System.out.println("helloworld consumer接收到消息:"+new String(body));}});System.in.read();//保持消费者一直监听队列}
}

创建生产者,与上面helloworld模式代码基本一致,这里连续发送10条消息

package org.cc;import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.MessageProperties;
import org.junit.Test;import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;public class WorkProducer {@Testpublic void sendMsg() throws IOException, TimeoutException {Connection connection = ConnectionUtils.createConnection();Channel channel = connection.createChannel();channel.queueDeclare("my work queue",true,false,false,null);for (int i = 0; i < 10; i++) {channel.basicPublish("","my work queue", MessageProperties.PERSISTENT_TEXT_PLAIN,("work消息内容"+i).getBytes(StandardCharsets.UTF_8));}ConnectionUtils.closeConnection(connection,channel);}
}

 从消费者的控制台可以看到两个消费者轮流接收到消息

Publish/Subscribe

消费者

package org.cc;import com.rabbitmq.client.*;
import org.junit.Test;import java.io.IOException;
import java.util.concurrent.TimeoutException;public class Subscriber {@Testpublic void receive() throws IOException, TimeoutException {Connection connection = ConnectionUtils.createConnection();Channel channel = connection.createChannel();channel.exchangeDeclare("fanout exchange", BuiltinExchangeType.FANOUT);channel.queueDeclare("my fanout queue1",true,false,false,null);channel.queueBind("my fanout queue1","fanout exchange","");channel.basicConsume("my fanout queue1",true,new DefaultConsumer(channel){@Overridepublic void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {System.out.println("my fanout queue1 consumer接收到消息:"+new String(body));}});Connection connection1 = ConnectionUtils.createConnection();Channel channel1 = connection1.createChannel();channel1.queueDeclare("my fanout queue2",true,false,false,null);channel.queueBind("my fanout queue2","fanout exchange","");channel1.basicConsume("my fanout queue2",true,new DefaultConsumer(channel1){@Overridepublic void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {System.out.println("my fanout queue2 consumer接收到消息:"+new String(body));}});System.in.read();//保持消费者一直监听队列}
}

生产者

package org.cc;import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.MessageProperties;
import org.junit.Test;import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;public class Publisher {@Testpublic void sendMsg() throws IOException, TimeoutException {Connection connection = ConnectionUtils.createConnection();Channel channel = connection.createChannel();channel.exchangeDeclare("fanout exchange", BuiltinExchangeType.FANOUT);channel.basicPublish("fanout exchange","", MessageProperties.PERSISTENT_TEXT_PLAIN,"fanout exchange消息内容".getBytes(StandardCharsets.UTF_8));ConnectionUtils.closeConnection(connection,channel);}
}

 队列需要同交换机绑定,生产者向交换机发送消息

Routing

消费者 

package org.cc;import com.rabbitmq.client.*;
import org.junit.Test;import java.io.IOException;
import java.util.concurrent.TimeoutException;public class RoutingKeyConsumer {@Testpublic void receive() throws IOException, TimeoutException {Connection connection = ConnectionUtils.createConnection();Channel channel = connection.createChannel();channel.exchangeDeclare("direct exchange", BuiltinExchangeType.DIRECT);channel.queueDeclare("my direct queue1",true,false,false,null);channel.queueBind("my direct queue1","direct exchange","info");channel.basicConsume("my direct queue1",true,new DefaultConsumer(channel){@Overridepublic void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {System.out.println("my direct queue1 consumer接收到消息:"+new String(body));}});Connection connection1 = ConnectionUtils.createConnection();Channel channel1 = connection1.createChannel();channel1.queueDeclare("my direct queue2",true,false,false,null);channel.queueBind("my direct queue2","direct exchange","info");channel.queueBind("my direct queue2","direct exchange","error");channel1.basicConsume("my direct queue2",true,new DefaultConsumer(channel1){@Overridepublic void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {System.out.println("my direct queue2 consumer接收到消息:"+new String(body));}});System.in.read();//保持消费者一直监听队列}
}

生产者

package org.cc;import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.MessageProperties;
import org.junit.Test;import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;public class RoutingProducer {@Testpublic void sendMsg() throws IOException, TimeoutException {Connection connection = ConnectionUtils.createConnection();Channel channel = connection.createChannel();channel.exchangeDeclare("direct exchange", BuiltinExchangeType.DIRECT);channel.basicPublish("direct exchange","info", MessageProperties.PERSISTENT_TEXT_PLAIN,"direct exchange info消息内容".getBytes(StandardCharsets.UTF_8));channel.basicPublish("direct exchange","error", MessageProperties.PERSISTENT_TEXT_PLAIN,"direct exchange error消息内容".getBytes(StandardCharsets.UTF_8));ConnectionUtils.closeConnection(connection,channel);}
}

Topics

交换机路由消息给队列时基于表达式,*匹配1个,#配置0个或1个或多个

例如:当队列1的路由值设置user.*,队列2的路由值设置user.#时,向交换机分别发送四条消息,消息的路由值分别为user.insert、user.insert.a、user.、user

此时队列1会收到路由值为user.insert和user.的消息,队列1能收到上面全部四条消息

消费者代码

package org.cc;import com.rabbitmq.client.*;
import org.junit.Test;import java.io.IOException;
import java.util.concurrent.TimeoutException;public class TopicsConsumer {@Testpublic void receive() throws IOException, TimeoutException {Connection connection = ConnectionUtils.createConnection();Channel channel = connection.createChannel();channel.exchangeDeclare("topic exchange", BuiltinExchangeType.TOPIC);channel.queueDeclare("my topic queue1",true,false,false,null);channel.queueBind("my topic queue1","topic exchange","user.*");channel.basicConsume("my topic queue1",true,new DefaultConsumer(channel){@Overridepublic void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {System.out.println("my topic queue1 consumer接收到消息:"+new String(body));}});Connection connection1 = ConnectionUtils.createConnection();Channel channel1 = connection1.createChannel();channel1.queueDeclare("my topic queue2",true,false,false,null);channel.queueBind("my topic queue2","topic exchange","user.#");channel1.basicConsume("my topic queue2",true,new DefaultConsumer(channel1){@Overridepublic void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {System.out.println("my topic queue2 consumer接收到消息:"+new String(body));}});System.in.read();//保持消费者一直监听队列}
}

生产者代码

package org.cc;import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.MessageProperties;
import org.junit.Test;import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;public class TopicsProducer {@Testpublic void sendMsg() throws IOException, TimeoutException {Connection connection = ConnectionUtils.createConnection();Channel channel = connection.createChannel();channel.exchangeDeclare("topic exchange", BuiltinExchangeType.TOPIC);channel.basicPublish("topic exchange","user.insert", MessageProperties.PERSISTENT_TEXT_PLAIN,"topic exchange user.insert消息内容".getBytes(StandardCharsets.UTF_8));channel.basicPublish("topic exchange","user.insert.a", MessageProperties.PERSISTENT_TEXT_PLAIN,"topic exchange user.insert.a消息内容".getBytes(StandardCharsets.UTF_8));channel.basicPublish("topic exchange","user.", MessageProperties.PERSISTENT_TEXT_PLAIN,"topic exchange user.消息内容".getBytes(StandardCharsets.UTF_8));channel.basicPublish("topic exchange","user", MessageProperties.PERSISTENT_TEXT_PLAIN,"topic exchange user消息内容".getBytes(StandardCharsets.UTF_8));ConnectionUtils.closeConnection(connection,channel);}
}

模式具体使用(springboot集成rabbitmq)

使用idea构建项目,选择spring initializer,创建生产者项目springboot-rabbitmq-producer

  dependencies选择如下

 application.properties设置如下

 使用同样的方式创建消费者项目springboot-rabbitmq-consumer,将server.port设置为8081

当前springboot版本最新为2.6.3

HelloWorld

创建消费者并启动消费者应用

package com.example.springbootrabbitmqconsumer.helloworld;import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;/*** springboot-rabbitmq-producer** @author v_choncheng* @description* @create 2022-02-15 14:42*/
@Component
@RabbitListener(queuesToDeclare = @Queue("helloworld"))
public class HelloWorldConsumer {@RabbitHandlerpublic void receive(String msg) {System.out.println("消费者接受到消息" + msg);}}

创建生产者

package com.example.springbootrabbitmqproducer.helloworld;import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;/*** springboot-rabbitmq-producer** @author v_choncheng* @description* @create 2022-02-15 14:42*/
@Configuration
public class HelloWorldProducer {@Beanpublic Queue createQueue() {return new Queue("helloworld");}
}

生产者工程测试类中增加测试方法

 运行此测试方法后可以看到消费者接收到一条消息


Work queues

创建消费者并启动消费者应用

package com.example.springbootrabbitmqconsumer.workqueues;import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;/*** springboot-rabbitmq-consumer** @author v_choncheng* @description* @create 2022-02-15 15:11*/
@Component
public class WorkQueuesConsumer {@RabbitListener(queuesToDeclare = @Queue("workqueues"))public void receive1(String msg) {System.out.println("消费者1接受到消息" + msg);}@RabbitListener(queuesToDeclare = @Queue("workqueues"))public void receive2(String msg) {System.out.println("消费者2接受到消息" + msg);}
}

生产者工程测试类中增加测试方法

运行此测试方法后可以看到消费者1、2轮流接收到消息


Publish/Subscribe

创建消费者并启动消费者应用

package com.example.springbootrabbitmqconsumer.fanout;import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;/*** springboot-rabbitmq-consumer** @author v_choncheng* @description* @create 2022-02-15 15:23*/
@Component
public class FanoutConsumer {@RabbitListener(bindings = @QueueBinding(exchange = @Exchange(type = ExchangeTypes.FANOUT, name = "fanoutexchange"), value = @Queue("fanoutqueues1")))public void receive1(String msg) {System.out.println("消费者1接受到消息" + msg);}@RabbitListener(bindings = @QueueBinding(exchange = @Exchange(type = ExchangeTypes.FANOUT, name = "fanoutexchange"), value = @Queue("fanoutqueues2")))public void receive2(String msg) {System.out.println("消费者2接受到消息" + msg);}
}

生产者工程测试类中增加测试方法

 运行此测试方法后可以看到消费者1、2同时接收到消息


Routing

创建消费者并启动消费者应用

package com.example.springbootrabbitmqconsumer.routing;import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;/*** springboot-rabbitmq-consumer** @author v_choncheng* @description* @create 2022-02-15 15:38*/
@Component
public class RoutingConsumer {@RabbitListener(bindings = @QueueBinding(exchange = @Exchange(type = ExchangeTypes.DIRECT, name = "routingexchange"), value = @Queue("routingqueues1"), key = {"debug", "verbose", "notice", "warning"}))public void receive1(String msg) {System.out.println("消费者1接受到消息" + msg);}@RabbitListener(bindings = @QueueBinding(exchange = @Exchange(type = ExchangeTypes.DIRECT, name = "routingexchange"), value = @Queue("routingqueues2"), key = {"debug", "verbose"}))public void receive2(String msg) {System.out.println("消费者2接受到消息" + msg);}
}

生产者工程测试类中增加测试方法

 运行此测试方法后可以看到消费者1接收四条消息、消费者2只接收到debug和verbose消息


Topics

创建消费者并启动消费者应用

package com.example.springbootrabbitmqconsumer.topics;import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;/*** springboot-rabbitmq-consumer** @author v_choncheng* @description* @create 2022-02-15 15:38*/
@Component
public class TopicsConsumer {@RabbitListener(bindings = @QueueBinding(exchange = @Exchange(type = ExchangeTypes.TOPIC, name = "topicexchange"), value = @Queue("topicqueues1"), key = {"user.*"}))public void receive1(String msg) {System.out.println("消费者1接受到消息" + msg);}@RabbitListener(bindings = @QueueBinding(exchange = @Exchange(type = ExchangeTypes.TOPIC, name = "topicexchange"), value = @Queue("topicqueues2"), key = {"user.#", "verbose"}))public void receive2(String msg) {System.out.println("消费者2接受到消息" + msg);}
}

生产者工程测试类中增加测试方法

 运行此测试方法后可以看到消费者2接收四条消息、消费者1只接收到user.和user.insert消息

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

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

相关文章

mysql 相关搜索_MySQL单词搜索相关度排名

一个单词搜索的相关度排名,这个例子演示了一个单词搜索的相关度排名计算。mysql> CREATE TABLE articles (-> id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,-> title VARCHAR(200),-> body TEXT,-> FULLTEXT (title,body)-> ) ENGINEInnoDB;Query O…

IDEA使用总结

idea中使用tomcat IntelliJ IDEA配置Tomcat&#xff08;完整版图文教程&#xff09;_猿Bug的博客-CSDN博客_intellij tomcat配置 用上面的方式发现缺少文件&#xff0c;在edit configuration页面选择before lanuch前选择Run maven goal package

mysql一直copying to tmp table_mysql提示Copying to tmp table on disk

网站运行的慢了&#xff0c;查找原因是Copying to tmp table on disk那怎么解决这个问题呢解决一例最近常常碰到网站慢的情况&#xff0c;登陆到后台&#xff0c;查询一下 /opt/mysql/bin/mysqladmin processlist;发现一个查询状态为&#xff1a; Copying to tmp table 而且此查…

idea cloud bootstrap是啥_application.yml与bootstrap.yml的区别

Spring Boot 默认支持 properties(.properties) 和 YAML(.yml .yaml ) 两种格式的配置文件&#xff0c;yml 和 properties 文件都属于配置文件&#xff0c;功能一样。Spring Cloud 构建于 Spring Boot 之上&#xff0c;在 Spring Boot 中有两种上下文&#xff0c;一种是 bootst…

python读取日期_从文件中读取日期和数据(Python)

我想从文件中读取时间字符串和数据&#xff0c;但是当我使用loadtxt时&#xff0c;我不能同时读取字符串和数字&#xff0c;因为字符串不是浮点型的。所以我尝试使用genfromtxt并使用delimiter[][][]作为我所拥有的列&#xff0c;但是字符串的读起来像nan。我希望像时间数组(da…

一个小白如何创建MYSQL数据表_MySQL小白扫盲(二)--建表、添加、查询

1.SELECT子句字句名称          使用目的select           确定结果集中应该包含哪些列from           指明所要提取数据的表&#xff0c;以及这些表示如何连接的where           过滤掉不需要的数据group by         用于…

元数据解决分表不可 mysql_MySQL InnoDB技术内幕:内存管理、事务和锁

前面有多篇文章介绍过MySQL InnoDB的相关知识&#xff0c;今天我们要更深入一些&#xff0c;看看它们的内部原理和机制是如何实现的。一、内存管理我们知道&#xff0c;MySQl是一个存储系统&#xff0c;数据最后都写在磁盘上。我们以前也提到过&#xff0c;磁盘的速度特别是大容…

navicat for mysql 13_Navicat for MySQL下载

Navicat for MySQL 是一套管理和开发 MySQL 或 MariaDB 的理想解决方案。它使你以单一程序同时连接到 MySQL 和 MariaDB。这个功能齐备的前端软件为数据库管理、开发和维护提供了直观而强大的图形界面。它提供了一组全面的工具给 MySQL 或MariaDB 新手&#xff0c;同时给专业人…

mysql 日期型中文报错_mysql日期类型默认值'0000-00-00' 报错,是什么问题?

如题&#xff0c;本来是 从另一个数据库中导出的sql文件&#xff0c;在我电脑上导入报这个错误&#xff0c;不知道是不是mysql 版本问题。多方搜索无果&#xff0c;所以上来求助。DROP TABLE IF EXISTS workreport_member;CREATE TABLE workreport_member (uid int(10) unsigne…

python在线作业_南开大学20春学期《Python编程基础》在线作业参考答案

南开大学20春学期(1709、1803、1809、1903、1909、2003)《Python编程基础》在线作业试卷总分:100 得分:98一、单选题(共20 道试题,共40 分)1.已知“stra\rb\r\nc\n”,则“str.splitlines()”的返回结果是( )。A.[a,b,c]B.[a\r,b\r\n,c\n]C.[a\r,b\r,c]D.[a\r,b,c]答案:A2.已知“…

spring兼容mysql_springboot 最新版本支持 mysql6.0.6吗

缥缈止盈1.首先在pom文件中加入下列依赖,一个使用jpa所需依赖,一个连接MySQL使用的依赖:mysqlmysql-connector-javaorg.springframework.bootspring-boot-starter-data-jpa 123456789102.在配置文件中添加datasource配置和jpa配置,在mysql中已经提前创建了一个名为db_test的数据…

java集合map_JAVA中的集合类Map、Set、List

*精炼的总结&#xff1a;Collection 是对象集合&#xff0c; Collection 有两个子接口 List 和 SetList 可以通过下标 (1,2..) 来取得值&#xff0c;值可以重复而 Set 只能通过游标来取值&#xff0c;并且值是不能重复的ArrayList &#xff0c; Vector &#xff0c; LinkedList…

java虚拟机内存监控_java虚拟机内存监控工具jps,jinfo,Jstack,jstat,jmap,jhat使用...

将会打印出很多jvm运行时参数信息&#xff0c;由于比较长这里不再打印出来&#xff0c;可以自己试试&#xff0c;内容一目了然Jstack(Stack Trace for Java)&#xff1a;JVM堆栈跟踪工具jstack用于打印出给定的java进程ID或core file或远程调试服务的Java堆栈信息&#xff0c;如…

idea 调试java技巧_IDEA 调试Java代码的两个技巧

本文介绍两个使用IDEA 调试Java代码的两个技巧&#xff1a;修改变量值使用RuntimeException终止代码执行修改变量值在Java代码调试过程中&#xff0c;我们可以修改变量值&#xff0c;使其达到走指定分支的目的&#xff0c;或者使其满足某个条件。我们以给变量beanName赋值为例&…

java 10进制转 000x_java 如何把 00 转换成 0x00 或者 10 转换成 0x10

public static void main(String[] args) {String s "00000018A0010098C68E00989A690000000000BC614E000055AA55AA";System.out.println(s);byte[] b HexString2Bytes(s);System.out.println(Bytes2HexString(b));}/*** 将指定byte数组以16进制的形式打印到控制台*…

java免检异常_java-异常

java提供了异常处理机制&#xff1a;程序运行受阻时候的处理方式。1、异常分类Error&#xff1a;系统错误&#xff0c;由java虚拟机抛出&#xff0c;很少发生&#xff1b;免检异常RuntimeException&#xff1a;程序设计错误&#xff0c;通常由java虚拟机抛出&#xff1b;免检异…

java编程需要数学知识吗_初学Java编程,需要英语和数学基础吗?

原标题&#xff1a;初学Java编程&#xff0c;需要英语和数学基础吗&#xff1f;“学习Java编程英语和数学是必备条件吗&#xff1f;”很多Java零基础学习或者转型IT行业的都会有这样的疑问&#xff0c;其实刚开始学习Java编程是不需要太高深的数学和英语基础的。刚开始学习Java…

java map put报错_java 集合(Map)

-------------------|Map 储存的数据都是以键值对的形式&#xff0c;键不可重复&#xff0c;值可重复。----------------------------| HashMap----------------------------| TreeMap----------------------------| HashTableMap接口的方法&#xff1a;添加&#xff1a;put(K…

java简单数据结构_图解Java常用数据结构

最近在整理数据结构方面的知识, 系统化看了下 Java 中常用数据结构, 突发奇想用动画来绘制数据流转过程.主要基于 jdk8, 可能会有些特性与 jdk7 之前不相同, 例如 LinkedList LinkedHashMap 中的双向列表不再是回环的.HashMap 中的单链表是尾插, 而不是头插入等等, 后文不再赘叙…

jest java_✅使用jest进行测试驱动开发

前言本文将使用jest进行测试驱动开发的示例&#xff0c;源码在github。重点说明在开发中引入单元测试后开发过程&#xff0c;以及测试先行的开发思路。本文的重点是过程以及思维方法&#xff0c;框架以及用法不是重点。本文使用的编程语言是javascript&#xff0c;思路对其他语…