SpringBoot学习笔记-4:第四章 Spring Boot Web 开发
第四章 Spring Boot Web 开发
1、web 开发简介
https://start.spring.io/
- 创建 SpringBoot 应用,选中需要的模块
- 使用 SpringBoot 自动配置
- 编写业务代码
@AutoConfiguration 自动配置组件
@Properties 封装配置文件的内容
webjars&静态资源映射规则
1、webjars
配置类:WebMvcAutoConfiguration
webjars 以 jar 包的方式引入静态资源
https://www.webjars.org/
资源路径映射
/webjars/**=>classpath:/META-INF/resources/webjars/
添加 jquery 依赖
<dependency><groupId>org.webjars</groupId><artifactId>jquery</artifactId><version>3.5.1</version>
</dependency>
访问路径
/webjars/jquery/3.5.1/jquery.js
2、静态资源映射规则
静态资源文件夹
classpath:/META-INF/resources/
classpath:/resources/
classpath:/static/
classpath:/public/
/ 当前项目根路径
默认静态文件下查找
# 欢迎页面
index.html# 图标路径
favicon.ico
自定义静态资源文件路径,默认资源路径失效
spring.resources.static-locations=classpath:/hello/
引入 thymeleaf
JSP、Velocity、Thymeleaf、Freemarker
模板引擎
Template ${name} + Data {"name": "Tom"}=> TemplateEngine =>output
Thymeleaf 依赖
<properties><java.version>1.8</java.version><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><!-- 切换 thymeleaf version --><!-- thymeleaf3 适配 layout2 --><springboot-thymeleaf.version>2.1.1.RELEASE</springboot-thymeleaf.version><thymeleaf-layout-dialect.version>2.0.0</thymeleaf-layout-dialect.version>
</properties><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId><version>${springboot-thymeleaf.version}</version>
</dependency>
thymeleaf 语法
https://www.thymeleaf.org/
默认配置
public class ThymeleafProperties {private String prefix = "classpath:/templates/";private String suffix = ".html";
}
模板使用示例
package com.example.demo.controller;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;import java.util.HashMap;@Controller
public class IndexController {@RequestMapping("/hello")public String hello(HashMap<String, Object> map){map.put("name", "Tom");// 模板路径// src/main/resources/templates/about.htmlreturn "hello";}
}
模板:
src/main/resources/templates/about.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"><head><meta charset="UTF-8" /><title>Title</title></head><body><h1>Hello</h1><!-- 设置文本内容 --><div th:text="${name}"></div></body>
</html>
语法规则
th: 任意html属性,用来替换原生属性的值th:text 改变文本内容(转义)
th:utext 改变文本内容(不转义)th:attr
th:href
th:srcth:each
th:for
表达式
${} 变量表达式获取变量值获取变量属性调用方法内置基本对象: #ctx #session...内置工具对象:*{} 选择表达式配合th:object使用#{} 获取国际化内容@{} 定义url~{} 片段表达式字面量
数学运算
布尔运算
比较运算
条件运算
特殊操作
示例
<!--文本输出-->
<div th:text="${name}"></div><!--循环遍历-->
<div th:each="pet: ${pets}"><div>[[${pet}]]</div>
</div><!--循环遍历-->
<div th:each="pet: ${pets}" th:text="pet"></div>
SpringMVC 自动配置原理
SpringBoot 对 SpringMVC 默认配置
自动配置
ViewResolver 视图解析器
根据方法返回值的到视图对象(View)
视图对象决定如何渲染、转发、重定向Converter 类型转换器
Formatter 格式化器
HttpMessageConverters 转换请求响应
MessageCodesResolver 定义错误代码生成规则
WebDataBinder 数据绑定器
修改 SpringBoot 默认配置
优先使用用户配置@Bean/@Component
如果没有才自动配置
有些组件可以有多个
eg: ViewResolver 将用户配置和默认配置组合起来
扩展与全面接管 SpringMVC
1、扩展配置
package com.example.demo.config;import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;@Configuration
public class CustomVmcConfig extends WebMvcConfigurerAdapter {@Overridepublic void addViewControllers(ViewControllerRegistry registry) {// super.addViewControllers(registry);// 浏览器的请求 /demo 到视图 /helloregistry.addViewController("demo").setViewName("hello");}
}
2、全面接管
增加 @EnableWebMvc
后,自动配置失效
package com.example.demo.config;import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;@EnableWebMvc
@Configuration
public class CustomVmcConfig extends WebMvcConfigurerAdapter {@Overridepublic void addViewControllers(ViewControllerRegistry registry) {// super.addViewControllers(registry);// 浏览器的请求 /demo 到视图 /helloregistry.addViewController("demo").setViewName("hello");}
}
引入资源
模板资源: https://getbootstrap.net/
模板语法: https://www.thymeleaf.org/
webjars: https://www.webjars.org/
目录设置
resources/templates 模板文件static 静态文件
首页设置
package com.example.demo.config;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;@Configuration
public class CustomVmcConfig extends WebMvcConfigurerAdapter {// 设置首页位置,默认访问 public/index.html 没有经过模板引擎处理@Beanpublic WebMvcConfigurerAdapter CustomVmcConfig() {WebMvcConfigurerAdapter adapter = new WebMvcConfigurerAdapter() {@Overridepublic void addViewControllers(ViewControllerRegistry registry) {registry.addViewController("/").setViewName("login");registry.addViewController("/index.html").setViewName("login");}};return adapter;}
}
国际化
默认根据浏览器语言获取对应国际化信息
1、配置语言文件
resources 资源文件夹下
├── i18n
│ ├── login.properties
│ ├── login_en_US.properties
│ └── login_zh_CN.properties
默认配置 login.properties
login.button=登录~
login.title=登录~
login.username=用户名~
login.password=密码~
login.remember=记住我~
英文配置 login_en_US.properties
login.button=Sign In
login.title=Login
login.username=UserName
login.password=Password
login.remember=Remenber Me
中文配置 login_zh_CN.properties
login.button=登录
login.title=登录
login.username=用户名
login.password=密码
login.remember=记住我
2、配置 application.yml
spring:messages:basename: i18n.login
3、模板文件中使用
<button th:text="#{login.button}"></button>
根据浏览器请求头设置语言
GET http://localhost:8080/
Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7
4、自定义国际化处理器
package com.example.demo.component;import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;/*** 区域信息解析器* 自定义国际化参数,支持链接上携带区域信息*/
public class MyLocaleResolver implements LocaleResolver {@Overridepublic Locale resolveLocale(HttpServletRequest request) {String lang = request.getParameter("lang");Locale locale = Locale.getDefault();if (!StringUtils.isEmpty(lang)) {String[] list = lang.split("_");if (list.length == 2) {locale = new Locale(list[0], list[1]);}}return locale;}@Overridepublic void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {}
}
启用自定义国际化处理器
package com.example.demo.config;import com.example.demo.component.MyLocaleResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;/*** 配置首页视图*/
@Configuration
public class CustomVmcConfig extends WebMvcConfigurerAdapter {@Beanpublic MyLocaleResolver localeResolver() {return new MyLocaleResolver();}
}
优先获取查询参数返回语言设置
http://localhost:8080/?lang=zh_CN
http://localhost:8080/?lang=en_US
登陆&拦截器
开发期间模板引擎修改要实时生效
- 禁用模板引擎缓存
- 重新编译
<!--登录错误消息提示-->
<pstyle="color: red;"th:text="${msg}"th:if="${not #strings.isEmpty(msg)}"
></p>
拦截器进行登录检查
登录
package com.example.demo.controller;import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;import javax.servlet.http.HttpSession;
import java.util.Map;@Controller
public class LoginController {@PostMapping("/user/login")// 等价于 @RequestMapping(value = "/user/login", method = {RequestMethod.POST})public String login(@RequestParam("username") String username,@RequestParam("password") String password,Map<String, Object> map,HttpSession session) {if (!StringUtils.isEmpty(username) && "123".equals(password)) {session.setAttribute("loginUser", username);// 登录成功 防止表单重新提交,做一个重定向return "redirect:/dashboard.html";} else {// 登录失败map.put("msg", "账号或密码不正确");return "login";}}
}
拦截器
package com.example.demo.component;import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;/*** 登录检查*/
public class LoginHandlerInterceptor implements HandlerInterceptor {@Overridepublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {Object loginUser = request.getSession().getAttribute("loginUser");// 未登录,返回登录页面if (loginUser == null) {request.setAttribute("msg", "没有权限,请先登录");request.getRequestDispatcher("/index.html").forward(request, response);return false;}// 已登录,放行else {return true;}}@Overridepublic void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {}@Overridepublic void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {}
}
注册拦截器
package com.example.demo.config;import com.example.demo.component.LoginHandlerInterceptor;
import com.example.demo.component.MyLocaleResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;/*** 配置首页视图*/@Configuration
@SuppressWarnings("all")
public class CustomVmcConfig extends WebMvcConfigurerAdapter {// 设置首页位置,默认访问 public/index.html 没有经过模板引擎处理@Beanpublic WebMvcConfigurerAdapter CustomVmcConfig() {WebMvcConfigurerAdapter adapter = new WebMvcConfigurerAdapter() {/*** 注册视图控制器* @param registry*/@Overridepublic void addViewControllers(ViewControllerRegistry registry) {registry.addViewController("/").setViewName("login");registry.addViewController("/index.html").setViewName("login");registry.addViewController("/dashboard.html").setViewName("dashboard");}/*** 注册拦截器* @param registry*/@Overridepublic void addInterceptors(InterceptorRegistry registry) {// super.addInterceptors(registry);// 拦截任意路径下的所有请求, 排除请求registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**").excludePathPatterns("/index.html", "/", "/user/login", "/static/**");}};return adapter;}}
Restful CRUD
Rest 风格
URI: /资源/资源标识 HTTP 请求方式区分对资源 CRUD
说明 | 普通 CRUD(URI 区分操作) | RestfulCRUD |
---|---|---|
查询 | getEmp | GET emp |
添加 | addEmp | POST emp |
修改 | updateEmp?id=1 | PUT emp/{id} |
删除 | deleteEmp?id=1 | DELETE emp/{id} |
查询接口定义
说明 | 请求方式 | 请求 URI |
---|---|---|
查询所有员工 | GET | emps |
查询某个员工 | GET | emp/{id} |
添加页面 | GET | emp |
添加员工 | POST | emp |
修改页面 | GET | emp/{id} |
修改员工 | PUT | emp |
删除员工 | DELETE | emp/{id} |
员工列表-公共页抽取
公共片段抽取
<!-- 1、抽取公共片段 -->
<div th:fragment="copy">content</div><!-- 2、引入公共片段 -->
<div th:insert="~{footer::copy}">content</div><!-- 3、默认效果 -->
<!-- insert功能片段在div标签中 -->
~{templateName::selector} 模板名::选择器
~{templateName::fragmentName}模板名::片段名
3 种方式引入片段
th:insert 插入
th:replace 替换
th:include 引入片段内容使用th:insert可以不写~{}
转义[[~{}]]
不转义[(~{})]
引入片段时候传入参数
链接高亮&列表完成
redirect 重定向
forward 转发
日期格式化
spring.mvc.format.date: yyyy-MM-dd
HiddenHttpMethodFilter
SpringMVC 中配置 HiddenHttpMethodFilter
页面创建一个 Post 表单
创建一个 input 项 name="_method",值就是请求方式
<input type="hidden" name="_method" value="put" th:if="${emp!=null}" />
有些版本可能需要配置
application.yml
spring.mvc.hiddenmethod.filter.enabled = true
错误页面
ErrorMvcAutoConfiguration
有模板引擎的情况下
error/状态码eg:
精确匹配
error/404.html模糊匹配
error/4xx.html
error/5xx.html
自定义异常处理
1、返回 JSON 数据
package com.example.demo.controller;import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;import java.util.HashMap;
import java.util.Map;@ControllerAdvice
public class ExceptionController {@ResponseBody@ExceptionHandlerpublic Map<String, Object> handleException(Exception e){Map<String, Object> map = new HashMap<>();map.put("code", -1);map.put("msg", e.getMessage());return map;}
}
{"msg": "用户不存在","code": -1
}
嵌入式 Servlet 容器配置修改
Tomcat
通用配置
# servlet配置
server.port=8001
server.context-path=/demo# Tomcat配置
server.tomcat.uri-encoding=UTF-8
注册 servlet 三大组件
Servlet/Filter/Listener
1、Servlet
package com.example.demo.servlet;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;public class MyServlet extends HttpServlet {@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {resp.getWriter().println("MyServlet");}
}
2、Filter
package com.example.demo.filter;import javax.servlet.*;
import java.io.IOException;public class MyFilter implements Filter {@Overridepublic void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {System.out.println("MyFilter");chain.doFilter(request, response);}
}
3、Listener
package com.example.demo.listener;import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;public class MyListener implements ServletContextListener {@Overridepublic void contextInitialized(ServletContextEvent sce) {System.out.println("contextInitialized");}@Overridepublic void contextDestroyed(ServletContextEvent sce) {System.out.println("contextDestroyed");}
}
注册组件
package com.example.demo.config;import com.example.demo.filter.MyFilter;
import com.example.demo.listener.MyListener;
import com.example.demo.servlet.MyServlet;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;import java.util.Arrays;/*** 注册Servlet/Filter/Listener组件*/
@Configuration
public class MyServletConfig {@Beanpublic ServletRegistrationBean myServlet(){ServletRegistrationBean registrationBean = new ServletRegistrationBean();registrationBean.setServlet(new MyServlet());registrationBean.setUrlMappings(Arrays.asList("/servlet"));return registrationBean;}@Beanpublic FilterRegistrationBean myFilter(){FilterRegistrationBean registrationBean = new FilterRegistrationBean();registrationBean.setFilter(new MyFilter());registrationBean.setUrlPatterns(Arrays.asList("/servlet"));return registrationBean;}@Beanpublic ServletListenerRegistrationBean myListener(){ServletListenerRegistrationBean registrationBean = new ServletListenerRegistrationBean(new MyListener());return registrationBean;}
}
访问
http://localhost:8080/servlet
默认拦截: /
修改 server.servletPath
其他 Servlet 容器
Tomcat 默认
Jetty 长连接
Undertow 不支持 jsp
嵌入式容器
外部容器
jar 包:执行 SpringBoot 主类的 main 方法,启动 IOC 容器,创建嵌入式的 Servlet 容器
war 包:启动服务器,服务器启动 SpringBoot,启动 IOC 容器
如若内容造成侵权/违法违规/事实不符,请联系编程学习网邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
相关文章
- 构建虚拟主机——基于端口
[root@promote extra]# cd /var/www/html [root@promote html]# mkdir aaa [root@promote html]# cd aaa [root@promote aaa]# vim index.html[root@promote ~]# vim /etc/httpd/conf/httpd.conf[root@promote ~]# systemctl restart httpd...
2024/4/30 13:49:37 - android 代码规律化
1.前面加m 原因:后面ctrl+f或ctrl+shift+f的时候可以当个查找,不然查找时会混淆...
2024/4/30 17:33:47 - MySQL是如何解决幻读的
一、什么是幻读 在一次事务里面,多次查询之后,结果集的个数不一致的情况叫做幻读。而多出来或者少的哪一行被叫做 幻行 二、为什么要解决幻读 在高并发数据库系统中,需要保证事务与事务之间的隔离性,还有事务本身的一致性。 三、MySQL 是如何解决幻读的 如果你看到了这篇文…...
2024/4/30 9:10:19 - 拳王虚拟项目公社:免费虚拟副业项目,创业副业首选虚拟资源平台转化虚拟资源池
虚拟资源项目算是一个能持续获取收益的老项目,在之前我也零散地跟大家分享了各种操作方法。例如我们以前比较常用的,将精准用户引导进入我们网盘下载资源,然后在资源里设置解压密码,并利用图片密码来获益。 不过,每次提起虚拟资源项目,总会有很多刚入行的朋友不得操作要领…...
2024/5/1 3:44:12 - 聊聊java多线程(转载)
本篇文章,为本人在某一阶段对此问题的个人理解总结,水平有限,会不断更新。对java中线程同步的理解对于这个话题,我们可以从两个方面去拆解,思考,首先,我需要知道线程同步的概念,什么是线程同步呢?为了充分利用硬件资源(对应多cpu单核、单cup多核、多cpu多核)去更高效…...
2024/4/22 0:45:31 - 主从复制原理
整理自深入浅出mysql:https://download.csdn.net/download/qq_16399991/10660150 https://blog.csdn.net/qq_16399991/article/details/82749333概述 mysql从3.23版本开始提供复制功能,复制是将主库的DDL和DML操作通过二进制日志传递到复制服务器(从库)上,然后从库对这些日…...
2024/5/3 5:05:46 - FreeCAD-0.19源码编译教程
一、前期准备Visual Studio 2019 Cmake(下载地址) FreeCADLibs_12.1.2_x64_VC15,源码依赖库,x64位,里面已集成boost/Qt5/Python等依赖环境,点击详细说明,FreeCAD源码和第三方依赖库(下载地址)二、CMake生成VS工程 1、新建文件目录(FreeCADbuild)注意:一定要将Freee…...
2024/4/26 17:08:43 - 在C#中嵌套使用语句
本文翻译自:Nested using statements in C# I am working on a project. 我正在做一个项目。 I have to compare the contents of two files and see if they match each other precisely. 我必须比较两个文件的内容,看看它们是否精确匹配。 Before a lot of error-checking …...
2024/5/3 1:40:27 - try except 用法
假设有一个文件当中存了几个学生的成绩,格式如下: Tom 96 Jack 95 Jimmy 93 Andy 94 Rose 99 其中每个学生的成绩之间及姓名和成绩之间都是用空格分开的。 写一段代码计算这几个学生的平均成绩。(使用try except语句) chengji = Tom 96 Jack 95 Jimmy 93 Andy 94 Rose 99 s…...
2024/5/5 4:51:59 - 神经网络与深度学习——神经网络基础——二分分类
二分分类结果是映射到离散的值上,比如给你一张图片,得到结果这张图片是猫(1)还是不是(0) 图片在计算机里的存储方式:一张6464像素大小的图片,在计算机中会有3个6464大小的矩阵来存储红绿蓝三个通道的亮度信息将所有像素值取出放入特征向量中,得到一个长度为64643的向量…...
2024/5/1 0:44:47 - Java中文本文件输入输出流综合实例
@Testpublic void test2() {FileInputStream fis = null;FileOutputStream fos = null;BufferedInputStream bis = null;BufferedOutputStream bos = null;try {// 源文件路径,如果源文件不存在,//则会运行报错:java.io.FileNotFoundExceptionfis = new FileInputStream(&qu…...
2024/4/26 5:52:57 - 【LeetCode】每日一题(8.6)
回文对 给定一组唯一的单词, 找出所有不同 的索引对(i, j),使得列表中的两个单词, words[i] + words[j] ,可拼接成回文串。 示例 1:输入: ["abcd","dcba","lls","s","sssll"] 输出: [[0,1],[1,0],[3,2],[2,4]] 解释: 可…...
2024/4/15 13:54:10 - 『互联网架构』软件架构-jenkins搭建和 maven gitlab自动化部署流程(上)(五)
几年前没用过jenkins的时候,每次都需要用eclipse打个war包,然后小心翼翼的上传到服务器,给服务器原有的war包改个名字,mv到bak目录中,停止服务,删除原有的webapps的项目,再把新上传的war包放进到tomcat的webapp说的目录下,启动项目。每次改个html的标签的名字都需要重新…...
2024/4/22 13:57:43 - 解决“此图片来自微信公众平台未经允许不可引用”的方法
解决“此图片来自微信公众平台未经允许不可引用”的方法参考文章: (1)解决“此图片来自微信公众平台未经允许不可引用”的方法 (2)http://www.cnblogs.com/zhengchunlin/p/9291796.html 备忘一下。...
2024/5/2 7:07:47 - Mybatis解决实体类中的属性名称和查询语句中的列名不一致无法访问数据的问题
当我们定义接受MYSQL数据的User类中的常量名和MYSQL中的列名不一致时,我们无法通过SQL语句来访问到MYSQL数据,有以下两种解决方案。 1、给属性名起别名 别名即为我们MYSQL中对应属性的列名。 <!-- 配置查询所有操作 --><select id="findAll" resultType=&…...
2024/5/1 23:25:37 - 有什么相见恨晚的算法答题套路?【力扣】
前言 本文是我在「力扣」上写的第一篇文章,现将其发布于此处。 众所周知,算法题主要有两大难点,一是「实现」,即算法本身的难度;二是「思路」,即你能否想到使用这个算法来解决题目。 并且对于有一定刷题基础的同学来说,力扣上大部分简单、中等题所涉及的算法都是非常常见…...
2024/4/15 19:59:34 - LeetCode刷题笔记_5_最长回文子串
题目出自LeetCode 5. 最长回文子串 其他题解或源码可以访问: tongji4m3描述 给定一个字符串 s,找到 s 中最长的回文子串。你可以假设 s 的最大长度为 1000。示例 1:输入: "babad" 输出: "bab" 注意: "aba" 也是一个有效答案。示例 2:输入: &qu…...
2024/4/27 23:48:36 - Mysql的存储引擎以及区别
Innodb:Innodb引擎提供了对数据库ACID事务的支持,并且实现了SQL标准的四种隔离级别.该引擎还提供了行级锁和外键约束,它的设计目标是处理大容量数据库系统,它本身其实就是基于MySQL后台的完整数据库系统,MySQL运行时Innodb会在内存中建立缓冲池,用于缓冲数据和索引.但是该…...
2024/4/24 5:35:12 - 计算机网络常见问题
计算机常用端口有哪些OSI与TCP/IP各层的结构与功能,都有哪些协议? 1.1 应用层 应用层(application-layer)的任务是通过应用进程间的交互来完成特定网络应用。应用层协议定义的是应用进程(进程:主机中正在运行的程序)间的通信和交互的规则。对于不同的网络应用需要不同的应…...
2024/4/15 19:59:33 - Linux下通配符[^此处为字符集]与字符集[a-z]匹配出大写字母文件原因
不想看废话的可以直接看文末加粗部分。 今日学习通配符[^字符集]:匹配列表中所有字符以外的字符。 步骤:创建文件touch f{a…z}.txt与 touch f{A…Z}.txt 。 用[^字符集]做筛选,选出除fa.txt,fb.txt……fz.txt文件以外的所有文件。 执行命令ls f[^a-f].* ,发现fA.txt,并未在…...
2024/5/1 2:08:16
最新文章
- W801学习笔记十八:古诗学习应用——中
现在我们加入交互逻辑——对用户选择的判断。 1、定义游戏的相关变量,如记录正确和错误的数量,运行时间等等。这些都可以作为游戏应用的私有属性。 u8 isFinished0;u16 correntCount 0;u16 wrongCount 0;u32 totalTime0; 2、处理交互。 根据前边定义…...
2024/5/5 5:02:38 - 梯度消失和梯度爆炸的一些处理方法
在这里是记录一下梯度消失或梯度爆炸的一些处理技巧。全当学习总结了如有错误还请留言,在此感激不尽。 权重和梯度的更新公式如下: w w − η ⋅ ∇ w w w - \eta \cdot \nabla w ww−η⋅∇w 个人通俗的理解梯度消失就是网络模型在反向求导的时候出…...
2024/3/20 10:50:27 - Java深度优先搜索DFS(含面试大厂题和源码)
深度优先搜索(Depth-First Search,简称DFS)是一种用于遍历或搜索树或图的算法。DFS 通过沿着树的深度来遍历节点,尽可能深地搜索树的分支。当节点v的所在边都已被探寻过,搜索将回溯到发现节点v的那条边的起始节点。这个…...
2024/5/3 10:02:23 - [Flutter]导入singular_flutter_sdk后运行到Android报错
问题: 接入归因之前,flutter项目一起正常。接入归因之后,iOS正常Android有问题。 dependencies: # Singular归因singular_flutter_sdk: ^1.3.3 针对 Flutter 的 Singular SDK 集成指南 https://support.singular.net/hc/zh-cn/articles/…...
2024/4/30 20:13:57 - 416. 分割等和子集问题(动态规划)
题目 题解 class Solution:def canPartition(self, nums: List[int]) -> bool:# badcaseif not nums:return True# 不能被2整除if sum(nums) % 2 ! 0:return False# 状态定义:dp[i][j]表示当背包容量为j,用前i个物品是否正好可以将背包填满ÿ…...
2024/5/4 12:05:22 - 【Java】ExcelWriter自适应宽度工具类(支持中文)
工具类 import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet;/*** Excel工具类** author xiaoming* date 2023/11/17 10:40*/ public class ExcelUti…...
2024/5/4 11:23:32 - Spring cloud负载均衡@LoadBalanced LoadBalancerClient
LoadBalance vs Ribbon 由于Spring cloud2020之后移除了Ribbon,直接使用Spring Cloud LoadBalancer作为客户端负载均衡组件,我们讨论Spring负载均衡以Spring Cloud2020之后版本为主,学习Spring Cloud LoadBalance,暂不讨论Ribbon…...
2024/5/4 14:46:16 - TSINGSEE青犀AI智能分析+视频监控工业园区周界安全防范方案
一、背景需求分析 在工业产业园、化工园或生产制造园区中,周界防范意义重大,对园区的安全起到重要的作用。常规的安防方式是采用人员巡查,人力投入成本大而且效率低。周界一旦被破坏或入侵,会影响园区人员和资产安全,…...
2024/5/4 23:54:44 - VB.net WebBrowser网页元素抓取分析方法
在用WebBrowser编程实现网页操作自动化时,常要分析网页Html,例如网页在加载数据时,常会显示“系统处理中,请稍候..”,我们需要在数据加载完成后才能继续下一步操作,如何抓取这个信息的网页html元素变化&…...
2024/5/4 12:10:13 - 【Objective-C】Objective-C汇总
方法定义 参考:https://www.yiibai.com/objective_c/objective_c_functions.html Objective-C编程语言中方法定义的一般形式如下 - (return_type) method_name:( argumentType1 )argumentName1 joiningArgument2:( argumentType2 )argumentName2 ... joiningArgu…...
2024/5/4 23:54:49 - 【洛谷算法题】P5713-洛谷团队系统【入门2分支结构】
👨💻博客主页:花无缺 欢迎 点赞👍 收藏⭐ 留言📝 加关注✅! 本文由 花无缺 原创 收录于专栏 【洛谷算法题】 文章目录 【洛谷算法题】P5713-洛谷团队系统【入门2分支结构】🌏题目描述🌏输入格…...
2024/5/4 23:54:44 - 【ES6.0】- 扩展运算符(...)
【ES6.0】- 扩展运算符... 文章目录 【ES6.0】- 扩展运算符...一、概述二、拷贝数组对象三、合并操作四、参数传递五、数组去重六、字符串转字符数组七、NodeList转数组八、解构变量九、打印日志十、总结 一、概述 **扩展运算符(...)**允许一个表达式在期望多个参数࿰…...
2024/5/4 14:46:12 - 摩根看好的前智能硬件头部品牌双11交易数据极度异常!——是模式创新还是饮鸩止渴?
文 | 螳螂观察 作者 | 李燃 双11狂欢已落下帷幕,各大品牌纷纷晒出优异的成绩单,摩根士丹利投资的智能硬件头部品牌凯迪仕也不例外。然而有爆料称,在自媒体平台发布霸榜各大榜单喜讯的凯迪仕智能锁,多个平台数据都表现出极度异常…...
2024/5/4 14:46:11 - Go语言常用命令详解(二)
文章目录 前言常用命令go bug示例参数说明 go doc示例参数说明 go env示例 go fix示例 go fmt示例 go generate示例 总结写在最后 前言 接着上一篇继续介绍Go语言的常用命令 常用命令 以下是一些常用的Go命令,这些命令可以帮助您在Go开发中进行编译、测试、运行和…...
2024/5/4 14:46:11 - 用欧拉路径判断图同构推出reverse合法性:1116T4
http://cplusoj.com/d/senior/p/SS231116D 假设我们要把 a a a 变成 b b b,我们在 a i a_i ai 和 a i 1 a_{i1} ai1 之间连边, b b b 同理,则 a a a 能变成 b b b 的充要条件是两图 A , B A,B A,B 同构。 必要性显然࿰…...
2024/5/5 2:25:33 - 【NGINX--1】基础知识
1、在 Debian/Ubuntu 上安装 NGINX 在 Debian 或 Ubuntu 机器上安装 NGINX 开源版。 更新已配置源的软件包信息,并安装一些有助于配置官方 NGINX 软件包仓库的软件包: apt-get update apt install -y curl gnupg2 ca-certificates lsb-release debian-…...
2024/5/4 21:24:42 - Hive默认分割符、存储格式与数据压缩
目录 1、Hive默认分割符2、Hive存储格式3、Hive数据压缩 1、Hive默认分割符 Hive创建表时指定的行受限(ROW FORMAT)配置标准HQL为: ... ROW FORMAT DELIMITED FIELDS TERMINATED BY \u0001 COLLECTION ITEMS TERMINATED BY , MAP KEYS TERMI…...
2024/5/4 12:39:12 - 【论文阅读】MAG:一种用于航天器遥测数据中有效异常检测的新方法
文章目录 摘要1 引言2 问题描述3 拟议框架4 所提出方法的细节A.数据预处理B.变量相关分析C.MAG模型D.异常分数 5 实验A.数据集和性能指标B.实验设置与平台C.结果和比较 6 结论 摘要 异常检测是保证航天器稳定性的关键。在航天器运行过程中,传感器和控制器产生大量周…...
2024/5/4 13:16:06 - --max-old-space-size=8192报错
vue项目运行时,如果经常运行慢,崩溃停止服务,报如下错误 FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 因为在 Node 中,通过JavaScript使用内存时只能使用部分内存(64位系统&…...
2024/5/4 16:48:41 - 基于深度学习的恶意软件检测
恶意软件是指恶意软件犯罪者用来感染个人计算机或整个组织的网络的软件。 它利用目标系统漏洞,例如可以被劫持的合法软件(例如浏览器或 Web 应用程序插件)中的错误。 恶意软件渗透可能会造成灾难性的后果,包括数据被盗、勒索或网…...
2024/5/4 14:46:05 - JS原型对象prototype
让我简单的为大家介绍一下原型对象prototype吧! 使用原型实现方法共享 1.构造函数通过原型分配的函数是所有对象所 共享的。 2.JavaScript 规定,每一个构造函数都有一个 prototype 属性,指向另一个对象,所以我们也称为原型对象…...
2024/5/5 3:37:58 - C++中只能有一个实例的单例类
C中只能有一个实例的单例类 前面讨论的 President 类很不错,但存在一个缺陷:无法禁止通过实例化多个对象来创建多名总统: President One, Two, Three; 由于复制构造函数是私有的,其中每个对象都是不可复制的,但您的目…...
2024/5/4 23:54:30 - python django 小程序图书借阅源码
开发工具: PyCharm,mysql5.7,微信开发者工具 技术说明: python django html 小程序 功能介绍: 用户端: 登录注册(含授权登录) 首页显示搜索图书,轮播图࿰…...
2024/5/4 9:07:39 - 电子学会C/C++编程等级考试2022年03月(一级)真题解析
C/C++等级考试(1~8级)全部真题・点这里 第1题:双精度浮点数的输入输出 输入一个双精度浮点数,保留8位小数,输出这个浮点数。 时间限制:1000 内存限制:65536输入 只有一行,一个双精度浮点数。输出 一行,保留8位小数的浮点数。样例输入 3.1415926535798932样例输出 3.1…...
2024/5/4 14:46:02 - 配置失败还原请勿关闭计算机,电脑开机屏幕上面显示,配置失败还原更改 请勿关闭计算机 开不了机 这个问题怎么办...
解析如下:1、长按电脑电源键直至关机,然后再按一次电源健重启电脑,按F8健进入安全模式2、安全模式下进入Windows系统桌面后,按住“winR”打开运行窗口,输入“services.msc”打开服务设置3、在服务界面,选中…...
2022/11/19 21:17:18 - 错误使用 reshape要执行 RESHAPE,请勿更改元素数目。
%读入6幅图像(每一幅图像的大小是564*564) f1 imread(WashingtonDC_Band1_564.tif); subplot(3,2,1),imshow(f1); f2 imread(WashingtonDC_Band2_564.tif); subplot(3,2,2),imshow(f2); f3 imread(WashingtonDC_Band3_564.tif); subplot(3,2,3),imsho…...
2022/11/19 21:17:16 - 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机...
win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”问题的解决方法在win7系统关机时如果有升级系统的或者其他需要会直接进入一个 等待界面,在等待界面中我们需要等待操作结束才能关机,虽然这比较麻烦,但是对系统进行配置和升级…...
2022/11/19 21:17:15 - 台式电脑显示配置100%请勿关闭计算机,“准备配置windows 请勿关闭计算机”的解决方法...
有不少用户在重装Win7系统或更新系统后会遇到“准备配置windows,请勿关闭计算机”的提示,要过很久才能进入系统,有的用户甚至几个小时也无法进入,下面就教大家这个问题的解决方法。第一种方法:我们首先在左下角的“开始…...
2022/11/19 21:17:14 - win7 正在配置 请勿关闭计算机,怎么办Win7开机显示正在配置Windows Update请勿关机...
置信有很多用户都跟小编一样遇到过这样的问题,电脑时发现开机屏幕显现“正在配置Windows Update,请勿关机”(如下图所示),而且还需求等大约5分钟才干进入系统。这是怎样回事呢?一切都是正常操作的,为什么开时机呈现“正…...
2022/11/19 21:17:13 - 准备配置windows 请勿关闭计算机 蓝屏,Win7开机总是出现提示“配置Windows请勿关机”...
Win7系统开机启动时总是出现“配置Windows请勿关机”的提示,没过几秒后电脑自动重启,每次开机都这样无法进入系统,此时碰到这种现象的用户就可以使用以下5种方法解决问题。方法一:开机按下F8,在出现的Windows高级启动选…...
2022/11/19 21:17:12 - 准备windows请勿关闭计算机要多久,windows10系统提示正在准备windows请勿关闭计算机怎么办...
有不少windows10系统用户反映说碰到这样一个情况,就是电脑提示正在准备windows请勿关闭计算机,碰到这样的问题该怎么解决呢,现在小编就给大家分享一下windows10系统提示正在准备windows请勿关闭计算机的具体第一种方法:1、2、依次…...
2022/11/19 21:17:11 - 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”的解决方法...
今天和大家分享一下win7系统重装了Win7旗舰版系统后,每次关机的时候桌面上都会显示一个“配置Windows Update的界面,提示请勿关闭计算机”,每次停留好几分钟才能正常关机,导致什么情况引起的呢?出现配置Windows Update…...
2022/11/19 21:17:10 - 电脑桌面一直是清理请关闭计算机,windows7一直卡在清理 请勿关闭计算机-win7清理请勿关机,win7配置更新35%不动...
只能是等着,别无他法。说是卡着如果你看硬盘灯应该在读写。如果从 Win 10 无法正常回滚,只能是考虑备份数据后重装系统了。解决来方案一:管理员运行cmd:net stop WuAuServcd %windir%ren SoftwareDistribution SDoldnet start WuA…...
2022/11/19 21:17:09 - 计算机配置更新不起,电脑提示“配置Windows Update请勿关闭计算机”怎么办?
原标题:电脑提示“配置Windows Update请勿关闭计算机”怎么办?win7系统中在开机与关闭的时候总是显示“配置windows update请勿关闭计算机”相信有不少朋友都曾遇到过一次两次还能忍但经常遇到就叫人感到心烦了遇到这种问题怎么办呢?一般的方…...
2022/11/19 21:17:08 - 计算机正在配置无法关机,关机提示 windows7 正在配置windows 请勿关闭计算机 ,然后等了一晚上也没有关掉。现在电脑无法正常关机...
关机提示 windows7 正在配置windows 请勿关闭计算机 ,然后等了一晚上也没有关掉。现在电脑无法正常关机以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!关机提示 windows7 正在配…...
2022/11/19 21:17:05 - 钉钉提示请勿通过开发者调试模式_钉钉请勿通过开发者调试模式是真的吗好不好用...
钉钉请勿通过开发者调试模式是真的吗好不好用 更新时间:2020-04-20 22:24:19 浏览次数:729次 区域: 南阳 > 卧龙 列举网提醒您:为保障您的权益,请不要提前支付任何费用! 虚拟位置外设器!!轨迹模拟&虚拟位置外设神器 专业用于:钉钉,外勤365,红圈通,企业微信和…...
2022/11/19 21:17:05 - 配置失败还原请勿关闭计算机怎么办,win7系统出现“配置windows update失败 还原更改 请勿关闭计算机”,长时间没反应,无法进入系统的解决方案...
前几天班里有位学生电脑(windows 7系统)出问题了,具体表现是开机时一直停留在“配置windows update失败 还原更改 请勿关闭计算机”这个界面,长时间没反应,无法进入系统。这个问题原来帮其他同学也解决过,网上搜了不少资料&#x…...
2022/11/19 21:17:04 - 一个电脑无法关闭计算机你应该怎么办,电脑显示“清理请勿关闭计算机”怎么办?...
本文为你提供了3个有效解决电脑显示“清理请勿关闭计算机”问题的方法,并在最后教给你1种保护系统安全的好方法,一起来看看!电脑出现“清理请勿关闭计算机”在Windows 7(SP1)和Windows Server 2008 R2 SP1中,添加了1个新功能在“磁…...
2022/11/19 21:17:03 - 请勿关闭计算机还原更改要多久,电脑显示:配置windows更新失败,正在还原更改,请勿关闭计算机怎么办...
许多用户在长期不使用电脑的时候,开启电脑发现电脑显示:配置windows更新失败,正在还原更改,请勿关闭计算机。。.这要怎么办呢?下面小编就带着大家一起看看吧!如果能够正常进入系统,建议您暂时移…...
2022/11/19 21:17:02 - 还原更改请勿关闭计算机 要多久,配置windows update失败 还原更改 请勿关闭计算机,电脑开机后一直显示以...
配置windows update失败 还原更改 请勿关闭计算机,电脑开机后一直显示以以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!配置windows update失败 还原更改 请勿关闭计算机&#x…...
2022/11/19 21:17:01 - 电脑配置中请勿关闭计算机怎么办,准备配置windows请勿关闭计算机一直显示怎么办【图解】...
不知道大家有没有遇到过这样的一个问题,就是我们的win7系统在关机的时候,总是喜欢显示“准备配置windows,请勿关机”这样的一个页面,没有什么大碍,但是如果一直等着的话就要两个小时甚至更久都关不了机,非常…...
2022/11/19 21:17:00 - 正在准备配置请勿关闭计算机,正在准备配置windows请勿关闭计算机时间长了解决教程...
当电脑出现正在准备配置windows请勿关闭计算机时,一般是您正对windows进行升级,但是这个要是长时间没有反应,我们不能再傻等下去了。可能是电脑出了别的问题了,来看看教程的说法。正在准备配置windows请勿关闭计算机时间长了方法一…...
2022/11/19 21:16:59 - 配置失败还原请勿关闭计算机,配置Windows Update失败,还原更改请勿关闭计算机...
我们使用电脑的过程中有时会遇到这种情况,当我们打开电脑之后,发现一直停留在一个界面:“配置Windows Update失败,还原更改请勿关闭计算机”,等了许久还是无法进入系统。如果我们遇到此类问题应该如何解决呢࿰…...
2022/11/19 21:16:58 - 如何在iPhone上关闭“请勿打扰”
Apple’s “Do Not Disturb While Driving” is a potentially lifesaving iPhone feature, but it doesn’t always turn on automatically at the appropriate time. For example, you might be a passenger in a moving car, but your iPhone may think you’re the one dri…...
2022/11/19 21:16:57