学习Rust的第22天:mini_grep第2部分

news2024/10/6 12:27:58

书接上文,在本文中,我们学习了如何通过将 Rust 程序的逻辑移至单独的库箱中并采用测试驱动开发 (TDD) 实践来重构 Rust 程序。通过在实现功能之前编写测试,我们确保了代码的可靠性。我们涵盖了基本的 Rust 概念,例如错误处理、环境变量和命令行参数。本文最后提出了最后一个改进:将错误消息重定向到 stderr 以提供更好的用户体验。

Recap 回顾

This is our code so far
这是我们到目前为止的代码

use std::env;
use std::fs;
use std::process;
use std::error::Error;

struct Config {
    query: String,
    file: String,
}

impl Config{
    fn new(args: &[String]) -> Result<Config, &str>{
        if args.len() < 3{
            return Err("Not enough arguments.");
        }

        let query: String = args[1].clone();
        let file: String = args[2].clone();

        Ok(Config{query,file})
    }
}

fn run(config: Config) -> Result<(), Box<dyn Error>>{
    let contents = fs::read_to_string(config.file)?;
    println!("file contents: {}",contents);

    Ok(())
}

fn main(){
    let args: Vec<String> = env::args().collect();

    let config = Config::new(&args).unwrap_or_else(|err|{
        println!("Problem parsing arguments: {}",err);
        println!("Expected: {} search_query filename", args[0]);
        process::exit(1);
    });

    if let Err(e) = run(config) {
        println!("Application error: {}",e);
        process::exit(1);
    }
}

Explanation: 解释:

use std::env;
use std::fs;
use std::process;
use std::error::Error;

These lines import specific modules from the standard library (std).
这些行从标准库 ( std ) 导入特定模块。

  • env: Provides functions for interacting with the environment (e.g., command-line arguments).
    env :提供与环境交互的函数(例如命令行参数)。
  • fs: Offers file system operations like reading and writing files.
    fs :提供文件系统操作,例如读取和写入文件。
  • process: Provides functions for interacting with processes (e.g., exiting a process).
    process :提供与进程交互的功能(例如,退出进程)。
  • error::Error: Imports the Error trait, which is used for error handling.
    error::Error :导入 Error 特征,用于错误处理。
struct Config {
    query: String,
    file: String,
}
  • Defines a struct named Config with two fields: query and file, both of type String.
    定义一个名为 Config 的结构体,其中包含两个字段: query 和 file ,均为 String 类型。
impl Config{
    fn new(args: &[String]) -> Result<Config, &str>{
        if args.len() < 3 {
            return Err("Not enough arguments.");
        }
    let query: String = args[1].clone();
        let file: String = args[2].clone();
        Ok(Config{query, file})
    }
}

Implements methods for the Config struct.
实现 Config 结构的方法。

  • Defines a constructor method new for creating a new Config instance.
    定义一个构造函数方法 new 用于创建新的 Config 实例。
  • Takes a slice of strings (&[String]) representing command-line arguments as input.
    将表示命令行参数的字符串片段 ( &[String] ) 作为输入。
  • Returns a Result where Ok contains a Config instance if arguments are sufficient, and Err contains an error message otherwise.
    如果参数足够,则返回 Result ,其中 Ok 包含 Config 实例,否则 Err 包含错误消息。
fn run(config: Config) -> Result<(), Box<dyn Error>>{
    let contents = fs::read_to_string(config.file)?;
    println!("file contents: {}",contents);
    Ok(())
}

Defines a function run that takes a Config instance as input.
定义一个函数 run ,它将 Config 实例作为输入。

  • Attempts to read the contents of the file specified in the Config.
    尝试读取 Config 中指定的文件的内容。
  • Prints the contents of the file.
    打印文件的内容。
  • Returns Ok(()) if successful, indicating no error.
    如果成功则返回 Ok(()) ,表示没有错误。
fn main(){
    let args: Vec<String> = env::args().collect();
    let config = Config::new(&args).unwrap_or_else(|err|{
        println!("Problem parsing arguments: {}",err);
        println!("Expected: {} search_query filename", args[0]);
        process::exit(1);
    });
    if let Err(e) = run(config) {
        println!("Application error: {}",e);
        process::exit(1);
    }
}

