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

【书籍篇】Spring实战第4版 第2部分 Web中的Spring

Spring实战第4版 第2部分 Web中的Spring

  • 五. 构建Spring Web应用程序
    • 5.1 SpirngMVC请求流程
    • 5.2 搭建Spring MVC
      • 5.2.1 配置DispatcherServlet
      • 5.2.2 配置WebConfig
      • 5.2.3 配置RootConfig
    • 5.3 编写基本的控制器
    • 5.4 Spittr首页
    • 5.6 复杂的控制器
      • 5.6.1 定义类级别的请求处理
      • 5.6.2 传递模型数据到视图中
      • 5.6.3 接受请求的输入
      • 5.6.4 处理表单
      • 5.6.5 校验表单
  • 六. 渲染Web视图
    • 6.1 视图解析器
    • 6.2 创建JSP视图
      • 6.2.1 配置InternalResourceViewResolver
      • 6.2.2 使用Spring的JSP库
      • 6.2.3 Spring通用标签库
      • 6.2.4 展示国际化信息
      • 6.2.5 创建URL
      • 6.2.6 转义
    • 6.3 使用Apache Tiles视图定义布局
      • 6.3.1 配置Tile视图解析器
      • 6.3.2 定义Tiles
      • 6.3.3 主布局模板
    • 6.4 使用Thymeleaf模板
      • 6.4.1 配置Thymeleaf视图解析器
      • 6.4.2 定义Thymeleaf模板
      • 6.4.3 借助Thymeleaf实现表单绑定
  • 七. Spring MVC的高级技术
    • 7.1 Spring MVC配置的替代方案
      • 7.1.1 自定义DispacherServlet配置
      • 7.1.2 添加其他Servlet和Filter
      • 7.1.3 web.xml中声明DispatcherServlet
      • 7.1.4 web.xml中使用基于java的配置
    • 7.2 处理Multipart形式的数据
      • 7.2.1 配置multipart解析器
      • 7.2.2 StandardServletMultipartResolver
      • 7.2.3 CommonsMultipartResolver
    • 7.3 处理Multipart请求
    • 7.4 处理异常
      • 7.4.1 异常映射HTTP状态码
      • 7.4.2 异常处理方法
      • 7.4.3 为控制器添加通知
    • 7.5 跨重定向请求传递数据
      • 7.5.1 使用URL传递
      • 7.5.2 使用flash传递
  • 八. 使用Spring Web Flow
    • 8.1 在Spring中配置Web Flow(xml配置)
      • 8.1.1 装配流程执行器
      • 8.1.2 配置流程注册表
      • 8.1.3 处理流程请求
    • 8.2 流程组件
      • 8.2.1 状态
        • 8.2.1.1 行为状态
        • 8.2.1.2 决策状态
        • 8.2.1.3 结束状态
        • 8.2.1.4 子流程状态
        • 8.2.1.5 视图状态
      • 8.2.2 转移
      • 8.2.3 流程数据
        • 8.2.3.1 声明变量
        • 8.2.3.2 作用域
    • 8.3 流程实例

五. 构建Spring Web应用程序

5.1 SpirngMVC请求流程

web浏览器发送请求
第一站:前端控制器(DispatcherServlet),其作用是将从处理器映射(handler mapping)获取请求的下一站是哪里(哪个控制器)。
第二站:将请求数据交由控制器处理(controller)或者是控制器将业务逻辑委托给一个或多个服务对象处理,处理完的数据称为模型(model),再进行友好的方式进行格式化,最后发送给视图(view)
第三站:视图渲染数据响应给web浏览器。

5.2 搭建Spring MVC

5.2.1 配置DispatcherServlet

