当前位置: 首页 > news >正文

J2EE征程——第一个纯servletCURD

第一个纯servletCURD

  • 前言
    • 在此之前
  • 一,概述
  • 二、CURD
    • 1介绍
    • 2查询并列表显示
      • 准备实体类country
      • 编写 CountryListServlet
      • 配置web.xml
      • 为web应用导入mysql-jdbc的jar包
    • 3增加
      • 准备增加的页面addc.html
      • 编写 CAddServlet
      • 配置web.xml
      • 测试
    • 4删除
      • 修改CountryListServlet(提供delete超链)
      • 编写CDeleteServlet
      • 配置web.xml
    • 5修改
      • 修改CountryListServlet (提供edit超链)
      • 准备CEditServlet(获取历史数据)
      • 准备CUpdateServlet(修改数据)
      • 配置web.xml
  • 三,总结

前言

很久以前便决定学习java了,那个时候还不知道J2EE到底是什么。逐渐地走了很远,才发现曾经遇到的、复现的java网站和赛题都只是一知半解。现如今总算是半只脚迈入了javaweb的大门,将成果分享一下,以供后来者参考。
注意:纯servlet项目和jsp项目有一定区别,后续学习若有成果会再次分享。

在此之前

说在前面,想要掌握CURD的基本知识需要一定基础,有关java的集合框架;servlet的部署、调用、request(response)方法;eclipse部署等要有一定了解(相信参考这篇文章学习的你已经掌握了上述知识)。

一,概述

Java2平台包括:标准版(J2SE)、企业版(J2EE)和微缩版(J2ME)三个版。
J2EE是简而言之,j2EE是一种网站开发标准或者说接口。

二、CURD

备注:表格结构
在这里插入图片描述mysql安装的示例类。这里把city和countrylanguage的外键都删除了,然后为country表新增了一个id列,保留了Name、SurfaceArea、Population这三个字段(String,int,float各一个),其他全部删除。
在这里插入图片描述

1介绍

CRUD是常见的页面功能,即我们常说的增删改查
C - Creation 增加
R - Retrieve 查询
U - Update 修改
D - DELETE 删除

备注:实体类一般定义在bean包中,DAO类一般定义在dao包中,Servlet一般定义在servlet包中,便于管理。

2查询并列表显示

准备实体类country

country表有Code、Name、Continent、Region、SurfaceArea、IndepYear、Population、LifeExpectancy、GNP、GNPOld、LocalName、GovernmentForm、HeadOfState、Capital、Code2等列名。
选择name、surfacearea、population三个(string、float、int各一个)作为country类的属性
并且为每一个属性提供public的getter和setter。

package world;
public class country {public int id;public String name;public float surfacearea;public int population;public int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public float getsurfacearea() {return surfacearea;}public void setsurfacearea(float surfacearea) {this.surfacearea = surfacearea;}public int getpopulation() {return population;}public void setpopulation(int population) {this.population = population;}}

准备一个CountryDAO,提供增加,删除,修改,查询等常规数据库操作方法
注意,查表的结果与字段顺序有关,若表结构更换,以下获取字段的序号都要更换。

