概述
前面两章收集了一些java 国际化相关api用法,以及spring MVC对国际化的支持。今天打算采用spring MVC搭建一套支持国际化的demo环境(采用的Spring MVC版本为:4.3.1.RELEASE),代码已经放到github,地址请见文章结尾。
主要整合内容包括:
1、view层采用的Freemaker。
2、使用自定义的formatter,对日期、货币等进行转化。
springMVC 相关配置
web.xml 配置:主要包含三部分,“Spring 容器的配置”、“Spring mvc 配置”、“spring 字符集处理配置”。完整的内容如下:
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>locale-demo</display-name> <!-- step1 Spring 容器启动器 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- spring 容器配置 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-config.xml</param-value> </context-param> <!-- step2 Spring mvc 配置 --> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:spring-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> <!-- 程序启动时装在该servlet --> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- step3 spring character encoding --> <filter> <filter-name>Character Encoding</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>Character Encoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
Spring容器对应的配置文件是:spring-config.xml ,SpringMVC对应的配置文件是spring-mvc.xml。spring-config.xml 可以手动配置bean、指定属性配置文件(.properties)、以及制定其他子配置文件,如:数据库配置文件、工具类配置文件、外部接口配置文件等。本次demo环境,只是整合框架,具体内容根据项目需要再添加。
spring-config.xml内容如下:
<?xml version="1.0" encoding="GBK"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" default-autowire="byName"> <!-- 加载属性配置文件,主要为spring bean实例化 提供配置支持--> <bean id="propertyPlaceholder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:spring-locale.properties</value> </list> </property> </bean> <!--导入其他所需的配置文件 --> <!-- <import resource="spring/*.xml" /> 配置文件尽量根据模块进行拆分--> </beans>
在手动注入bean时,往往我们需要一些配置参数,比如:数据库用户名、密码等,这些参数都可以提前配置到属性配置文件spring-locale.properties中。本次demo spring-locale.properties为空,根据业务需要添加。
SpringMVC对应的配置文件spring-mvc.xml,是本次讲解的重点。整合freemaker、以及国际化支持等都在该配置文件中体现,内容如下:
<?xml version="1.0" encoding="GBK"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd" default-autowire="byName"> <mvc:annotation-driven /> <mvc:default-servlet-handler /> <context:component-scan base-package="com.sky.locale.demo.controller" > <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> <mvc:resources mapping="/css/**" location="/css/" /> <mvc:resources mapping="/*.html" location="/" /> <!-- Freemarker属性配置--> <bean id="freemarkerConfiguration" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="location" value="classpath:freemarker.properties"/> </bean> <bean id="fmXmlEscape" class="freemarker.template.utility.XmlEscape" /> <!-- Freemarker配置--> <bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> <property name="freemarkerSettings" ref="freemarkerConfiguration"/> <property name="templateLoaderPath"> <value>/WEB-INF/view/</value> </property> <property name="freemarkerVariables"> <map> <entry key="xml_escape" value-ref="fmXmlEscape" /> </map> </property> </bean> <!-- 配置freeMarker视图解析器 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView"/> <property name="contentType" value="text/html; charset=utf-8"/> <property name="cache" value="false"/> <property name = "suffix" value = ".ftl"></property> <property name="exposeRequestAttributes" value="true" /> <property name="exposeSessionAttributes" value="true" /> <property name="exposeSpringMacroHelpers" value="true" /> <property name="requestContextAttribute" value="request"/> </bean> <!-- 图片上传 处理--> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="defaultEncoding" value="utf-8" /> <property name="maxUploadSize" value="10485760000" /> <property name="maxInMemorySize" value="40960" /> </bean> <!-- 国际化资源文件 --> <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basenames" > <list> <value>/WEB-INF/resource/usermsg</value> <value>/WEB-INF/resource/userlabels</value> </list> </property> <property name="defaultEncoding" value="UTF-8"/> </bean> <!-- 本地化配置 --> <bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver"> <property name="cookieName" value="clientlanguage"/> <property name="cookieMaxAge" value="94608000"/> <property name="defaultLocale" value="en" /> </bean> <mvc:annotation-driven conversion-service="formatService" /> <!-- formatter转换配置 --> <bean id="formatService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"> <property name="formatters"> <set> <!--<bean class="org.springframework.format.number.CurrencyStyleFormatter"> </bean> <bean class="org.springframework.format.number.NumberStyleFormatter"> </bean> <bean class="org.springframework.format.number.PercentStyleFormatter"> </bean> <bean class="org.springframework.format.datetime.DateFormatter"> </bean> --> <bean class="com.sky.locale.demo.formatter.MyDateFormatter" /> <bean class="com.sky.locale.demo.formatter.MyCurrencyFormatter" /> </set> </property> </bean> </beans>
这里主要说下与Freemaker整合的配置,其他关于国际化的配置说明可以参考上一章《java国际化之---springMVC(二)》。
首先看下Freemaker基础配置:
<!-- Freemarker配置--> <bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> <property name="freemarkerSettings" ref="freemarkerConfiguration"/> <property name="templateLoaderPath"> <value>/WEB-INF/view/</value> </property> <property name="freemarkerVariables"> <map> <entry key="xml_escape" value-ref="fmXmlEscape" /> </map> </property> </bean>
1、freemarkerSettings属性:设置FreeMarker启动属性配置,可以直接配置,也可以配置到属性文件,这次采用的后者。对应的属性配置为:
<!-- Freemarker属性配置--> <bean id="freemarkerConfiguration" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="location" value="classpath:freemarker.properties"/> </bean>
可以看到读取了属性配置文件freemarker.properties,再来看下中的内容:
#设置标签类型:square_bracket:[] auto_detect:[]<> tag_syntax=auto_detect #模版缓存时间,单位:秒 template_update_delay=0 default_encoding=UTF-8 output_encoding=UTF-8 locale=zh_CN #设置数字格式 ,防止出现 000.00 number_format=\# #变量为空时,不会报错 classic_compatible=true #这个表示每个freemarker的视图页面都会自动引入这个ftl文件。里面定议的就是一些宏,如text文本框,各种form元素 #auto_import="/WEB-INF/templates/index.ftl" as do auto_import="/common/spring.ftl" as spring
具体根据自己的需要调整,这里特别说下auto_import="/common/spring.ftl" as spring,spring.ftl是spring MVC针对Freemaker实现的宏,可以用来读取国际化配置信息等。该文件在spring-webmvc-4.3.1.RELEASE.jar中,具体路径如下:
将该文件copy到WEB-INF/common路径下,还可以根据自己需要修改和新增宏命令。
2、templateLoaderPath属性:配置Freemaker模板文件路径前缀,这里配置的/WEB-INF/view/,注意根目录别配置错了。Spring MVC还支持,多种视图一起使用,一般使用二级目录区分,比如:/WEB-INF/vm/对应velocity,/WEB-INF/jsp/ 对应原始jsp 等等。
3、freemarkerVariables属性:配置Freemaker的自定义标签,这里是个map结构,可以配置多个。
再来看下Freemaker的视图配置:
<!-- 配置freeMarker视图解析器 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView"/> <property name="contentType" value="text/html; charset=utf-8"/> <property name="cache" value="false"/> <property name = "suffix" value = ".ftl"></property> <property name="exposeRequestAttributes" value="true" /> <property name="exposeSessionAttributes" value="true" /> <property name="exposeSpringMacroHelpers" value="true" /> <property name="requestContextAttribute" value="request"/> </bean>
如前面所说,你还可以配置多个视图解析器:jsp文件对应的InternalResourceViewResolver解析器,以及velocity对应的VelocityLayoutViewResolver视图解析器,并且Spring MVC允许你配置多个一起使用,根据不同的业务使用不同的视图解析器。
最终配置相关的目录结构如下:
国际化配置文件、以及Freemaker模板文件目录结构如下:
Spring相关配置就说这些吧,关于Freemaker模板文件后面讲解,下面来看看Controller。
Controller控制器代码
Controller相关的代码结构如下:
controller包中对应的是本实例的控制器存放目录,首先来看下UserController,主要处理4类请求:add、save、edit、changelanguage 分别对应:添加用户、保存用户、修改用户、修改语言。具体代码如下:
@Controller public class UserController { @RequestMapping(value="add") public String addUser(Model model) { model.addAttribute(new User()); return "/user/UserForm"; } @RequestMapping(value="save") public String saveUser(@ModelAttribute User user, BindingResult bindingResult, Model model) { UserValidator userValidator = new UserValidator(); userValidator.validate(user, bindingResult); if (bindingResult.hasErrors()) { FieldError fieldError = bindingResult.getFieldError(); System.out.println("Code:" + fieldError.getCode() + ", field:" + fieldError.getField()); return "/user/UserForm"; } // save product here model.addAttribute("org.springframework.validation.BindingResult.user",new BindException(bindingResult)); return "/user/UserInfo"; } /** * * @param model * @return */ @RequestMapping(value="edit") public String editUser(Model model) { //省略从数据库中查询代码 User user = new User(); user.setName("张三"); Date now = new Date(); user.setBirthday(now); user.setMoney(new BigDecimal("12.12")); model.addAttribute("user",user); return "/user/UserForm"; } @RequestMapping(value = "/changelanguage", method = RequestMethod.POST) public void changeLanguage(@RequestParam String new_lang,HttpServletRequest request, HttpServletResponse response) { String msg = ""; try { LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request); if (localeResolver == null) { throw new IllegalStateException("No LocaleResolver found: not in a DispatcherServlet request?"); } LocaleEditor localeEditor = new LocaleEditor(); localeEditor.setAsText(new_lang); localeResolver.setLocale(request, response, (Locale)localeEditor.getValue()); msg = "Change Language Success!"; } catch(Exception ex) { msg = "error"; ex.printStackTrace(); } response.setCharacterEncoding(CharEncoding.UTF_8); try { response.getWriter().print(msg); } catch (IOException e) { e.printStackTrace(); } } }
View视图
这里采用的是Freemaker视图,模板文件主要有两个:
首先看下UserForm.ftl(UserInfo.ftl文件内容不再累述):
<!DOCTYPE html> <html> <head> <title><@spring.message "page.user.title"/> </title> <link rel="stylesheet" href="/css/main.css"> </head> <body> <div id="global"> <@spring.message "current.locale"/> : ${request.locale} <br/> <@spring.message "select.language"/> : <span><a href="javascript:void(0)" onclick="changeLanguage('en_GB')">EN</a></span> |<span><a href="javascript:void(0)" onclick="changeLanguage('zh_CN')">CN</a></span> <form name="user" action="save" method="post"> <fieldset> <legend><@spring.message "user.form.name"/></legend> <p> <@spring.bind "user.name" /> <label for="name"><@spring.message "label.userName"/>:</label> <input id="name" type="text" name="name" value="${user.name}" cssErrorClass="error"/> <@spring.showErrors "<br/>" cssClass="error"/> </p> <p> <@spring.bind "user.birthday" /> <label for="birthday"><@spring.message "label.birthday"/>: </label> <input id="birthday" type="text" name="birthday" value="<#if (user.birthday)??> ${(user.birthday?datetime)} </#if>" cssErrorClass="error"/> <@spring.showErrors "<br/>" cssClass="error"/> </p> <p> <@spring.bind "user.money" /> <label for="money"><@spring.message "label.money"/>: </label> <input id="money" type="text" name="money" value="${(user.money?string.currency)!}" cssErrorClass="error"/> <@spring.showLastError classOrStyle="error"/> </p> <p id="buttons"> <input id="reset" type="reset" tabindex="4" value="<@spring.message "button.reset"/>"> <input id="submit" type="submit" tabindex="5" value="<@spring.message "button.submit"/>"> </p> </fieldset> </form> </div> </body> </html> <script type="text/javascript" src="//misc.360buyimg.com/jdf/lib/jquery-1.6.4.js?t=1705252218"></script> <script type="text/javascript"> function changeLanguage(language) { $.ajax({ type: "POST", url:"/changelanguage", data: "new_lang="+language, dataType:"text", async: true, error: function(data, error) {alert("change lang error!"); alert(error)}, success: function(data) { window.location.reload(); } }); } </script>
需要说明以下几点:
1、@spring.message,带有这个标记的标签,表面是本地化消息,这里会根据不同的语言选择不同的国际化配置文件,再根据不同的key选择不同的消息。
比如当前语言为cn_ZH(汉语_中国大陆),对应的配置文件为:usermsg_zh_CN.properties、userlabels_zh_CN.properties。<@spring.message "page.user.title"/>标签中,page.user.title对应的值在userlabels_zh_CN.properties中,配置为:page.user.title=新增用户,该位置的渲染结果即为:“新增用户”。配置文件中的内容,就不贴出来了,感兴趣的可以从文章结尾的github地址中下载。
2、@spring.bind、@spring.showErrors分别为绑定变量,和显示该变量的错误信息。连同1中的@spring.message 这三个标签都是在spring.ftl中定义的。
3、Freemaker国际化支持,${(user.birthday?datetime)}、${(user.money?string.currency)} 会根据不同的语言国家,做不同的格式显示。比如中国,货币显示为:¥12.12;英语英国,货币显示为:£12.12。
其他关于Freemaker的标签说明,参考其官方文档:http://freemarker.org/docs/ref_directive_local.html
日期、货币国际化处理
SpringMVC主要通过定义不同Formatter实现对日期、货币等国际化处理。 Springmvc 自带对日期、货币国际化处理Formatter实现,我们也可以根据自己业务定义自己的Formatter。
自定义的日期时间formatter,MyDateFormatter,调用其可以把String格式的日期转换为Date型,比如:可以把英文环境下的“Jun 13, 2017 9:40:57 PM”,以及中文环境下的” 2017-06-13 21:40:57” 转换为相同的Date,实现如下:
public class MyDateFormatter implements Formatter<Date> { @Override public Date parse(String s, Locale locale) throws ParseException{ DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale); System.out.println("parse"); try { return df.parse(s); } catch (ParseException e) { throw new IllegalArgumentException( "invalid date format."); } } @Override public String print(Date date, Locale locale) { DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale); System.out.println("format"); return df.format(date); } }
自定义的货币处理formatter,MyCurrencyFormatter,可以实现把不同国家带符号的价格转换为BigDecimal,实现如下:
public class MyCurrencyFormatter implements Formatter<BigDecimal> { /** * 去掉货币符号,并转换为BigDecimal * @param s * @param locale * @return * @throws ParseException */ @Override public BigDecimal parse(String s, Locale locale) throws ParseException { try { NumberFormat curF = NumberFormat.getCurrencyInstance(locale); BigDecimal bd = new BigDecimal(curF.parse(s).toString());//去掉货币符号 return bd; } catch (ParseException e) { //如果没有带单位 转换会失败,但是如果是数字可以成功转换成BigDecimal,主要是springMVC做了兼容处理 throw new IllegalArgumentException( "invalid Currency format."); } } /** * 把BigDecimal 转换为对应国家带货币单位的 字符串格式 * @param bigDecimal * @param locale * @return */ @Override public String print(BigDecimal bigDecimal, Locale locale) { NumberFormat curF = NumberFormat.getCurrencyInstance(locale); return curF.format(bigDecimal); } }
最后通过配置注入到Spring 容器中,当表单提交时就可以实现类型自动转换,配置如下:
<!-- formatter转换配置 -->
<bean id="formatService"
class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<property name="formatters">
<set>
<!-- 使用SpringMVC 自带的formatters处理 日期、数字国际化 -->
<!--<bean class="org.springframework.format.number.CurrencyStyleFormatter">
</bean>
<bean class="org.springframework.format.number.NumberStyleFormatter">
</bean>
<bean class="org.springframework.format.number.PercentStyleFormatter">
</bean>
<bean class="org.springframework.format.datetime.DateFormatter">
</bean> -->
<bean class="com.sky.locale.demo.formatter.MyDateFormatter" />
<bean class="com.sky.locale.demo.formatter.MyCurrencyFormatter" />
</set>
</property>
</bean>
示例演示
以上实例demo代码,已经放到github:https://github.com/gantianxing/locale-demo.git,方便以后继续整合使用,也欢迎感兴趣的朋友下载。下载成功后,使用idea打开,打包即可运行。
启动成功后,首先访问http://localhost/add
访问:http://localhost/edit
修改相关数据后,点添加按钮,返回:
点击add页面的‘EN’,可以切换到英文版(ps:如果切换不成功,tomcat版本请换成tomcat8以上):
关于英文版的操作,就不再演示了。感兴趣的可以自己操作下,如有问题请指正,欢迎留言。
以上代码GitHub地址https://github.com/gantianxing/locale-demo.git。
相关推荐
在本项目中,我们主要探讨如何手动构建一个基于SpringMVC、Spring Data JPA、Hibernate以及FreeMarker模板引擎的Maven工程,同时实现环境切换功能。这个基础框架为日常开发工作提供了必要的支持。 首先,SpringMVC...
通过这个"SpringMVC+Freemaker Demo",你可以深入了解这两种技术的结合使用,以及它们如何协同工作来构建一个完整的Web应用。实际操作过程中,可以进一步学习异常处理、国际化、缓存等高级话题,提升自己的开发能力...
这个demo项目展示了如何将这些技术有效地集成,以实现数据持久化、模板渲染、权限管理以及日志记录等功能。接下来,我们将深入探讨这些关键组件及其在项目中的作用。 1. **SpringBoot**:SpringBoot是Spring框架的...
"SpringMVC集成Freemarker例子demo"是一个实际的项目示例,展示了如何在SpringMVC框架下配置和使用Freemarker。在这个例子中,你可能能看到如何配置SpringMVC的`freemarkerConfigurer`,设置模板路径,以及如何在...
内容概要:本文详细介绍了基于多目标粒子群(MOPSO)算法的冷热电联供(CCHP)综合能源系统运行优化的方法和技术细节。文章首先构建了一个涵盖冷、热、电负荷的优化调度模型,该模型不仅考虑了多种能源资源如燃气轮机、电制冷机、锅炉和风光机组,还包括与上级电网的购售电交易。随后,文章展示了MOPSO算法的具体实现步骤,包括粒子初始化、迭代更新、惯性权重调整、非支配排序和拥挤度计算等关键技术环节。此外,文中还讨论了MATLAB仿真平台的优势及其在处理多时间尺度耦合、风光出力波动等方面的应用。最终,通过Pareto前沿分析,揭示了系统在不同条件下的最优运行模式。 适用人群:适用于从事能源系统优化的研究人员、工程师以及对多目标优化算法有兴趣的学习者。 使用场景及目标:①帮助研究人员理解和应用MOPSO算法进行CCHP系统的优化;②为工程师提供具体的代码实现和仿真工具,以便更好地设计和管理实际的能源系统;③促进学术交流和技术进步,推动可持续能源的发展。 其他说明:文章提供了详细的MATLAB代码片段,便于读者理解和复现实验结果。同时,强调了多目标优化在解决复杂能源系统问题中的重要性和优越性。
原始数据集
文档支持目录章节跳转同时还支持阅读器左侧大纲显示和章节快速定位,文档内容完整、条理清晰。文档内所有文字、图表、函数、目录等元素均显示正常,无任何异常情况,敬请您放心查阅与使用。文档仅供学习参考,请勿用作商业用途。 编译闪电般迅速,并发性能卓越,部署轻松简单!Go 语言以极简设计理念和出色工程性能,成为云原生时代的首选编程语言。从 Docker 到 Kubernetes,全球顶尖科技企业都在采用 Go。点击了解 Go 语言的核心优势、实战窍门和未来走向,开启高效编程的全新体验!
数据库
内容概要:本文详细介绍了基于Matlab 2021a的异步电机矢量控制系统中电流滞环控制的实现过程。首先,文章解释了电流环的整体结构,包括定子电流的坐标变换、转矩分量和励磁分量的分离以及旋转变压器模块的应用。接着,展示了电流滞环控制的核心代码,强调了带积分修正的滞环控制机制,并讨论了SVPWM模块的实现技巧。此外,文章探讨了速度环PI参数的自整定设计、谐波分析、磁链观测器的改进方案以及仿真加速技巧。最后,分享了一些实用的调试经验和仿真优化方法,如参数自适应调整、变步长求解器的选择和数据存储格式的优化。 适合人群:从事电机控制领域的研究人员和技术人员,尤其是对异步电机矢量控制和电流滞环控制感兴趣的读者。 使用场景及目标:适用于希望深入了解异步电机矢量控制系统中电流滞环控制实现细节的研究人员和技术人员。目标是帮助读者掌握电流滞环控制的关键技术和调试技巧,提高仿真实践能力。 其他说明:文中提供了丰富的代码片段和调试经验,有助于读者更好地理解和应用所介绍的技术。同时,报告中还包括详细的故障分析和解决方案,确保读者能够避免常见陷阱并顺利进行仿真。
内容概要:本文详细介绍了如何在LabVIEW 2019环境中实现与三菱PLC的通信及其多线程交互。首先探讨了使用OPC和MC两种通讯协议与三菱PLC建立连接的方法,接着讲述了SQLite数据库用于数据存储的具体步骤,然后阐述了JKI状态机框架的应用,最后讲解了通过数组队列实现多线程交互的技术细节。文中不仅提供了具体的代码示例,还分享了许多实用的经验技巧,如异常处理、性能优化等。 适合人群:从事工业自动化领域的工程师和技术人员,尤其是那些正在使用或计划使用LabVIEW进行PLC通信和数据处理的人群。 使用场景及目标:适用于需要构建高效稳定的工业控制系统的企业和个人开发者。主要目的是帮助读者掌握如何利用LabVIEW平台完成复杂的PLC通信任务,提高系统的可靠性和效率。 其他说明:作者强调了在实际应用过程中需要注意的问题,例如硬件兼容性、网络稳定性、数据安全性等方面的内容,并给出了针对性的解决方案。此外,还提到了一些常见的误区和潜在的风险点,为后续的工作提供了宝贵的参考资料。
计算机视觉_深度学习_图像处理_目标检测_OpenCV_TensorFlow_PyTorch_基于YOLOv5改进算法的高精度实时多目标检测与跟踪系统_用于智能监控_自动驾驶_工业
文档支持目录章节跳转同时还支持阅读器左侧大纲显示和章节快速定位,文档内容完整、条理清晰。文档内所有文字、图表、函数、目录等元素均显示正常,无任何异常情况,敬请您放心查阅与使用。文档仅供学习参考,请勿用作商业用途。 编译闪电般迅速,并发性能卓越,部署轻松简单!Go 语言以极简设计理念和出色工程性能,成为云原生时代的首选编程语言。从 Docker 到 Kubernetes,全球顶尖科技企业都在采用 Go。点击了解 Go 语言的核心优势、实战窍门和未来走向,开启高效编程的全新体验!
内容概要:本文详细介绍了威纶通触摸屏与施耐德ATV12变频器之间的Modbus通讯方法,涵盖硬件接线、参数设置、控制程序编写以及调试技巧。首先,文章讲解了正确的硬件连接方式,强调了接线规范和注意事项,如使用带屏蔽的双绞线并确保正确接地。接着,针对ATV12变频器的具体参数设置进行了详尽说明,包括通信模式的选择、波特率、校验位等重要参数的配置。随后,文章展示了如何在威纶通触摸屏上创建Modbus RTU设备,并提供了具体的配置参数和控制命令示例。此外,文中还分享了一些常见的调试问题及其解决办法,如通讯超时、频率设定异常等。最后,给出了实用的调试建议,如使用串口助手抓包分析和加入通讯心跳检测等功能。 适合人群:从事工业自动化领域的工程师和技术人员,尤其是那些负责PLC编程、HMI界面开发以及设备集成工作的专业人员。 使用场景及目标:适用于需要将威纶通触摸屏与施耐德ATV12变频器进行Modbus通讯连接的实际工程项目中,帮助技术人员顺利完成设备间的通讯配置,确保系统稳定可靠运行。 其他说明:本文不仅提供了详细的理论指导,还结合了丰富的实践经验,能够有效地提高读者在实际工作中解决问题的能力。同时提醒读者,在进行相关操作前务必仔细阅读官方文档,避免因误操作造成不必要的损失。
文档支持目录章节跳转同时还支持阅读器左侧大纲显示和章节快速定位,文档内容完整、条理清晰。文档内所有文字、图表、函数、目录等元素均显示正常,无任何异常情况,敬请您放心查阅与使用。文档仅供学习参考,请勿用作商业用途。 Rust 以内存安全、零成本抽象和并发高效的特性,重塑编程体验。无需垃圾回收,却能通过所有权与借用检查机制杜绝空指针、数据竞争等隐患。从底层系统开发到 Web 服务构建,从物联网设备到高性能区块链,它凭借出色的性能和可靠性,成为开发者的全能利器。拥抱 Rust,解锁高效、安全编程新境界!
文档支持目录章节跳转同时还支持阅读器左侧大纲显示和章节快速定位,文档内容完整、条理清晰。文档内所有文字、图表、函数、目录等元素均显示正常,无任何异常情况,敬请您放心查阅与使用。文档仅供学习参考,请勿用作商业用途。 编译闪电般迅速,并发性能卓越,部署轻松简单!Go 语言以极简设计理念和出色工程性能,成为云原生时代的首选编程语言。从 Docker 到 Kubernetes,全球顶尖科技企业都在采用 Go。点击了解 Go 语言的核心优势、实战窍门和未来走向,开启高效编程的全新体验!
文档支持目录章节跳转同时还支持阅读器左侧大纲显示和章节快速定位,文档内容完整、条理清晰。文档内所有文字、图表、函数、目录等元素均显示正常,无任何异常情况,敬请您放心查阅与使用。文档仅供学习参考,请勿用作商业用途。 Rust 以内存安全、零成本抽象和并发高效的特性,重塑编程体验。无需垃圾回收,却能通过所有权与借用检查机制杜绝空指针、数据竞争等隐患。从底层系统开发到 Web 服务构建,从物联网设备到高性能区块链,它凭借出色的性能和可靠性,成为开发者的全能利器。拥抱 Rust,解锁高效、安全编程新境界!
文档支持目录章节跳转同时还支持阅读器左侧大纲显示和章节快速定位,文档内容完整、条理清晰。文档内所有文字、图表、函数、目录等元素均显示正常,无任何异常情况,敬请您放心查阅与使用。文档仅供学习参考,请勿用作商业用途。 Rust 以内存安全、零成本抽象和并发高效的特性,重塑编程体验。无需垃圾回收,却能通过所有权与借用检查机制杜绝空指针、数据竞争等隐患。从底层系统开发到 Web 服务构建,从物联网设备到高性能区块链,它凭借出色的性能和可靠性,成为开发者的全能利器。拥抱 Rust,解锁高效、安全编程新境界!
文档支持目录章节跳转同时还支持阅读器左侧大纲显示和章节快速定位,文档内容完整、条理清晰。文档内所有文字、图表、函数、目录等元素均显示正常,无任何异常情况,敬请您放心查阅与使用。文档仅供学习参考,请勿用作商业用途。 Rust 以内存安全、零成本抽象和并发高效的特性,重塑编程体验。无需垃圾回收,却能通过所有权与借用检查机制杜绝空指针、数据竞争等隐患。从底层系统开发到 Web 服务构建,从物联网设备到高性能区块链,它凭借出色的性能和可靠性,成为开发者的全能利器。拥抱 Rust,解锁高效、安全编程新境界!
文档支持目录章节跳转同时还支持阅读器左侧大纲显示和章节快速定位,文档内容完整、条理清晰。文档内所有文字、图表、函数、目录等元素均显示正常,无任何异常情况,敬请您放心查阅与使用。文档仅供学习参考,请勿用作商业用途。 编译闪电般迅速,并发性能卓越,部署轻松简单!Go 语言以极简设计理念和出色工程性能,成为云原生时代的首选编程语言。从 Docker 到 Kubernetes,全球顶尖科技企业都在采用 Go。点击了解 Go 语言的核心优势、实战窍门和未来走向,开启高效编程的全新体验!