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.pswp.cn/news/530329.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/530329.shtml
英文地址,請注明出處:http://en.pswp.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;思路對其他語…