Defines the main function, the entry point of the program.
定义 main 函数,程序的入口点。

  • Retrieves command-line arguments and collects them into a vector of strings.
    检索命令行参数并将它们收集到字符串向量中。
  • Attempts to create a Config instance from the command-line arguments.
    尝试从命令行参数创建 Config 实例。
  • If successful, continues with the program execution.
    如果成功,则继续执行程序。
  • If unsuccessful, prints an error message and exits the program.
    如果不成功,则打印错误消息并退出程序。
  • Calls the run function with the Config instance.
    使用 Config 实例调用 run 函数。
  • Handles any errors that occur during the execution of run by printing an error message and exiting the program.
    通过打印错误消息并退出程序来处理 run 执行期间发生的任何错误。
let config = Config::new(&args).unwrap_or_else(|err|{
        println!("Problem parsing arguments: {}",err);
        println!("Expected: {} search_query filename", args[0]);
        process::exit(1);
    });
  • This is a closure, an error-handling mechanism used when creating a Config instance from command-line arguments. It prints error details and expected usage if parsing fails, then exits the program with an error code. We will study about closures in detail in the upcoming articles
    这是一个闭包,是从命令行参数创建 Config 实例时使用的错误处理机制。如果解析失败,它会打印错误详细信息和预期用法,然后使用错误代码退出程序。我们将在接下来的文章中详细研究闭包

Extracting logic to a library crate
将逻辑提取到库箱中

Our main.rs file is kind of bloated at the moment and all oof our logic is stored in one place, to tackle this situation we can create a library crate and store all the logic there and our main.rs file can call the library crate for logic.
我们的 main.rs 文件目前有点臃肿,我们所有的逻辑都存储在一个地方,为了解决这种情况,我们可以创建一个库板条箱并将所有逻辑存储在那里,我们的 main.rs
First things first, create a lib.rs file in the src directory, this is where we will store all our logic…
首先,在 src 目录中创建一个 lib.rs 文件,这是我们存储所有逻辑的地方......

$ touch src/lib.rs
├── Cargo.lock
├── Cargo.toml
├── lorem.txt
├── src
│   ├── lib.rs
│   └── main.rs
└── target
    ├── CACHEDIR.TAG
    └── debug

We will move our run() function and the Config struct and implementation to the lib.rs file with the relevant use statements
我们将把 run() 函数以及 Config 结构和实现移至 lib.rs 文件,并包含相关的 use 语句

// lib.rs

use std::fs;
use std::error::Error;

pub struct Config {
    pub query: String,
    pub file: String,
}

impl Config{
    pub fn new(args: &[String]) -> Result<Config, &str>{
        if args.len() < 3{
            return Err("Not enough arguments.");
        }

        let query: String = args[1].clone();
        let file: String = args[2].clone();

        Ok(Config{query,file})
    }
}

pub fn run(config: Config) -> Result<(), Box<dyn Error>>{
    let contents = fs::read_to_string(config.file)?;
    println!("file contents: {}",contents);

    Ok(())
}

Remember, everything in rust is private by default, that is where we can use the pub keyword to make it public
请记住,默认情况下,rust 中的所有内容都是私有的,这就是我们可以使用 pub 关键字将其公开的地方

Then we can import the Config struct from the library crate and call the run function from there as well in the main.rs file.
然后我们可以从库箱中导入 Config 结构,并在 main.rs 文件中调用 run 函数。

use std::env;
use std::process;

use minigrep::Config;

fn main(){
    let args: Vec<String> = env::args().collect();

    let config = Config::new(&args).unwrap_or_else(|err|{
        println!("Problem parsing arguments: {}",err);
        println!("Expected: {} search_query filename", args[0]);
        process::exit(1);
    });

    if let Err(e) = minigrep::run(config) {
        println!("Application error: {}",e);
        process::exit(1);
    }
}

Now seems like a good time for us to dive into Test-driven development, this is an important concept when it comes to programming. It involves
现在似乎是我们深入研究测试驱动开发的好时机,这是编程时的一个重要概念。它涉及

  • Writing a test that fails
    编写失败的测试
  • Writing code to make it pass
    编写代码使其通过
  • Refactoring the code to make it readable
    重构代码以使其可读
  • REPEAT 重复

So let’s write a failing test
那么让我们编写一个失败的测试

#[cfg(test)]
mod tests{
  #[test]
  fn single_result_test(){
    let query = "dolor";
    let contents = "Lorem
ipsum
dolor
sit
amet";
    assert_eq!(vec!["dolor"], search(query,contents));
  }
}