public class SpittrWebAppInitializerextends AbstractAnnotationConfigDispatcherServletInitializer {@Overrideprotected String[] getServletMappings() {return new String[] {"/"};	// 将DispatcherServlet映射到"/"}@Overrideprotected Class<?>[] getRootConfigClasses() {return new Class<?>[] {RootConfig.class};}@Overrideprotected Class<?>[] getServletConfigClasses() {return new Class<?>[] {WebConfig.class};}
}

5.2.2 配置WebConfig

@Configuration
@EnableWebMvc
public class WebConfig {}

5.2.3 配置RootConfig

@Configuration
@ComponentScan(basePackages={"spittr"}, excludeFilters={@Filter(type=FilterType.ANNOTATION, value=EnableWebMvc.class)
})
public class RootConfig {}

5.3 编写基本的控制器

@Controller		// 声明为一个控制器
public class DemoController {@RequestMapping(value="/", method=GET)	// 处理对"/"的Get请求public String demo() {return "demo";		// 发送给视图“demo”}
}

5.4 Spittr首页

略。。。详细可从书中p144获知

5.6 复杂的控制器

5.6.1 定义类级别的请求处理

@Controller
@RequestMapping("/")
public class DemoController {...
}

5.6.2 传递模型数据到视图中

略。。。详细可从书中p147获知

5.6.3 接受请求的输入

@Controller
@RequestMapping("/")
public class DemoController {@Autowiredprivate DemoService demoService;@RequestMapping(value="/getList", method=GET)public List<String> getList(@RequestParam("conut") long count) {  return demoService.selectByCount(count);}@RequestMapping(value="/{id}", method=GET)public List<String> getObj(@PathVariable("id") long id) {  return demoService.selectById(id);}
}

5.6.4 处理表单

略。。。详细可从书中p158获知

5.6.5 校验表单

在Spring MVC中提供了对java校验API的支持,详细可从书中p164获知或百度

public class Demo {@NotNull@Size(min=5, max=16)private Long id;...
}@Controller
@RequestMapping("/")
public class DemoController {@RequestMapping(value="/valid", method=POST)public Boolean valid(@Valid Demo demo, Errors errors) {if (errors.hasErrors()) {return false;}return true;}
}

六. 渲染Web视图

6.1 视图解析器

Spring自带了13个视图解析器

视图解析器描述
BeanNameViewResolver将视图解析为Spring应用上下文中的bean,其中bean的ID与视图的名字相同
ContentNegotiatingViewResolver通过考虑客户端的内容类型来解析视图,委托给另一个能够产生对应内容类型的视图解析器
FreeMarkerViewResolver将视图解析为FreeMarker模板
InternalResourceViewResolver将视图解析为Web应用的内部资源(一般为JSP)
JasperReportsViewResolver将视图解析为JasperReports定义
ResourceBundleViewResolver将视图解析为资源bundle(一般为属性文件)
TilesViewResolver将视图解析为Apache Tiles定义,其中tile ID与视图名称相同(注意有两个不同的TilesViewResolver实现,分别对应Tiles 2.0 和 Tiles 3.0)
UrlBasedViewResolver直接更具视图的名称解析视图,视图的名称会匹配一个物理视图的定义
VelocityLayoutViewResolver将视图解析为Velocity布局,从不同的Velocity模板中组合页面
VelocityViewResolver将视图解析为Velocity模板
XmlViewResolver将视图解析为XML文件中bean的定义(类似于BeanNameViewResolver)
XsltViewReslover将视图解析为XSLT转换后的结果
ThymeleafViewResolver将逻辑视图名称解析为Thymeleaf模板视图

6.2 创建JSP视图

6.2.1 配置InternalResourceViewResolver

@bean
public ViewResolver viewResolver() {InternalResourceViewResolver resolver = new InternalResourceViewResolver();resolver.setPrefix("/WEB-INFO/views/");resolver.setSuffix(".jsp");// 解析JSTL标签resolver.setViewClass("org.springframework.web.servlet.view.JstlView.class");return resolver;
}
<bean id="viewResolver"  class= "org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INFO/views/" p:suffix=".jsp" p:viewClass="org.springframework.web.servlet.view.JstlView" />

6.2.2 使用Spring的JSP库

<!-- JSP页面声明 -->
<%@ tagblib uri="http://wwww.springframwork.org/tags/form" prefix="sf" %>

6.2.3 Spring通用标签库

<%@ tagblib uri="http://wwww.springframwork.org/tags" prefix="s" %>

6.2.4 展示国际化信息

<h1><s:message code="spittr.welcome" />
</h1>
@Bean
public MessageSource messageSource() {ResourceBunleMessageSource messageSource = new ResourceBunleMessageSource();messageSource.setBeanname("message");return messageSource;
}@Bean
public MessageSource messageSource() {ReloadableResourceBunleMessageSource messageSource = new ReloadableResourceBunleMessageSource();messageSource.setBasename("file://etc/spittr/messages");	// 类路径以 classpath: 为前缀messageSource.setCacheSeconds(10);return messageSource;
}// en.properties
spittr.welcome=Welcome to Spittr!// zh.properties
spittr.welcome=欢迎来到Spittr!

6.2.5 创建URL

<s:url>。。。详细可从书中p182获知

6.2.6 转义

<s:escapebody>。。。详细可从书中p184获知

6.3 使用Apache Tiles视图定义布局

6.3.1 配置Tile视图解析器

@Bean
public TilesConfigurer tilesConfigurer() {TilesConfigurer tiles = new TilesConfigurer();// 指定Tile的定义的位置	"/WEB-INFO/**/tiles.xml"	tiles.setDefinitions(new String[] {"/WEB-INFO/layout/tiles.xml"	});// 启用刷新功能tiles.setCheckRefresh(true);return tiles;
}@Bean
public ViewResolver viewResolver() {return new TilesViewResolver();
}
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer"><property name="definitions"><list><value>/WEB-INFO/layout/tiles.xml</value><value>/WEB-INFO/**/tiles.xml</value></list></property>
</bean><bean id="viewResolver" class="org.springframework.web.servlet.view.tiles3.ViewResolver" />

6.3.2 定义Tiles

<xml version="1.0" encoding="UTF-8">
<DOCTYPE tiles-definitions PUBLIC"...">
<tiles-definitions><!-- 定义base Tiles --><definition name="base" template="/WEB-INF/layout/page.jsp"><!-- 设置属性 --><put-attribute name="body" value="/WEB-INF/layout/header.jsp" /><put-attribute name="footer" value="/WEB-INF/layout/footer.jsp" /></definition><!-- 扩展base Tiles --><definition name="home" template="/WEB-INF/layout/home.jsp"><!-- 设置属性 --><put-attribute name="body" value="/WEB-INF/layout/home.jsp" /></definition>
</tiles-definitions>

6.3.3 主布局模板

<%@ tagblib uri="http://wwww.springframwork.org/tags" prefix="s" %>
<%@ tagblib uri="tiles.apache.org/tags-tiles" prefix="t" %><html><head>...</head><body><div id="header"><t:insertAttribute name="header" />	</div><div id="content"><t:insertAttribute name="body" /></div><div id="footer"><t:insertAttribute name="footer" /></div></body>
</html>

6.4 使用Thymeleaf模板

略。。。详细可从书中p190~196获知

6.4.1 配置Thymeleaf视图解析器

6.4.2 定义Thymeleaf模板

6.4.3 借助Thymeleaf实现表单绑定

七. Spring MVC的高级技术

7.1 Spring MVC配置的替代方案

略。。。详细可从书中p200~205获知

7.1.1 自定义DispacherServlet配置

7.1.2 添加其他Servlet和Filter

7.1.3 web.xml中声明DispatcherServlet

7.1.4 web.xml中使用基于java的配置

7.2 处理Multipart形式的数据

7.2.1 配置multipart解析器

从Spring3.1开始,Spring内置了两个MultipartResolver的实现供我们选择

multipart解析器描述
CommonsMultipartResolver使用Jakarta Commons FileUpload解析multipart请求
StandardServletMultipartResolver依赖于servlet3.0对multipart请求的支持

7.2.2 StandardServletMultipartResolver

@bean
public MultipartResolver multipartResolver() throws IOException {return new StandardServletMultipartResolver();
}
// java配置
@Override
protected void custiomizeRegistration(Dynamic registration) {// 临时路径,文件大小不超过2MB,整个请求不超过4MB,所有文件都写入磁盘registration.setMultipartConfig(new MultipartConfigElement("/tmp/spittr/uploads"2096000, 4192000, 0));
}
<!-- xml配置 -->
<servlet><servlet-name>appServlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><load-on-startup>1</load-on-startup><multipart-config><location>/tmp/spittr/uploads</location><max-file-size>2096000</max-file-size><max-request-size>4192000</max-request-size></multipart-config>
</servlet>

7.2.3 CommonsMultipartResolver

@bean
public MultipartResolver multipartResolver() throws IOException {CommonsMultipartResolver resolver = new CommonsMultipartResolver();resolver.setUploadTempDir(new FileSystemResource("/tmp/spittr/uploads"));	// 临时路径resolver.setMaxUploadSize(2096000);		// 最大的文件容量resolver.setMaxInMemorySize(0);		// 最大的内存大小return resolver;
}

7.3 处理Multipart请求

<form method="POST" enctype="multipart/form-data" th:object="${spitter}">...<label>Profile picture</label><input type="file" name="profilePicture" accept="image/jpeg,image/png,image/gif" />...
</form>
// 方式一:无法获取文件信息
@RequestMapping(value="/register", method=POST)
public String processRegistration(@RequestPart("profilePicture") btye[] profilePicture,@Valid Spitter spitter,Errors errors) {...
}// 方式二:使用part,能获取文件信息
@RequestMapping(value="/register", method=POST)
public String processRegistration(@RequestPart("profilePicture") Part profilePicture,@Valid Spitter spitter,Errors errors) {...
}

7.4 处理异常

7.4.1 异常映射HTTP状态码

@ResponseStatus(value=HttpStatus.NOT_FOUND, reson="Spittle Not Found")
public class SpitterNotFoundException extends RuntimeException {...
}

7.4.2 异常处理方法

// 方式一
@RequestMapping(method=POST)
public String saveSpitter(SpittleForm form, Model model) {try {spittleRepository.save(new Spittle(null, form.getName()));return "redirect:/spittles";} catch (DuplicateSpittleException e) {return "error/duplicate";}
}// 方式二
// 该控制器里的方法抛出DuplicateSpittleException异常就会调用handleDuplicateSpittle()方法来处理异常
@RequestMapping(method=POST)
public String saveSpitter(SpittleForm form, Model model) {spittleRepository.save(new Spittle(null, form.getName()));return "redirect:/spittles";
}@ExceptionHandler(DuplicateSpittleException.class)
public String handleDuplicateSpittle() {return "error/duplicate";
}

7.4.3 为控制器添加通知

// 任意控制器抛出DuplicateSpittleException异常都会调用handleDuplicateSpittle()方法来处理异常
@ControllerAdvice
public class AppWideExceptionHandller {@ExceptionHandler(DuplicateSpittleException.class)public String handleDuplicateSpittle() {return "error/duplicate";}
}

7.5 跨重定向请求传递数据

跨重定向请求传递数据
使用URL模板以路径变量或查询参数的形式传递数据
通过flash属性发送数据

7.5.1 使用URL传递

@RequestMapping(value="/register", method=POST)
public String processRegistration(Spitter spitter, Model model) {spittleRepository.save(Spitter);model.adddAttribute("name", Spitter.getName());return "redirect:/spittles/{name}";
}

7.5.2 使用flash传递

@RequestMapping(value="/register", method=POST)
public String processRegistration(Spitter spitter, Model model) {spittleRepository.save(spitter);model.adddAttribute("name", spitter.getName());model.adddFlashAttribute("spitter", spitter);return "redirect:/spittles/{name}";
}@RequestMapping(value="/{name}", method=GET)
public String showSpitterProfile(@PathVariable String name, Model model) {if (!model.contaionsAttribute("spitter")) {model.adAttribute(spittleRepository.findByName(name));}return "profile";
}

八. 使用Spring Web Flow

8.1 在Spring中配置Web Flow(xml配置)

8.1.1 装配流程执行器

<!-- 当用户进入一个流程时,流程执行器会为用户创建并启用一个流程执行实例 -->
<flow:flow-executor id="flowExecutor" />

8.1.2 配置流程注册表

<!-- 加载流程定义并让流程执行器能够使用它们 -->
<!-- 流程注册表会在"/WEB-INF/flows"目录下查找流程定义,任何文件名以"*-flow.xml"结尾的xml文件都视为流程 -->
<flow:flow-registry id="flowRegistry" base-path="/WEB-INF/flows"><flow:flow-location-pattern value="*-flow.xml" />
</flow:flow-registry>
<!-- 直接指明文件 springpizza作为流程id -->
<flow:flow-registry id="flowRegistry"><flow:flow-location value="/WEB-INF/flows/springpizza.xml" />
</flow:flow-registry><!-- 直接指明文件和id -->
<flow:flow-registry id="flowRegistry"><flow:flow-location id="pizza" value="/WEB-INF/flows/springpizza.xml" />
</flow:flow-registry>

8.1.3 处理流程请求

<!-- 在Spring应用上下文中配置一个FlowHandlerMapping来帮助前端控制器将流程请求发送给Spring Web Flow  -->
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping"><propertry name="flowRegistry" ref="flowRegistry" />
</bean><!-- 响应请求的是FlowHandlerAdapter,等同于Spring MVC的控制器对请求进行处理 -->
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter"><propertry name="flowExecutor" ref="flowExecutor" />
</bean>

8.2 流程组件

8.2.1 状态

类型作用
行为(Action)流程逻辑发生的地方
决策(Decision)将流程基于流程数据确定分成两个方向
结束(End)流程最后一站,一旦进入流程终止
子流程(Subflow)会在当前正在运行大队流程上下文中启动一个新的流程
视图(View)暂停流程并邀请用户参与流程
8.2.1.1 行为状态
<!-- 应用程序执行任务时一般会出发Spring所管理bean的一些方法,并根据方法的执行结果转移到另一个状态 -->
<action-state id="saveOrder"><evaluate expression="pizzaFlowActions.saveOrder(order)" /><transition to="thankYou" />
</action-state>
8.2.1.2 决策状态
<!-- 评估一个boolean类型的表达式,然后再两个状态转移中选择一个 -->
<decision-state id="checkDeiveryArea"><if test="pizzaFlowAtions.checkDeliveryArea(customer.zipCode)"then="addCustomer"else="deliveryWarning" />
</decision-state>
8.2.1.3 结束状态
<!-- 结束之后发生什么取决于三个因素。。。详细可从书中p231获知 -->
<end-state id="customerReady" />
8.2.1.4 子流程状态
<!-- 如果子流程结束状态id为orderCreated,那么流程会转移到payment -->
<subflow-state id="order" subflow="pizza/order"><input name="order" value="order" /><transition on="orderCreated" to="payment" />
</subflow-state>
8.2.1.5 视图状态
<!-- 简单实例 -->
<view-state id = "welcome" />
<!-- 指明视图名 -->
<view-state id = "welcome" view="greeting"/>
<!-- 视图绑定的对象 -->
<view-state id = "welcome" modedl="flowScope.paymentDetails"/>

8.2.2 转移

<!-- 当前状态的默认转移项 -->
<transition to="customerReady" />
<!-- 触发了phoneEntered就会进入customerReady状态 -->
<transition on="phoneEntered" to="customerReady" />
<!-- 触发了异常就会进入customerReady状态 -->
<transition on-exception="com.springinaction.pizza.service.CustomerNotFoundException" to="customerReady" />
<!-- 全局转移,流程中所有的状态都会默认拥有这个转移 -->
<global-transitions><transition on="cancel" to="endstate" />
</global-transitions>

8.2.3 流程数据

8.2.3.1 声明变量
<!-- 该变量可以再流程的任意状态进行访问 -->
<var name="customer" class="com.springinaction.pizza.domain.Customer" />
<!-- 计算一个表达式并且放到toppingsList,该变量是一个视图作用域变量 -->
<evaluate result="viewScope.toppingsList" expression="T(com.springinaction.pizza.ddomain.Topping).asList()" />
<!-- 将变量设置为表达式计算的结果,类似evaluate标签 -->
<set name="flowScope.pizza" value="new com.springinaction.pizza.domain.Pizza()" />
8.2.3.2 作用域
范围作用域和可见性
Conversation最高层级的的流程开始时创建,最高层级的流程结束时销毁。被最高层级的流程和其所有的子流程所共享
Flow当流程开始时创建,在流程结束时销毁。只有在创建它的流程中是可见的
Request当一个请求进入流程时创建,在流程返回时销毁
Flash当流程开始时创建,在流程结束时销毁。在视图状态渲染后,它会被清除
View当进入视图状态时创建,当这个状态退出时销毁。只在视图状态内是可见的

8.3 流程实例

略。。。详细可从书中p234~248获知

相关文章:

【书籍篇】Spring实战第4版 第2部分 Web中的Spring

Spring实战第4版 第2部分 Web中的Spring 五. 构建Spring Web应用程序5.1 SpirngMVC请求流程5.2 搭建Spring MVC5.2.1 配置DispatcherServlet5.2.2 配置WebConfig5.2.3 配置RootConfig 5.3 编写基本的控制器5.4 Spittr首页5.6 复杂的控制器5.6.1 定义类级别的请求处理5.6.2 传递…...

IC - 基础知识 - SOC与MCU

说明 工作中有涉及到SOC和MCU&#xff0c;非嵌入式专业&#xff0c;对两个概念理解不是很清晰。 共同点 MCU和SOC是两种常见的集成电路 (IC) 设计形式&#xff0c;它们的区别在于它们的设计目的和应用场景。工作中将MCU和SOC都称为IC也是没问题的&#xff0c;但是专业人员会…...

【elasticsearch+kibana基于windows docker安装】

创建网络&#xff1a;es和kibana容器互联 docker network create es-net加载镜像 docker pull elasticsearch:7.12.1运行 docker run -d --name es -p 9200:9200 -p 9300:9300 -e "discovery.typesingle-node" -e ES_JAVA_OPTS"-Xms512m -Xmx512m" -v $…...

VMware网络设置 桥接模式 NAT VMNET0 1 8

1.桥接模式 虚拟机与主机并列 可拥有独立IP 主机与虚拟机之间&#xff0c;以及各虚拟机之间都可以互访。对应虚拟机就被当成主机所在以太网上的一个独立物理机来看待&#xff0c;各虚拟机通过默认的 VMnet0 网卡与主机以太网连接&#xff0c;虚拟机间的虚拟网络为 VMnet0。这…...

【MongoDB】MongoExport如何过滤数据导出

问题 使用MongoDB处理导出数据时&#xff0c;想增加数据过滤操作。 例如&#xff1a;导出所有isGirl为true的所有数据。 分析 在mongoexport说明文档中找到了query字段和queryFile字段&#xff0c;用来进行数据查询匹配导出。 query字段 后面直接跟 json格式数据。 queryF…...

吴恩达《机器学习》6-1->6-3:分类问题、假设陈述、决策界限

一、什么是分类问题&#xff1f; 在分类问题中&#xff0c;我们试图预测的变量&#x1d466;是离散的值&#xff0c;通常表示某种类别或标签。这些类别可以是二元的&#xff0c;也可以是多元的。分类问题的示例包括&#xff1a; 判断一封电子邮件是否是垃圾邮件&#xff08;二…...

C语言 用字符串比较函数cmp来做一个门禁:账号密码是否匹配 (干货满满)

#include<stdio.h> #include<string.h> void fun04() {for (int i 0; i < 3; i){char *str01 "hello";char uname[100] ;printf("请输入账号");scanf("%s",uname);char *str02 "123456";char pword[100];printf(&qu…...

Uniapp实现多语言切换

前言 之前做项目过程中&#xff0c;也做过一次多语言切换&#xff0c;大致思想都是一样的&#xff0c;想了解的可以看下之前的文章C#WinForm实现多语言切换 使用i18n插件 安装插件 npm install vue-i18n --saveMain.js配置 // 引入 多语言包 import VueI18n from vue-i18n…...

企业数字化转型与供应链效率-基准回归复刻(2007-2022年)

参照张树山&#xff08;2023&#xff09;的做法&#xff0c;本团队对来自统计与决策《企业数字化转型与供应链效率》一文中的基准回归部分进行复刻。文章实证检验企业数字化转型对供应链效率的影响。用年报词频衡量上市公司数字化转型程度&#xff0c;以库存周转天数来衡量供应…...

支持向量机 (SVM):初学者指南

照片由 Unsplash上的 vackground.com提供 一、说明 SVM&#xff08;支持向量机&#xff09;简单而优雅用于分类和回归的监督机器学习方法。该算法试图找到一个超平面&#xff0c;将数据分为不同的类&#xff0c;并具有尽可能最大的边距。本篇我们将介绍如果最大边距不存在的时候…...

UnityShader(五)

这次要用表面着色器实现一个水的特效。先翻到最下边看代码&#xff0c;看不懂再看下面的解释。 首先第一步要实现水的深浅判断&#xff0c;实现深水区和浅水区的区分。 这里需要用到深度图的概念。不去说太多概念&#xff0c;只去说怎么实现的&#xff0c;首先我们的水面是在…...

Java中的类和对象

文章目录 一、类和对象的基本概念二、类和对象的定义和使用1.创建类的语法2.创建类的对象3.范例(创建一个类的对象) 三、this引用1.什么是this引用2.this引用的特性 四、构造方法五、封装1.封装的概念2.访问限定符3.封装扩展包3.1包的概念3.2常见的包 六、static成员1.static修…...

多测师肖sir_高级金牌讲师_jenkins搭建

jenkins操作手册 一、jenkins介绍 1、持续集成&#xff08;CI&#xff09; Continuous integration 持续集成 团队开发成员每天都有集成他们的工作&#xff0c;通过每个成员每天至少集成一次&#xff0c;也就意味着一天有可 能多次集成。在工作中我们引入持续集成&#xff0c;通…...

Ps:色彩范围

Ps菜单&#xff1a;选择/色彩范围 Select/Color Range 色彩范围 Color Range是一个功能强大选择命令&#xff0c;不仅可以基于颜色进行选择&#xff0c;而且可以基于影调进行选择。不仅可以用来检测人脸选择肤色&#xff0c;也可用来选择超出印刷色域范围的区域。 在图层蒙版的…...

基于SSM的宠物医院管理系统

末尾获取源码 开发语言&#xff1a;Java Java开发工具&#xff1a;JDK1.8 后端框架&#xff1a;SSM 前端&#xff1a;Vue 数据库&#xff1a;MySQL5.7和Navicat管理工具结合 服务器&#xff1a;Tomcat8.5 开发软件&#xff1a;IDEA / Eclipse 是否Maven项目&#xff1a;是 目录…...

华为政企园区网络交换机产品集

产品类型产品型号产品说明 核心/汇聚交换机CloudEngine S5731-H24P4XCCloudEngine S5731-H24P4XC 提供 24个10/100/1000BASE-T以太网端口&#xff0c;4个万兆SFP&#xff0c;CloudEngine S5731-H 系列交换机是华为公司推出的新一代智能千兆交换机&#xff0c;基于华为公司统…...

NVMe FDP会被广泛使用吗?

文章开头&#xff0c;我们需要先了解固态硬盘的读写机制。我们知道&#xff0c;固态硬盘的存储单元是由闪存颗粒组成的&#xff0c;无法实现物理性的数据覆盖&#xff0c;只能擦除然后写入&#xff0c;重复这一过程。因而&#xff0c;我们可以想象得到&#xff0c;在实际读写过…...

[黑马程序员Pandas教程]——Pandas数据结构

目录&#xff1a; 学习目标认识Pandas中的数据结构和数据类型Series对象通过numpy.ndarray数组来创建通过list列表来创建使用字典或元组创建s对象在notebook中不写printSeries对象常用API布尔值列表获取Series对象中部分数据Series对象的运算DataFrame对象创建df对象DataFrame…...

AI 绘画 | Stable Diffusion 提示词

Prompts提示词简介 在Stable Diffusion中&#xff0c;Prompts是控制模型生成图像的关键输入参数。它们是一种文本提示&#xff0c;告诉模型应该生成什么样的图像。 Prompts可以是任何文本输入&#xff0c;包括描述图像的文本&#xff0c;如“一只橘色的短毛猫&#xff0c;坐在…...

tomcat默认最大线程数、等待队列长度、连接超时时间

tomcat默认最大线程数、等待队列长度、连接超时时间 tomcat的默认最大线程数是200&#xff0c;默认核心线程数(最小空闲线程数)是10。 在核心线程数满了之后&#xff0c;会直接启用最大线程数&#xff08;和JDK线程池不一样&#xff0c;JDK线程池先使用工作队列再使用最大线程…...

AI-调查研究-01-正念冥想有用吗?对健康的影响及科学指南

点一下关注吧&#xff01;&#xff01;&#xff01;非常感谢&#xff01;&#xff01;持续更新&#xff01;&#xff01;&#xff01; &#x1f680; AI篇持续更新中&#xff01;&#xff08;长期更新&#xff09; 目前2025年06月05日更新到&#xff1a; AI炼丹日志-28 - Aud…...

conda相比python好处

Conda 作为 Python 的环境和包管理工具&#xff0c;相比原生 Python 生态&#xff08;如 pip 虚拟环境&#xff09;有许多独特优势&#xff0c;尤其在多项目管理、依赖处理和跨平台兼容性等方面表现更优。以下是 Conda 的核心好处&#xff1a; 一、一站式环境管理&#xff1a…...

智慧医疗能源事业线深度画像分析(上)

引言 医疗行业作为现代社会的关键基础设施,其能源消耗与环境影响正日益受到关注。随着全球"双碳"目标的推进和可持续发展理念的深入,智慧医疗能源事业线应运而生,致力于通过创新技术与管理方案,重构医疗领域的能源使用模式。这一事业线融合了能源管理、可持续发…...

黑马Mybatis

Mybatis 表现层&#xff1a;页面展示 业务层&#xff1a;逻辑处理 持久层&#xff1a;持久数据化保存 在这里插入图片描述 Mybatis快速入门 ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/6501c2109c4442118ceb6014725e48e4.png //logback.xml <?xml ver…...

可靠性+灵活性:电力载波技术在楼宇自控中的核心价值

可靠性灵活性&#xff1a;电力载波技术在楼宇自控中的核心价值 在智能楼宇的自动化控制中&#xff0c;电力载波技术&#xff08;PLC&#xff09;凭借其独特的优势&#xff0c;正成为构建高效、稳定、灵活系统的核心解决方案。它利用现有电力线路传输数据&#xff0c;无需额外布…...

Python爬虫实战:研究feedparser库相关技术

1. 引言 1.1 研究背景与意义 在当今信息爆炸的时代,互联网上存在着海量的信息资源。RSS(Really Simple Syndication)作为一种标准化的信息聚合技术,被广泛用于网站内容的发布和订阅。通过 RSS,用户可以方便地获取网站更新的内容,而无需频繁访问各个网站。 然而,互联网…...

Nuxt.js 中的路由配置详解

Nuxt.js 通过其内置的路由系统简化了应用的路由配置&#xff0c;使得开发者可以轻松地管理页面导航和 URL 结构。路由配置主要涉及页面组件的组织、动态路由的设置以及路由元信息的配置。 自动路由生成 Nuxt.js 会根据 pages 目录下的文件结构自动生成路由配置。每个文件都会对…...

SpringBoot+uniapp 的 Champion 俱乐部微信小程序设计与实现,论文初版实现

摘要 本论文旨在设计并实现基于 SpringBoot 和 uniapp 的 Champion 俱乐部微信小程序&#xff0c;以满足俱乐部线上活动推广、会员管理、社交互动等需求。通过 SpringBoot 搭建后端服务&#xff0c;提供稳定高效的数据处理与业务逻辑支持&#xff1b;利用 uniapp 实现跨平台前…...

大模型多显卡多服务器并行计算方法与实践指南

一、分布式训练概述 大规模语言模型的训练通常需要分布式计算技术,以解决单机资源不足的问题。分布式训练主要分为两种模式: 数据并行:将数据分片到不同设备,每个设备拥有完整的模型副本 模型并行:将模型分割到不同设备,每个设备处理部分模型计算 现代大模型训练通常结合…...

用docker来安装部署freeswitch记录

今天刚才测试一个callcenter的项目&#xff0c;所以尝试安装freeswitch 1、使用轩辕镜像 - 中国开发者首选的专业 Docker 镜像加速服务平台 编辑下面/etc/docker/daemon.json文件为 {"registry-mirrors": ["https://docker.xuanyuan.me"] }同时可以进入轩…...