package world;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;import world.country;public class countrydao {public countrydao() {try {Class.forName("com.mysql.jdbc.Driver");} catch (ClassNotFoundException e) {e.printStackTrace();}}public Connection getConnection() throws SQLException {return DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/world?characterEncoding=UTF-8", "root","123456");}public int getTotal() {int total = 0;try (Connection c = getConnection(); Statement s = c.createStatement();) {String sql = "select count(*) from country";ResultSet rs = s.executeQuery(sql);while (rs.next()) {total = rs.getInt(1);}System.out.println("total:" + total);} catch (SQLException e) {e.printStackTrace();}return total;}public void add(country country) {String sql = "insert into country values(null,?,?,?)";try (Connection c = getConnection(); PreparedStatement ps = c.prepareStatement(sql);) {ps.setString(1, country.name);ps.setFloat(2, country.surfacearea);ps.setInt(3, country.population);ps.execute();ResultSet rs = ps.getGeneratedKeys();if (rs.next()) {int id = rs.getInt(1);country.id = id;}} catch (SQLException e) {e.printStackTrace();}}public void update(country country) {String sql = "update country set name= ?, surfacearea = ? , population = ? where id = ?";try (Connection c = getConnection(); PreparedStatement ps = c.prepareStatement(sql);) {ps.setString(1, country.name);ps.setFloat(2, country.surfacearea);ps.setInt(3, country.population);ps.setInt(4, country.id);ps.execute();} catch (SQLException e) {e.printStackTrace();}}public void delete(int id) {try (Connection c = getConnection(); Statement s = c.createStatement();) {String sql = "delete from country where id = " + id;s.execute(sql);} catch (SQLException e) {e.printStackTrace();}}public country get(int id) {//返回值为country类的get方法country country = null;try (Connection c = getConnection(); Statement s = c.createStatement();) {String sql = "select * from country where id = " + id;ResultSet rs = s.executeQuery(sql);if (rs.next()) {country = new country();String name = rs.getString(2);//获取表的第3个列名float surfacearea = rs.getFloat("surfacearea");int population = rs.getInt(4);//获取表的第8个列名country.name = name;country.surfacearea = surfacearea;country.population = population;country.id = id;}} catch (SQLException e) {e.printStackTrace();}return country;}public List<country> list() {return list(0, Short.MAX_VALUE);}public List<country> list(int start, int count) {List<country> countries = new ArrayList<country>();String sql = "select * from country order by id desc limit ?,? ";try (Connection c = getConnection(); PreparedStatement ps = c.prepareStatement(sql);) {ps.setInt(1, start);ps.setInt(2, count);ResultSet rs = ps.executeQuery();while (rs.next()) {country country = new country();int id = rs.getInt(1);String name = rs.getString(2);float surfacearea = rs.getFloat("surfacearea");int population = rs.getInt(4);country.id = id;country.name = name;country.surfacearea = surfacearea;country.population = population;countries.add(country);}} catch (SQLException e) {e.printStackTrace();}return countries;}}

编写 CountryListServlet

做一个Country的维护页面需要一些通用的操作,比如增加,删除,编辑,修改,查询等。
每个不同的操作,都需要一个对应的Servlet,除了做Country之外,还会做到其他的一些表的相关操作,所以好的规范会对将来的维护更有好处。
一般会这样命名,以查询为例 CountryListServlet : [表][行为]Servlet 这样一种命名规则。
所以对于Country而言就会如此命名:
增加 CountryAddServlet
删除 CountryDeleteServlet
编辑 CountryEditServlet
修改 CountryUpdateServlet
查询 CountryListServlet
在CountryListServlet中,会使用CountryDAO把数据查询出来,然后拼接成一个table用于显示其内容

package world;import java.io.IOException;
import java.util.List;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import world.country;
import world.countrydao;public class CountryListServlet extends HttpServlet {protected void service(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {response.setContentType("text/html; charset=UTF-8");List<country> countries = new countrydao().list();StringBuffer sb = new StringBuffer();sb.append("<table align='center' border='1' cellspacing='0'>\r\n");sb.append("<tr><td>id</td><td>name</td><td>surfacearea</td><td>population</td></tr>\r\n");String trFormat = "<tr><td>%d</td><td>%s</td><td>%f</td><td>%d</td></tr>\r\n";for (country country : countries) {String tr = String.format(trFormat, country.getId(), country.getName(), country.getsurfacearea(), country.getpopulation());sb.append(tr);}sb.append("</table>");response.getWriter().write(sb.toString());}
}

配置web.xml

在web.xml中把路径 listHero映射到HeroListServlet上。

<?xml version="1.0" encoding="UTF-8"?>
<web-app><servlet><servlet-name>HelloServlet</servlet-name><servlet-class>HelloServlet</servlet-class><load-on-startup>10</load-on-startup></servlet><servlet-mapping><servlet-name>HelloServlet</servlet-name><url-pattern>/hello</url-pattern></servlet-mapping><servlet><servlet-name>LoginServlet</servlet-name><servlet-class>LoginServlet</servlet-class></servlet><servlet-mapping><servlet-name>LoginServlet</servlet-name><url-pattern>/login</url-pattern></servlet-mapping>   <servlet><servlet-name>RegisterServlet</servlet-name><servlet-class>RegisterServlet</servlet-class></servlet><servlet-mapping><servlet-name>RegisterServlet</servlet-name><url-pattern>/register</url-pattern></servlet-mapping><servlet><servlet-name>CountryListServlet</servlet-name><servlet-class>world.CountryListServlet</servlet-class></servlet><servlet-mapping><servlet-name>CountryListServlet</servlet-name><url-pattern>/listc</url-pattern></servlet-mapping>   </web-app>

为web应用导入mysql-jdbc的jar包

把 mysql 的jar包放在WEB-INF/lib 目录下
放在WEB-INF/lib 下指的是能够web应用中找到对应的class,如果要在eclipse中做调试,还是需要为项目添加该jar才可以。

3增加

准备增加的页面addc.html

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

表示用UTF-8显示中文,同时浏览器也会使用UTF-8编码提交中文
form:
action设置为addHero路径
method设置为post 也是为了提交中文
在web目录下添加

<!DOCTYPE html><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><form action="addc" method="post">国家名称 : <input type="text" name="name"> <br>国土面积: <input type="text" name="surfacearea"> <br>人口数量: <input type="text" name="population"> <br><input type="submit" value="增加 ">
</form>

在这里插入图片描述

编写 CAddServlet

HeroAddServlet 中根据浏览器传过来的参数,创建一个Hero对象。 接着通过HeroDAO把该对象保存到数据库中。
最后使用客户端跳转到listHero查看所有的Hero,就能看到新加入的Hero对象了
request.setCharacterEncoding(“UTF-8”);
表示使用UTF-8的方式获取浏览器传过来的中文

package world;import java.io.IOException;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import world.country;
import world.countrydao;public class CAddServlet extends HttpServlet {protected void service(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {request.setCharacterEncoding("UTF-8");country country = new country();country.setName(request.getParameter("name"));country.setsurfacearea(Float.parseFloat(request.getParameter("surfacearea")));country.setpopulation(Integer.parseInt(request.getParameter("population")));new countrydao().add(country);response.sendRedirect("/j2ee/listc");}
}

配置web.xml

    <servlet><servlet-name>HeroAddServlet</servlet-name><servlet-class>servlet.HeroAddServlet</servlet-class></servlet><servlet-mapping><servlet-name>HeroAddServlet</servlet-name><url-pattern>/addHero</url-pattern></servlet-mapping>    

测试

重启tomcat,访问增加页面http://127.0.0.1/addc.html
提交数据,接着客户端跳转到/j2ee/lisc,就可以显示新增加的这条数据了
在这里插入图片描述

4删除

修改CountryListServlet(提供delete超链)

修改CountryListServlet,多一个单元格,是一个超链
超链的href属性指向地址 /deleteC?id=242(每条不同的记录id不一样)
可以在左下角的浏览器状态栏里看到

package world;import java.io.IOException;
import java.util.List;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import world.country;
import world.countrydao;public class CountryListServlet extends HttpServlet {protected void service(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {response.setContentType("text/html; charset=UTF-8");List<country> countries = new countrydao().list();StringBuffer sb = new StringBuffer();sb.append("<table align='center' border='1' cellspacing='0'>\r\n");sb.append("<tr><td>id</td><td>name</td><td>surfacearea</td><td>population</td><td>delete</td></tr>\r\n");String trFormat = "<tr><td>%d</td><td>%s</td><td>%f</td><td>%d</td><td><a href='deletec?id=%d'>delete</a></td></tr>\r\n";for (country country : countries) {String tr = String.format(trFormat, country.getId(), country.getName(), country.getsurfacearea(), country.getpopulation(), country.getId());sb.append(tr);}sb.append("</table>");response.getWriter().write(sb.toString());}
}

在这里插入图片描述

编写CDeleteServlet

首先获取参数id
然后通过countrydao根据id,删除该对象
然后客户端跳转到 /listc

package world;import java.io.IOException;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import world.country;public class CDeleteServlet extends HttpServlet {protected void service(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {int id = Integer.parseInt(request.getParameter("id"));new countrydao().delete(id);response.sendRedirect("/j2ee/listc");}
}

配置web.xml

把/deletec指向CDeleteServlet

<servlet><servlet-name>CDeleteServlet</servlet-name><servlet-class>world.CDeleteServlet</servlet-class></servlet><servlet-mapping><servlet-name>CDeleteServlet</servlet-name><url-pattern>/deletec</url-pattern></servlet-mapping>    

在这里插入图片描述

5修改

修改CountryListServlet (提供edit超链)

新增加一列 edit,里面放上指向 /edit的超链

package world;import java.io.IOException;
import java.util.List;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import world.country;
import world.countrydao;public class CountryListServlet extends HttpServlet {protected void service(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {response.setContentType("text/html; charset=UTF-8");List<country> countries = new countrydao().list();StringBuffer sb = new StringBuffer();sb.append("<table align='center' border='1' cellspacing='0'>\r\n");sb.append("<tr><td>id</td><td>name</td><td>surfacearea</td><td>population</td><td>edit</td><td>delete</td></tr>\r\n");String trFormat = "<tr><td>%d</td><td>%s</td><td>%f</td><td>%d</td><td><a href='edit?id=%d'>edit</a></td><td><a href='deletec?id=%d'>delete</a></td></tr>\r\n";for (country country : countries) {String tr = String.format(trFormat, country.getId(), country.getName(), country.getsurfacearea(), country.getpopulation(), country.getId(), country.getId());sb.append(tr);}sb.append("</table>");response.getWriter().write(sb.toString());}
}

在这里插入图片描述

准备CEditServlet(获取历史数据)

CEditServlet 根据浏览器传过来的id获取一个country对象
然后根据这个对象,准备一个类似add.html的页面,不同之处在于每个输入框都是有值的。
最后还会提供一个type="hidden"的input,用于提交id到路径/update

package world;import java.io.IOException;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import world.country;
import world.countrydao;public class CEditServlet extends HttpServlet {protected void service(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {int id = Integer.parseInt(request.getParameter("id"));country country = new countrydao().get(id);StringBuffer format = new StringBuffer();response.setContentType("text/html; charset=UTF-8");format.append("<!DOCTYPE html>");format.append("<form action='update' method='post'>");format.append("国家名称: <input type='text' name='name' value='%s' > <br>");format.append("国土面积: <input type='text' name='surfacearea'  value='%f' > <br>");format.append("人口数量: <input type='text' name='population'  value='%d' > <br>");format.append("<input type='hidden' name='id' value='%d'>");format.append("<input type='submit' value='更新'>");format.append("</form>");String html = String.format(format.toString(), country.getName(), country.getsurfacearea(), country.getpopulation(), country.getId());response.getWriter().write(html);}
}

在这里插入图片描述

准备CUpdateServlet(修改数据)

package world;import java.io.IOException;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import world.country;
import world.countrydao;public class CUpdateServlet extends HttpServlet {protected void service(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {request.setCharacterEncoding("UTF-8");country country = new country();country.setId(Integer.parseInt(request.getParameter("id")));country.setName(request.getParameter("name"));country.setsurfacearea(Float.parseFloat(request.getParameter("surfacearea")));country.setpopulation(Integer.parseInt(request.getParameter("population")));new countrydao().update(country);response.sendRedirect("/j2ee/listc");}
}

在这里插入图片描述

配置web.xml

    <servlet><servlet-name>CEditServlet</servlet-name><servlet-class>world.CEditServlet</servlet-class></servlet><servlet-mapping><servlet-name>CEditServlet</servlet-name><url-pattern>/edit</url-pattern></servlet-mapping><servlet><servlet-name>CUpdateServlet</servlet-name><servlet-class>world.CUpdateServlet</servlet-class></servlet><servlet-mapping><servlet-name>CUpdateServlet</servlet-name><url-pattern>/update</url-pattern></servlet-mapping>

三,总结

以上便是整个CURD案例的全部源代码了,每一步都有详细的介绍,虽然参考了其他的学习案例,但是本测试是根据mysql的案例类专门设计的。测试的过程中,基本把所有的报错都踩了一边,略有感慨,小写一篇文章以分享和记录。

相关文章:

J2EE征程——第一个纯servletCURD

第一个纯servletCURD 前言在此之前 一&#xff0c;概述二、CURD1介绍2查询并列表显示准备实体类country编写 CountryListServlet配置web.xml为web应用导入mysql-jdbc的jar包 3增加准备增加的页面addc.html编写 CAddServlet配置web.xml测试 4删除修改CountryListServlet&#xf…...

BatchOutput PDF for Mac(PDF 批量处理软件)

BatchOutput PDF是一款适用于 Mac 的 PDF 批量处理软件。它可以帮助用户将多个 PDF 文件进行异步处理&#xff0c;提高工作效率。 BatchOutput PDF 可以自动化执行许多任务&#xff0c;包括 PDF 文件的打印、转换、分割、压缩、加密、重命名等&#xff0c;而且它还可以将自定义…...

记一次oracle错误处理

16:00:05 SQL> alter database open; alter database open * 第 1 行出现错误: ORA-01589: 要打开数据库则必须使用 RESETLOGS 或 NORESETLOGS 选项 16:00:49 SQL> startup ORA-01081: 无法启动已在运行的 ORACLE - 请首先关闭它 16:02:56 SQL> shutdown immediate O…...

hugging face下载dataset时候出现You must be authenticated to access it.问题解决

Cannot access gated repo for url https://huggingface.co/tiiuae/falcon-180B/resolve/main/tokenizer_config.json. Repo model tiiuae/falcon-180B is gated. You must be authenticated to access it. 参考https://huggingface.co/docs/huggingface_hub/guides/download …...

数据结构---树

树概念及结构 1.树的概念 树是一种非线性的数据结构&#xff0c;它是由n&#xff08;n>0&#xff09;个有限结点组成一个具有层次关系的集合。把它叫做树是因 为它看起来像一棵倒挂的树&#xff0c;也就是说它是根朝上&#xff0c;而叶朝下的 有一个特殊的结点&#xff0c…...

tomcat调优配置

一. 设置账户进入管理页面 通过浏览器进入Tomcat7的管理模块页面&#xff1a;http://localhost:8080/manager/status 按照提示&#xff0c;在Tomcat7服务器指定的位置修改配置文件&#xff08;conf/tomcat-users.xml&#xff09;&#xff0c;增加相应的用户和角色配置标签 <…...

基于深度学习的点云三维目标检测方法综述

论文标题&#xff1a;基于深度学习的点云三维目标检测方法综述 作者&#xff1a;郭毅锋&#xff11;&#xff0c;&#xff12;†&#xff0c;吴帝浩&#xff11;&#xff0c;魏青民&#xff11; 发表日期&#xff1a; 2023 1 阅读日期 &#xff1a;2023 11 29 研究背景&…...

Linux命令中的符号

目录 1 管道符 | 1.1 | grep [要检索的东西] 1.2 echo | tee 2 重定向 2.1 输出重定向覆盖 > 2.2 输出重定向添加 >> 2.3 文件输入重定向 < 2.4 多行文本输入重定向 << 2.5 常用搭配 2.5.1 终端不显示 > /dev/null 1 管道符 | 我们…...

BTCPay Server:免费、安全、开源的比特币支付处理器 | 开源日报 No.90

MunGell/awesome-for-beginners Stars: 58.0k License: NOASSERTION 这个项目是一个收集开源项目的列表&#xff0c;旨在帮助初学者找到可以贡献代码的机会。该列表按编程语言分类&#xff0c;并列出了每个项目以及其标签 (如 “good-first-issue”、“beginner” 等)。主要功…...

【数据挖掘】国科大刘莹老师数据挖掘课程作业 —— 第三次作业

Written Part 1. 基于表 1 1 1 回答下列问题&#xff08;min_sup40%, min_conf75%&#xff09;&#xff1a; Transaction IDItems Bought0001{a, d, e}0024{a, b, c, e}0012{a, b, d, e}0031{a, c, d, e}0015{b, c, e}0022{b, d, e}0029{c, d}0040{a, b, c}0033{a, d, e}0038…...

Windows挂载NFS

ubuntu开启nfs 安装 sudo apt install nfs-kernel-server编辑 /etc/exports /data/share *(rw,no_root_squash)重启服务 sudo systemctl restart nfs-server.service验证 showmount -e localhostwindows连接NFS 选择控制面板 > 程序 > 启用或关闭 Windows 功能 添加…...

数据结构第五课 -----二叉树的代码实现

作者前言 &#x1f382; ✨✨✨✨✨✨&#x1f367;&#x1f367;&#x1f367;&#x1f367;&#x1f367;&#x1f367;&#x1f367;&#x1f382; ​&#x1f382; 作者介绍&#xff1a; &#x1f382;&#x1f382; &#x1f382; &#x1f389;&#x1f389;&#x1f389…...

优橙内推北京专场——5G网络优化(中高级)工程师

可加入就业QQ群&#xff1a;801549240 联系老师内推简历投递邮箱&#xff1a;hrictyc.com 内推公司1&#xff1a;西安长河通讯有限责任公司 内推公司2&#xff1a;北京电旗通讯技术股份有限公司 内推公司3&#xff1a;润建股份有限公司 西安长河通讯有限责任公司 西安长河…...

Mysql DDL语句建表及空字符串查询出0问题

DDL语句建表 语法&#xff1a; create table 指定要建立库的库名.新建表名 &#xff08;... 新建表的字段以及类型等 ...&#xff09;comment 表的作用注释 charset 表编译格式 row_format DYNAMIC create table dev_dxtiot.sys_url_permission (id integer …...

深入ArkTS:应用状态管理与LocalStorage装饰器详解【鸿蒙专栏-11】

文章目录 ArkTS 应用状态管理详解LocalStorage: 页面级 UI 状态存储使用规则概述:装饰器详解:限制条件:使用场景:1. 应用逻辑使用 LocalStorage2. 从 UI 内部使用 LocalStorageArkTS 应用状态管理进阶LocalStorage 装饰器详解1. @LocalStorageProp2. @LocalStorageLink观察…...

管理Android12系统的WLAN热点

大家好!我是编码小哥,欢迎关注,持续分享更多实用的编程经验和开发技巧,共同进步。 要创建一个APK管理Android 12系统的WLAN热点,你需要遵循以下步骤: 1. 获取必要的权限和API访问权限。在AndroidManifest.xml文件中添加以下权限: ```xml <uses-permission android:…...

从0开始学习JavaScript--JavaScript 中 `let` 和 `const` 的区别及最佳实践

在JavaScript中&#xff0c;let 和 const 是两个用于声明变量的关键字。尽管它们看起来很相似&#xff0c;但它们之间有一些重要的区别。本篇博客将深入探讨 let 和 const 的用法、区别&#xff0c;并提供一些最佳实践&#xff0c;以确保在代码中正确使用它们。 let 和 const …...

【上海大学数字逻辑实验报告】二、组合电路(一)

一、 实验目的 熟悉TTL异或门构成逻辑电路的基本方式&#xff1b;熟悉组合电路的分析方法&#xff0c;测试组合逻辑电路的功能&#xff1b;掌握构造半加器和全加器的逻辑测试&#xff1b;学习使用可编程逻辑器件的开发工具 Quartus II设计电路。 二、 实验原理 异或门是数字…...

lodash中foreach踩坑

什么是lodash Lodash 是一个 JavaScript 实用工具库&#xff0c;提供了很多用于处理数据、简化开发等方面的功能。它提供了一组常用的工具函数&#xff0c;用于处理数组、对象、字符串等常见数据结构&#xff0c;同时也包含了一些函数式编程的工具。对于前端开发来说&#xff…...

Unity C++交互

一、设置Dll输出。 两种方式&#xff1a; 第一&#xff1a;直接创建动态链接库工程第二&#xff1a;创建的是可执行程序&#xff0c;在visual studio&#xff0c;右键项目->属性(由exe改成dll) 二、生成Dll 根据选项Release或Debug&#xff0c;运行完上面的生成解决方案后…...

华为云AI开发平台ModelArts

华为云ModelArts&#xff1a;重塑AI开发流程的“智能引擎”与“创新加速器”&#xff01; 在人工智能浪潮席卷全球的2025年&#xff0c;企业拥抱AI的意愿空前高涨&#xff0c;但技术门槛高、流程复杂、资源投入巨大的现实&#xff0c;却让许多创新构想止步于实验室。数据科学家…...

MPNet:旋转机械轻量化故障诊断模型详解python代码复现

目录 一、问题背景与挑战 二、MPNet核心架构 2.1 多分支特征融合模块(MBFM) 2.2 残差注意力金字塔模块(RAPM) 2.2.1 空间金字塔注意力(SPA) 2.2.2 金字塔残差块(PRBlock) 2.3 分类器设计 三、关键技术突破 3.1 多尺度特征融合 3.2 轻量化设计策略 3.3 抗噪声…...

51c自动驾驶~合集58

我自己的原文哦~ https://blog.51cto.com/whaosoft/13967107 #CCA-Attention 全局池化局部保留&#xff0c;CCA-Attention为LLM长文本建模带来突破性进展 琶洲实验室、华南理工大学联合推出关键上下文感知注意力机制&#xff08;CCA-Attention&#xff09;&#xff0c;…...

【位运算】消失的两个数字(hard)

消失的两个数字&#xff08;hard&#xff09; 题⽬描述&#xff1a;解法&#xff08;位运算&#xff09;&#xff1a;Java 算法代码&#xff1a;更简便代码 题⽬链接&#xff1a;⾯试题 17.19. 消失的两个数字 题⽬描述&#xff1a; 给定⼀个数组&#xff0c;包含从 1 到 N 所有…...

AtCoder 第409​场初级竞赛 A~E题解

A Conflict 【题目链接】 原题链接&#xff1a;A - Conflict 【考点】 枚举 【题目大意】 找到是否有两人都想要的物品。 【解析】 遍历两端字符串&#xff0c;只有在同时为 o 时输出 Yes 并结束程序&#xff0c;否则输出 No。 【难度】 GESP三级 【代码参考】 #i…...

Mac软件卸载指南,简单易懂!

刚和Adobe分手&#xff0c;它却总在Library里给你写"回忆录"&#xff1f;卸载的Final Cut Pro像电子幽灵般阴魂不散&#xff1f;总是会有残留文件&#xff0c;别慌&#xff01;这份Mac软件卸载指南&#xff0c;将用最硬核的方式教你"数字分手术"&#xff0…...

EtherNet/IP转DeviceNet协议网关详解

一&#xff0c;设备主要功能 疆鸿智能JH-DVN-EIP本产品是自主研发的一款EtherNet/IP从站功能的通讯网关。该产品主要功能是连接DeviceNet总线和EtherNet/IP网络&#xff0c;本网关连接到EtherNet/IP总线中做为从站使用&#xff0c;连接到DeviceNet总线中做为从站使用。 在自动…...

WPF八大法则:告别模态窗口卡顿

⚙️ 核心问题&#xff1a;阻塞式模态窗口的缺陷 原始代码中ShowDialog()会阻塞UI线程&#xff0c;导致后续逻辑无法执行&#xff1a; var result modalWindow.ShowDialog(); // 线程阻塞 ProcessResult(result); // 必须等待窗口关闭根本问题&#xff1a…...

十九、【用户管理与权限 - 篇一】后端基础:用户列表与角色模型的初步构建

【用户管理与权限 - 篇一】后端基础:用户列表与角色模型的初步构建 前言准备工作第一部分:回顾 Django 内置的 `User` 模型第二部分:设计并创建 `Role` 和 `UserProfile` 模型第三部分:创建 Serializers第四部分:创建 ViewSets第五部分:注册 API 路由第六部分:后端初步测…...

vue3 daterange正则踩坑

<el-form-item label"空置时间" prop"vacantTime"> <el-date-picker v-model"form.vacantTime" type"daterange" start-placeholder"开始日期" end-placeholder"结束日期" clearable :editable"fal…...