We have not yet created the search function, and running the test command now will result in a compilation error because of that…
我们还没有创建搜索功能,现在运行测试命令将导致编译错误,因为......

So let’s create a search function
那么让我们创建一个搜索功能

pub fn search(query: &str, contents: &str) -> Vec<&str> {
  let mut results = Vec::new();
  for line in contents.lines(){
    if line.contains(query){
      results.push(line);
    }
  }
  results
}

As of now this function will give us an error to work with because out Vector is going to be tied to either query or contents and we haven’t specified the lifetime for it yet, so let’s do that
到目前为止,这个函数会给我们带来一个错误,因为 out Vector 将绑定到 query 或 contents 并且我们还没有指定它的生命周期,所以让我们这样做吧

pub fn search<'a>(query: &str, contents: &'a str) -> Vec<&'a str> {
  let mut results = Vec::new();
  for line in contents.lines(){
    if line.contains(query){
      results.push(line);
    }
  }
  results
}

Running the test now, will pass
现在运行测试,将通过

running 1 test
test tests::one_result ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running unittests src/main.rs (target/debug/deps/minigrep-35c886545281e89c)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests minigrep

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

Now that the search function works, lets use that in our run function
现在搜索功能可以工作了,让我们在运行功能中使用它

pub fn run(config: Config) -> Result<(), Box<dyn Error>>{
    let contents = fs::read_to_string(config.file)?;
    let result = search(&config.query, &contents);

    for lines in result {
        println!("{}",lines);
    }

    Ok(())
}

Running this program we get
运行这个程序我们得到

cargo run dolor lorem.txt

dolor

It works, but there is one major problem here
它可以工作,但是这里有一个主要问题
Our search logic is case sensitive, Let’s fix it
我们的搜索逻辑区分大小写,让我们修复它

Continuing TDD, let’s make a failing test and then work our way up
继续 TDD,让我们进行一次失败的测试,然后继续努力

#[test]
fn case_insensitive(){
  let query = "DoLoR";
  let contents = "Lorem
ipsum
dolor
sit
amet
DOLOR
DolOR
doLOR";
  assert_eq!(vec!["dolor","DOLOR","DolOR","doLOR"], search_case_insensitive(query,contents));
    }

This test will fail, because we don’t have the search_case_insensitive function as of now
这个测试将会失败,因为我们现在还没有 search_case_insensitive 函数

We will use most of the logic of the previous function here, and modify a few things
我们将在这里使用上一个函数的大部分逻辑,并修改一些内容

pub fn search_case_insensitive<'a>(query: &str, contents: &'a str) -> Vec<&'a str>{
    let mut results = Vec::new();
    let query = query.to_lowercase();
    for line in contents.lines(){
        if line.to_lowercase().contains(&query){
    results
}

The difference in logic is as follows:
逻辑上的区别如下:

search_case_insensitive: 搜索不区分大小写:

  • This function converts both the query and each line of the content to lowercase using the to_lowercase() method. This ensures that the comparison is case insensitive.
    此函数使用 to_lowercase() 方法将查询和每一行内容转换为小写。这确保了比较不区分大小写。
  • After converting the query and the line to lowercase, it checks if the lowercase version of the line contains the lowercase version of the query.
    将查询和行转换为小写后,它检查该行的小写版本是否包含查询的小写版本。
  • If a match is found, it doesn’t actually push the original line into the results vector. Instead, it returns an empty results vector, thus indicating that it didn’t store the original lines matching the case-insensitive query. There’s a missing line to push the matched line into results.
    如果找到匹配项,它实际上不会将原始行推入结果向量中。相反,它返回一个空结果向量,从而表明它没有存储与不区分大小写的查询匹配的原始行。缺少一行将匹配行推入 results 。

search: 搜索:

  • This function searches for the query within each line of the content without altering the case.
    此函数在内容的每一行中搜索查询,而不改变大小写。
  • It iterates over each line of the content, and for each line, it checks if the line contains the query.
    它迭代内容的每一行,并针对每一行检查该行是否包含查询。
  • If a match is found, it pushes the original line (in its original case) into the results vector.
    如果找到匹配项,它将原始行(在其原始情况下)推送到结果向量中。
  • It doesn’t perform any case conversion, so the search is case sensitive by default.
    它不执行任何大小写转换,因此默认情况下搜索区分大小写。

Environment variables 环境变量

Now that we have two search functions, our run function needs to know which function to call, but to do that we will add a boolean to the Config struct named case_sensitive
现在我们有两个搜索函数,我们的 run 函数需要知道要调用哪个函数,但为此,我们将向名为 case_sensitive

pub struct Config{
  pub query: String,
  pub file: String,
  pub case_sensitive: bool,
}

Then we will modify our run function to use the case_sensitive field…
然后我们将修改 run 函数以使用 case_sensitive 字段...

pub fn run(config: Config) -> Result<(), Box<dyn Error>>{
    let contents = fs::read_to_string(config.file)?;
    let result = if config.case_sensitive{
        search(&config.query, &contents);
    }else {
        search_case_insensitive(&config.query, &contents);
    }
    for lines in result {
        println!("{}",lines);
    }
    Ok(())
}

Now we modify the new function to use environment variables for case_sensitivity
现在我们修改新函数以使用 case_sensitivity 的环境变量

We need to have the env module in scope to use this functionality
我们需要在范围内包含 env 模块才能使用此功能

use std::env;
impl Config{
    pub fn new(args: &[String]) -> Result<Config, &str>{
        if args.len() < 3{
            return Err("Not enough arguments.");
        }
        let query: String = args[1].clone();
        let file: String = args[2].clone();
        let case_sensitive = env::var("CASE_INSENSITIVE").is_err();
        Ok(Config{query,file,case_sensitive})
    }
}

Now for the final step we need to display our errors to stderr instead of stdout
现在,最后一步我们需要将错误显示到 stderr 而不是 stdout
All out error handling is in the main.rs file so let’s get to it. This step is really easy, We just need to change out println! for eprintln!this redirects the output to stderr. This is useful when a user wants to send the output stream to a file, they can still see the errors on their terminal screen.
所有错误处理都在 main.rs 文件中,所以让我们开始吧。这一步非常简单,我们只需要将 println! 更改为 eprintln! 这会将输出重定向到 stderr. 这在用户想要发送输出时很有用流到文件,他们仍然可以在终端屏幕上看到错误。

Congratulations on creating your very first useful Rust program
恭喜您创建了第一个有用的 Rust 程序

Directory structure : 目录结构:

├── Cargo.lock
├── Cargo.toml
├── lorem.txt
├── src
│   ├── lib.rs
│   └── main.rs
└── target
    ├── CACHEDIR.TAG
    └── debug

Code: 代码:

lib.rs 库文件

use std::fs;
use std::error::Error;
use std::env;

pub struct Config {
    pub query: String,
    pub file: String,
    pub case_sensitive: bool,
}

impl Config{
    pub fn new(args: &[String]) -> Result<Config, &str>{
        if args.len() < 3{
            return Err("Not enough arguments.");
        }

        let query: String = args[1].clone();
        let file: String = args[2].clone();
        let case_sensitive = env::var("CASE_INSENSITIVE").is_err();

        Ok(Config{query,file,case_sensitive})
    }
}

pub fn run(config: Config) -> Result<(), Box<dyn Error>>{
    let contents = fs::read_to_string(config.file)?;
    let result = if config.case_sensitive{
        search(&config.query, &contents)
    }else {
        search_case_insensitive(&config.query, &contents)
    };

    for lines in result {
        println!("{}",lines);
    }

    Ok(())
}

pub fn search<'a>(query: &str, contents: &'a str) -> Vec<&'a str>{
    let mut results = Vec::new();
    for line in contents.lines() {
        if line.contains(query){
            results.push(line);
        }
    }
    results
}

pub fn search_case_insensitive<'a>(query: &str, contents: &'a str) -> Vec<&'a str>{
    let mut results = Vec::new();
    let query = query.to_lowercase();
    for line in contents.lines(){
        if line.to_lowercase().contains(&query){
            results.push(line);
        }
    }
    results
}

#[cfg(test)]
mod tests{
    use super::*;

    #[test]
    fn case_sensitive(){
        let query = "dolor";
        let contents = "Lorem
ipsum
dolor
DoloR
sit
amet";
        assert_eq!(vec!["dolor"], search(query,contents));
    }

    #[test]
    fn case_insensitive(){
        let query = "DoLoR";
        let contents = "Lorem
ipsum
dolor
sit
amet
DOLOR
DolOR
doLOR";
        assert_eq!(vec!["dolor","DOLOR","DolOR","doLOR"], search_case_insensitive(query,contents));
    }
}

main.rs 主程序.rs

use std::env;
use std::process;

use minigrep::Config;

fn main(){
    let args: Vec<String> = env::args().collect();

    let config = Config::new(&args).unwrap_or_else(|err|{
        eprintln!("Problem parsing arguments: {}",err);
        eprintln!("Expected: {} search_query filename", args[0]);
        process::exit(1);
    });

    if let Err(e) = minigrep::run(config) {
        eprintln!("Application error: {}",e);
        process::exit(1);
    }
}

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

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

相关文章

【ARM Cache 系列文章 11.2 -- ARM Cache 组相联映射】

请阅读【ARM Cache 系列文章专栏导读】 文章目录 Cache 组相联映射组相联映射原理多路组相连缓存的优势多路组相连缓存的代价关联度&#xff08;Associativity&#xff09; 上篇文章&#xff1a;【ARM Cache 系列文章 11.1 – ARM Cache 全相连 详细介绍】 Cache 组相联映射 A…

文章解读与仿真程序复现思路——电力自动化设备EI\CSCD\北大核心《计及多重不确定性的虚拟电厂响应区间评估方法》

本专栏栏目提供文章与程序复现思路&#xff0c;具体已有的论文与论文源程序可翻阅本博主免费的专栏栏目《论文与完整程序》 论文与完整源程序_电网论文源程序的博客-CSDN博客https://blog.csdn.net/liang674027206/category_12531414.html 电网论文源程序-CSDN博客电网论文源…

mysql-sql-练习题-4-标记

标记 连续登录2-7天用户建表排名找规律 最大连胜次数建表只输出连胜结果输出所有连续结果 连续登录2-7天用户 建表 create table continuous_login(user_id1 integer comment 用户id,date_login date comment 登陆日期 ) comment 用户登录表;insert into continuous_login val…

【Java基础】Spring核心之控制反转(IOC)

1. 如何理解IOC 1.1 什么是IOC 在Spring框架中&#xff0c;IOC&#xff08;Inversion of Control&#xff0c;控制反转&#xff09;是一种设计原则&#xff0c;它是Spring框架的核心概念之一。IOC的基本思想是将程序的控制权从应用程序代码中转移到框架或容器中&#xff0c;从…

c#数据库: 4.修改学生成绩

将4年级的学生成绩全部修改为100分,。修改前的学生信息表如图所示: using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks;namespace StudentUpdate {internal class Program{s…

C++:运算符重载-加号(+)

在C中&#xff0c;运算符重载允许重新定义已有运算符的行为&#xff0c;以便让它们适用于自定义类型。这样&#xff0c;你可以通过自定义类型使用内置运算符&#xff0c;使得代码更加直观和易读。 此时我在代码中定义一个新类MyString&#xff1a; class MyString { public:i…

MySQL常见问题解决和自动化安装脚本

常见问题 MySQL密码正确但无法登录的情况 这种情况一般都是因为缓存&#xff0c;使用mysql -u root -p123456直到成功登陆为止&#xff0c;并且进入之后重新修改密码&#xff0c;多次重复修改密码的命令并且再一次清除缓存后退出。 ALTER USER rootlocalhost IDENTIFIED WIT…

Microsoft Threat Modeling Tool 使用(二)

主界面 翻译 详细描述 选择了 “SDL TM Knowledge Base (Core)” 模板并打开了一个新的威胁模型。这个界面主要用于绘制数据流图&#xff08;Data Flow Diagram, DFD&#xff09;&#xff0c;它帮助您可视化系统的组成部分和它们之间的交互。以下是界面中各个部分的功能介绍&a…

CogAgent:开创性的VLM在GUI理解和自动化任务中的突破

尽管LLMs如ChatGPT在撰写电子邮件等任务上能够提供帮助&#xff0c;它们在理解和与GUIs交互方面存在挑战&#xff0c;这限制了它们在提高自动化水平方面的潜力。数字世界中的自主代理是许多现代人梦寐以求的理想助手。这些代理能够根据用户输入的任务描述自动完成如在线预订票务…

Bert基础(二十)--Bert实战:机器阅读理解任务

一、机器阅读理解任务 1.1 概念理解 机器阅读理解&#xff08;Machine Reading Comprehension, MRC&#xff09;就是给定一篇文章&#xff0c;以及基于文章的一个问题&#xff0c;让机器在阅读文章后对问题进行作答。 在机器阅读理解领域&#xff0c;模型的核心能力体现在对…

STM32使用PWM驱动直流电机

系列文章目录 STM32单片机系列专栏 C语言术语和结构总结专栏 文章目录 1. 直流电机和驱动简介 2. 驱动电路原理 3. 代码实现 3.1 PWM.c 3.2 PWM.h 3.3 MOTOR.c 3.4 MOTOR.h 3.5 main.c 3.6 完整工程文件 PWM和OC输出比较详解&#xff1a; STM32定时器的OC比较和PW…

LT6911GX HDMI2.1 至四端口 MIPI/LVDS,带音频 龙迅方案

1. 描述LT6911GX 是一款面向 VR / 显示应用的高性能 HDMI2.1 至 MIPI 或 LVDS 芯片。HDCP RX作为HDCP中继器的上游&#xff0c;可以与其他芯片的HDCP TX配合使用&#xff0c;实现中继器功能。对于 HDMI2.1 输入&#xff0c;LT6911GX 可配置为 3/4 通道。自适应均衡功能使其适合…

使用Github+Picgo+npm实现免费图床

本文参考自 Akilar&#xff0c;原文地址&#xff1a;https://akilar.top/posts/3e956346/ Picgo的配置 Github图床仓库内容不能超过1GB&#xff0c;因为Github原则上是反对仓库图床化的&#xff0c;超过1GB之后会由人工审核仓库内容&#xff0c;如果仓库被发现用来做图床&…

简要说说软分叉和硬分叉。

前言 一、软分叉 二、硬分叉 三、用途 总结 前言 软分叉和硬分叉是区块链技术中的两个重要概念&#xff0c;它们通常与加密货币的网络升级有关。下面我将分别解释这两个概念&#xff0c;并提供一些例子来帮助理解。下面是方便理解软分叉和硬分叉的图 一、软分叉 软分叉是一…

docker学习笔记4:CentOS7安装docker

文章目录 一、安装docker二、配置阿里云加速三、测试镜像安装本篇博客介绍如何在centos7里安装docker,关于CentOS7的安装可以查看本专栏的这篇博客: VmWare CentOS7安装与静态ip配置 centos7里安装docker步骤如下: 一、安装docker 先在终端输入su进入root用户,输入如下命…

Outlook大附件插件 有效解决附件大小限制问题

很多企业都是使用Outlook来进行邮件的收发&#xff0c;可是由于附件大小有限&#xff0c;导致很多大文件发不出去&#xff0c;就会产生Outlook大附件插件这种业务需求。 邮件系统在发送大文件时面临的限制问题主要如下&#xff1a; 1、附件大小限制&#xff1a;大多数邮件服务…

操作系统课程设计-人机交互的模拟操作系统

&#xff08;一&#xff09;课设板块 模块划分&#xff1a; &#xff08;1&#xff09;、进程管理模块 &#xff08;2&#xff09;、内存管理模块 &#xff08;3&#xff09;、文件管理模块 &#xff08;4&#xff09;、设备管理模块 &#xff08;5&#xff09;、界面管理模块…

Elasticsearch中【文档查询】DSL语句以及对应的Java实现

目录 全文检索查询 精准查询 布尔查询 排序、分页查询 高亮 地理查询 复合查询 Elasticsearch提供了基于JSON的DSL&#xff08;Domain Specific Language&#xff09;来定义查询。常见的查询类型包括&#xff1a; 查询所有&#xff1a;查询出所有数据&#xff0c;一般测…

C语言:项目实践(贪吃蛇)

前言&#xff1a; 相信大家都玩过贪吃蛇这款游戏吧&#xff0c;贪吃蛇是久负盛名的游戏&#xff0c;它也和俄罗斯方块&#xff0c;扫雷等游戏位列经典游戏的行列&#xff0c;那贪吃蛇到底是怎么实现的呢&#xff1f; 今天&#xff0c;我就用C语言带着大家一起来实现一下这款游戏…

Springboot+Vue项目-基于Java+MySQL的校园疫情防控系统(附源码+演示视频+LW)

大家好&#xff01;我是程序猿老A&#xff0c;感谢您阅读本文&#xff0c;欢迎一键三连哦。 &#x1f49e;当前专栏&#xff1a;Java毕业设计 精彩专栏推荐&#x1f447;&#x1f3fb;&#x1f447;&#x1f3fb;&#x1f447;&#x1f3fb; &#x1f380; Python毕业设计 &…