- 浏览: 2578498 次
- 性别:
- 来自: 成都
-
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Spring3 and REST Integration(IV)Controller JUnit Test and Mock/Servlet
There are 4 different ways to JUnit our REST style JSON data Controller.
Servlet Mock
The first way is to use Servlet Mock. There are 2 base classes needed in our project
The Mock Web Application Loader class will be like these:
package com.sillycat.easyrestserver.core;
import javax.servlet.ServletException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.SourceFilteringListener;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.io.FileSystemResourceLoader;
import org.springframework.mock.web.MockServletConfig;
import org.springframework.mock.web.MockServletContext;
import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.test.context.support.AbstractContextLoader;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.XmlWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
public class MockWebApplicationContextLoader extends AbstractContextLoader {
MockWebApplication configuration;
static MockServletContext servletContext;
static MockServletConfig servletConfig;
static XmlWebApplicationContext webApplicationContext;
public ApplicationContext loadContext(
MergedContextConfiguration mergedConfig) throws Exception {
servletConfig = new MockServletConfig(servletContext,
configuration.name());
servletContext = new MockServletContext(configuration.webapp(),
new FileSystemResourceLoader());
webApplicationContext = new XmlWebApplicationContext();
webApplicationContext.getEnvironment().setActiveProfiles(
mergedConfig.getActiveProfiles());
servletContext.setAttribute(
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
webApplicationContext);
webApplicationContext.setServletConfig(servletConfig);
webApplicationContext.setConfigLocations(configuration.locations());
prepareWebApplicationContext();
return webApplicationContext;
}
public ApplicationContext loadContext(String... locations) throws Exception {
servletConfig = new MockServletConfig(servletContext,
configuration.name());
servletContext = new MockServletContext(configuration.webapp(),
new FileSystemResourceLoader());
webApplicationContext = new XmlWebApplicationContext();
servletContext.setAttribute(
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
webApplicationContext);
webApplicationContext.setServletConfig(servletConfig);
webApplicationContext.setConfigLocations(locations);
prepareWebApplicationContext();
return webApplicationContext;
}
private void prepareWebApplicationContext() throws ServletException {
@SuppressWarnings("serial")
final DispatcherServlet dispatcherServlet = new DispatcherServlet() {
protected WebApplicationContext createWebApplicationContext(
ApplicationContext parent) {
return webApplicationContext;
}
};
webApplicationContext
.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {
public void postProcessBeanFactory(
ConfigurableListableBeanFactory beanFactory) {
beanFactory.registerResolvableDependency(
DispatcherServlet.class, dispatcherServlet);
}
});
webApplicationContext
.addApplicationListener(new SourceFilteringListener(
webApplicationContext,
new ApplicationListener<ContextRefreshedEvent>() {
public void onApplicationEvent(
ContextRefreshedEvent event) {
dispatcherServlet.onApplicationEvent(event);
}
}));
webApplicationContext.refresh();
webApplicationContext.registerShutdownHook();
dispatcherServlet.setContextConfigLocation("");
dispatcherServlet.init(servletConfig);
}
protected String[] generateDefaultLocations(Class<?> clazz) {
extractConfiguration(clazz);
return super.generateDefaultLocations(clazz);
}
protected String[] modifyLocations(Class<?> clazz, String... locations) {
extractConfiguration(clazz);
return super.modifyLocations(clazz, locations);
}
private void extractConfiguration(Class<?> clazz) {
configuration = AnnotationUtils.findAnnotation(clazz,
MockWebApplication.class);
if (configuration == null) {
throw new IllegalArgumentException("Test class " + clazz.getName()
+ " must be annotated @MockWebApplication.");
}
}
protected String getResourceSuffix() {
return "-context.xml";
}
}
And we will use the mockwebapplication class to hold our annotation configuration:
package com.sillycat.easyrestserver.core;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface MockWebApplication {
String webapp() default "src/main/webapp";
String name();
String[] locations() default "src/test/test-content.xml";
}
The test class will be like this:
package com.sillycat.easyrestserver.controller;
import java.io.IOException;
import javax.servlet.ServletException;
import org.codehaus.jackson.map.ObjectMapper;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.HandlerMapping;
import com.sillycat.easyrestserver.core.MockWebApplication;
import com.sillycat.easyrestserver.core.MockWebApplicationContextLoader;
import com.sillycat.easyrestserver.model.Company;
import com.sillycat.easyrestserver.model.Person;
/**
* mock the servlet and use servlet to test our controller
* servlet.service(mockRequest, mockResponse);
* can not mock the service or manager in controller
* @author karl
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = MockWebApplicationContextLoader.class)
@MockWebApplication(name = "easyrestserver", locations = "classpath:test-context.xml")
public class PersonControllerTest1 {
@Autowired
private DispatcherServlet servlet;
ObjectMapper mapper;
Person person;
MockHttpServletRequest mockRequest;
MockHttpServletResponse mockResponse;
@Before
public void setUp() throws ServletException, IOException {
MockitoAnnotations.initMocks(this);
mapper = new ObjectMapper();
person = new Person();
person.setCompany(new Company());
person.setId(1);
person.setPersonName("person1");
mockRequest = new MockHttpServletRequest();
mockRequest.setAttribute(HandlerMapping.INTROSPECT_TYPE_LEVEL_MAPPING,true);
mockResponse = new MockHttpServletResponse();
}
@Test
public void get() throws Exception {
mockRequest.setMethod("GET");
mockRequest.setRequestURI("/person/1");
mockRequest.setContentType(MediaType.APPLICATION_JSON_VALUE);
mockResponse = new MockHttpServletResponse();
servlet.service(mockRequest, mockResponse);
Person actualPerson = mapper.readValue(
mockResponse.getContentAsString(), Person.class);
Assert.assertEquals(actualPerson.getId(), person.getId());
}
@Test
public void add() throws Exception{
mockRequest.setContentType(MediaType.APPLICATION_JSON_VALUE);
mockRequest.setMethod("POST");
mockRequest.setRequestURI("/person");
String jsonPerson = mapper.writeValueAsString(person);
mockRequest.setContent(jsonPerson.getBytes());
servlet.service(mockRequest, mockResponse);
Assert.assertEquals(mockResponse.getStatus(), 200);
Person actualPerson = mapper.readValue(
mockResponse.getContentAsString(), Person.class);
Assert.assertEquals(actualPerson.getId(), person.getId());
}
}
The sample project named easyrestserver.
references:
spring 3 and rest
http://hi.baidu.com/luohuazju/blog/item/1fe358ea5da873c0d539c9b4.html
http://hi.baidu.com/luohuazju/blog/item/c380b67f9946421b28388ab7.html
http://hi.baidu.com/luohuazju/blog/item/3b68f609650a37dc3bc763c5.html
tcpdump on mac
http://support.apple.com/kb/HT3994
http://hi.baidu.com/luohuazju/blog/item/da079eb3de7109b2d9335aa5.html
mock test
http://www.iteye.com/topic/828513
http://stackoverflow.com/questions/9138555/spring-framework-test-restful-web-service-controller-offline-i-e-no-server-n
http://stackoverflow.com/questions/1401128/how-to-unit-test-a-spring-mvc-controller-using-pathvariable/2457902#2457902
http://ted-young.googlecode.com/svn/trunk/blog.spring-mvc-integration-testing/
https://github.com/springside/springside4/blob/master/examples/mini-service/src/test/java/org/springside/examples/miniservice/webservice/ws/AccountWebServiceTest.java
https://github.com/SpringSource/spring-test-mvc
http://elf8848.iteye.com/blog/875830
There are 4 different ways to JUnit our REST style JSON data Controller.
Servlet Mock
The first way is to use Servlet Mock. There are 2 base classes needed in our project
The Mock Web Application Loader class will be like these:
package com.sillycat.easyrestserver.core;
import javax.servlet.ServletException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.SourceFilteringListener;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.io.FileSystemResourceLoader;
import org.springframework.mock.web.MockServletConfig;
import org.springframework.mock.web.MockServletContext;
import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.test.context.support.AbstractContextLoader;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.XmlWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
public class MockWebApplicationContextLoader extends AbstractContextLoader {
MockWebApplication configuration;
static MockServletContext servletContext;
static MockServletConfig servletConfig;
static XmlWebApplicationContext webApplicationContext;
public ApplicationContext loadContext(
MergedContextConfiguration mergedConfig) throws Exception {
servletConfig = new MockServletConfig(servletContext,
configuration.name());
servletContext = new MockServletContext(configuration.webapp(),
new FileSystemResourceLoader());
webApplicationContext = new XmlWebApplicationContext();
webApplicationContext.getEnvironment().setActiveProfiles(
mergedConfig.getActiveProfiles());
servletContext.setAttribute(
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
webApplicationContext);
webApplicationContext.setServletConfig(servletConfig);
webApplicationContext.setConfigLocations(configuration.locations());
prepareWebApplicationContext();
return webApplicationContext;
}
public ApplicationContext loadContext(String... locations) throws Exception {
servletConfig = new MockServletConfig(servletContext,
configuration.name());
servletContext = new MockServletContext(configuration.webapp(),
new FileSystemResourceLoader());
webApplicationContext = new XmlWebApplicationContext();
servletContext.setAttribute(
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
webApplicationContext);
webApplicationContext.setServletConfig(servletConfig);
webApplicationContext.setConfigLocations(locations);
prepareWebApplicationContext();
return webApplicationContext;
}
private void prepareWebApplicationContext() throws ServletException {
@SuppressWarnings("serial")
final DispatcherServlet dispatcherServlet = new DispatcherServlet() {
protected WebApplicationContext createWebApplicationContext(
ApplicationContext parent) {
return webApplicationContext;
}
};
webApplicationContext
.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {
public void postProcessBeanFactory(
ConfigurableListableBeanFactory beanFactory) {
beanFactory.registerResolvableDependency(
DispatcherServlet.class, dispatcherServlet);
}
});
webApplicationContext
.addApplicationListener(new SourceFilteringListener(
webApplicationContext,
new ApplicationListener<ContextRefreshedEvent>() {
public void onApplicationEvent(
ContextRefreshedEvent event) {
dispatcherServlet.onApplicationEvent(event);
}
}));
webApplicationContext.refresh();
webApplicationContext.registerShutdownHook();
dispatcherServlet.setContextConfigLocation("");
dispatcherServlet.init(servletConfig);
}
protected String[] generateDefaultLocations(Class<?> clazz) {
extractConfiguration(clazz);
return super.generateDefaultLocations(clazz);
}
protected String[] modifyLocations(Class<?> clazz, String... locations) {
extractConfiguration(clazz);
return super.modifyLocations(clazz, locations);
}
private void extractConfiguration(Class<?> clazz) {
configuration = AnnotationUtils.findAnnotation(clazz,
MockWebApplication.class);
if (configuration == null) {
throw new IllegalArgumentException("Test class " + clazz.getName()
+ " must be annotated @MockWebApplication.");
}
}
protected String getResourceSuffix() {
return "-context.xml";
}
}
And we will use the mockwebapplication class to hold our annotation configuration:
package com.sillycat.easyrestserver.core;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface MockWebApplication {
String webapp() default "src/main/webapp";
String name();
String[] locations() default "src/test/test-content.xml";
}
The test class will be like this:
package com.sillycat.easyrestserver.controller;
import java.io.IOException;
import javax.servlet.ServletException;
import org.codehaus.jackson.map.ObjectMapper;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.HandlerMapping;
import com.sillycat.easyrestserver.core.MockWebApplication;
import com.sillycat.easyrestserver.core.MockWebApplicationContextLoader;
import com.sillycat.easyrestserver.model.Company;
import com.sillycat.easyrestserver.model.Person;
/**
* mock the servlet and use servlet to test our controller
* servlet.service(mockRequest, mockResponse);
* can not mock the service or manager in controller
* @author karl
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = MockWebApplicationContextLoader.class)
@MockWebApplication(name = "easyrestserver", locations = "classpath:test-context.xml")
public class PersonControllerTest1 {
@Autowired
private DispatcherServlet servlet;
ObjectMapper mapper;
Person person;
MockHttpServletRequest mockRequest;
MockHttpServletResponse mockResponse;
@Before
public void setUp() throws ServletException, IOException {
MockitoAnnotations.initMocks(this);
mapper = new ObjectMapper();
person = new Person();
person.setCompany(new Company());
person.setId(1);
person.setPersonName("person1");
mockRequest = new MockHttpServletRequest();
mockRequest.setAttribute(HandlerMapping.INTROSPECT_TYPE_LEVEL_MAPPING,true);
mockResponse = new MockHttpServletResponse();
}
@Test
public void get() throws Exception {
mockRequest.setMethod("GET");
mockRequest.setRequestURI("/person/1");
mockRequest.setContentType(MediaType.APPLICATION_JSON_VALUE);
mockResponse = new MockHttpServletResponse();
servlet.service(mockRequest, mockResponse);
Person actualPerson = mapper.readValue(
mockResponse.getContentAsString(), Person.class);
Assert.assertEquals(actualPerson.getId(), person.getId());
}
@Test
public void add() throws Exception{
mockRequest.setContentType(MediaType.APPLICATION_JSON_VALUE);
mockRequest.setMethod("POST");
mockRequest.setRequestURI("/person");
String jsonPerson = mapper.writeValueAsString(person);
mockRequest.setContent(jsonPerson.getBytes());
servlet.service(mockRequest, mockResponse);
Assert.assertEquals(mockResponse.getStatus(), 200);
Person actualPerson = mapper.readValue(
mockResponse.getContentAsString(), Person.class);
Assert.assertEquals(actualPerson.getId(), person.getId());
}
}
The sample project named easyrestserver.
references:
spring 3 and rest
http://hi.baidu.com/luohuazju/blog/item/1fe358ea5da873c0d539c9b4.html
http://hi.baidu.com/luohuazju/blog/item/c380b67f9946421b28388ab7.html
http://hi.baidu.com/luohuazju/blog/item/3b68f609650a37dc3bc763c5.html
tcpdump on mac
http://support.apple.com/kb/HT3994
http://hi.baidu.com/luohuazju/blog/item/da079eb3de7109b2d9335aa5.html
mock test
http://www.iteye.com/topic/828513
http://stackoverflow.com/questions/9138555/spring-framework-test-restful-web-service-controller-offline-i-e-no-server-n
http://stackoverflow.com/questions/1401128/how-to-unit-test-a-spring-mvc-controller-using-pathvariable/2457902#2457902
http://ted-young.googlecode.com/svn/trunk/blog.spring-mvc-integration-testing/
https://github.com/springside/springside4/blob/master/examples/mini-service/src/test/java/org/springside/examples/miniservice/webservice/ws/AccountWebServiceTest.java
https://github.com/SpringSource/spring-test-mvc
http://elf8848.iteye.com/blog/875830
发表评论
-
RESTful JSON Mock Server
2015-03-19 11:58 811RESTful JSON Mock Server C ... -
Performance Tool(7)Improve Lua and Wrk
2015-01-17 06:37 1050Performance Tool(7)Improve Lua ... -
Performance Tool(6)Gatling Upgrade to 2.1.2 Version Or wrk
2015-01-10 01:15 992Performance Tool(6)Gatling Upg ... -
Performance Tool(5)Upgrade to 2.0.x
2014-08-27 03:34 1146Performance Tool(5)Upgrade to 2 ... -
Performance Tool(4)CSV File Data Feeder
2014-08-25 10:50 1054Performance Tool(4)CSV File Dat ... -
wrk with LuaJIT
2014-08-19 06:30 1358wrk with LuaJITHere is an exa ... -
Performance Tool(3)Gatling Upgrade and Cluster
2014-07-25 02:32 1352Performance Tool(3)Gatling Upgr ... -
WRK a HTTP Benchmarking Tool
2014-03-07 04:42 1164WRK a HTTP Benchmarking Tool1 ... -
Performance Tool(1)Gatling
2013-03-15 05:28 1315Performance Tool(1)Gatling 1. ... -
Jenkins Configuration(4)Improve Shell Script Debug/Info Message
2013-01-07 06:32 1351Jenkins Configuration(4)Improve ... -
Jenkins Configuration(3)Shell Script
2012-12-28 01:17 2708Jenkins Configuration(3)Shell S ... -
Eclipse Plugin(2)SOAP UI
2012-06-08 10:48 1366Eclipse Plugin(2)SOAP UI Plugi ... -
Spring3 and REST Integeration(VII)Controller JUnit Test and Mock/Spring Test MVC
2012-04-06 15:57 1925Spring3 and REST Integeration(V ... -
Spring3 and REST Integration(VI)Controller JUnit Test and Mock/Spring HandlerAda
2012-04-06 15:51 1837Spring3 and REST Integration(VI ... -
Spring3 and REST Integration(V)Controller JUnit Test and Mock/HandlerAdapter
2012-04-06 15:41 2853Spring3 and REST Integration(V) ... -
Jbehave(2)Some Improvement and POM changes
2012-03-28 23:11 1448Jbehave(2)Some Improvement and ... -
buildr(1)Introduce and Install
2011-12-23 16:37 2211buildr(1)Introduce and Install ... -
Jbehave(1) First Web Page Sample
2011-10-26 15:00 2226Jbehave(1) First Web Page Sampl ... -
WarcraftIII Problem on English Win7
2011-07-25 10:18 1966WarcraftIII Problem on English ... -
Web Performance Test Tool
2011-05-10 15:37 1485Web Performance Test Tool 1. F ...
相关推荐
3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................
3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................
内容概要:本文详细介绍了如何利用Simulink对BUCK电路进行PI闭环控制仿真。首先解释了BUCK电路的基本原理及其数学表达式,接着逐步指导如何在Simulink中构建仿真模型,包括选择合适的元件如电源、开关、电感、电容等,并设置了具体的参数。然后重点讲解了PI控制器的设计方法,展示了如何通过MATLAB代码实现PI控制算法,并讨论了不同参数对控制系统的影响。最后,通过观察和分析仿真结果的关键波形,探讨了如何优化PI控制器参数以获得更好的输出效果。 适合人群:从事电力电子设计的研究人员和技术爱好者,尤其是那些希望深入了解BUCK电路及其控制机制的人群。 使用场景及目标:适用于需要掌握BUCK电路工作原理以及PI闭环控制方法的学习者;旨在提高对电力电子系统的理解和优化能力。 其他说明:文中提供了详细的步骤和实例,有助于读者更好地理解和应用所学知识。此外,还提到了一些常见的挑战和解决方案,例如如何避免电压过冲、优化负载响应时间和减少输出电压纹波等问题。
MFC-Windows应用程序设计-第2章-Windows应用程序的类封装.pptx
MCS51单片机指令系统数据传送类指令.pptx
PLC电源模块维修重点技术实例.doc
内容概要:本文详细介绍了如何利用西门子S7-1200 PLC构建一个高精度的恒温水箱控制系统。首先讨论了硬件选择与配置,包括PT100温度传感器、模拟量模块的选择以及滤波时间的优化。接着深入探讨了PID控制算法的应用,包括参数整定技巧、移动平均滤波的应用以及PWM输出控制方法。此外,还涉及了人机界面的设计,强调了报警机制的优化和现场调试的经验分享。文中提供了多个实用的SCL代码片段,帮助读者更好地理解和实施具体的技术细节。 适合人群:从事工业自动化领域的工程师和技术人员,尤其是对PLC编程和温度控制感兴趣的初学者。 使用场景及目标:适用于需要精确温度控制的工业应用场景,如食品加工、生物制药等行业。目标是将温度波动控制在±0.5℃以内,确保生产过程的稳定性。 其他说明:文中不仅提供了详细的理论讲解,还结合了大量的实际案例和调试经验,有助于读者快速掌握相关技术和应对常见问题。
内容概要:本文详细介绍了利用COMSOL进行太赫兹波段石墨烯超表面吸波器的设计与仿真的全过程。首先,通过几何建模创建了基于矩形堆叠的石墨烯单元结构,并设置了合适的材料参数,特别是石墨烯的表面电导率采用Kubo公式表示。接着,针对边界条件进行了细致设定,如使用完美匹配层(PML)和Floquet周期边界条件,确保计算效率和准确性。然后,通过参数扫描和优化,研究了不同费米能级对吸收峰的影响,实现了吸收频段的动态调控。最后,通过后处理和动画制作,展示了吸收峰随费米能级变化的动态效果,并提供了具体的MATLAB和COMSOL代码示例。 适合人群:从事太赫兹器件设计、电磁仿真以及石墨烯材料应用的研究人员和技术人员。 使用场景及目标:适用于希望深入了解太赫兹波段吸波器设计原理及其动态调控特性的科研工作者。目标是通过实际操作和理论分析相结合,掌握石墨烯超表面吸波器的设计方法和优化技巧。 其他说明:文中提供的具体步骤和代码示例有助于快速上手COMSOL仿真工具,同时强调了常见问题的解决方法,如收敛问题和网格划分策略。
内容概要:本文详细介绍了两轮平衡车和扭扭车的完整设计方案,涵盖硬件和软件两个方面。硬件部分包括主控芯片(如STM32F103)、传感器(如MPU6050)的选择与布局,以及PCB设计要点,强调了电机驱动模块的布线规则和电磁干扰防护措施。软件部分则聚焦于核心算法,如PID控制和卡尔曼滤波,用于处理传感器数据并实现车辆的平衡和运动控制。此外,文章还讨论了烧写程序、调试文件和BOM清单等量产相关的内容,分享了许多实用经验和技巧。 适合人群:对两轮平衡车和扭扭车设计感兴趣的电子工程师、硬件开发者和嵌入式程序员。 使用场景及目标:帮助读者掌握从原理图设计到量产的全流程,包括硬件选型、PCB布局、程序编写、调试方法和批量生产的注意事项。目标是让读者能够独立完成一套完整的两轮平衡车或扭扭车项目。 其他说明:文中提供了大量实战经验和技术细节,如PID参数调优、PCB布局技巧、电机驱动优化等,有助于提高产品的稳定性和可靠性。
内容概要:文章详细介绍了汽车电子软件A/B分区方案,这是一种用于汽车电子系统软件管理的最佳实践。A/B分区通过将存储空间划分为两个独立分区,分别保存完整的软件镜像,实现软件的无感更新、提高系统可靠性和支持远程更新(OTA)。具体工作流程包括从当前分区启动、下载更新包、分区验证、切换准备、重启运行以及回滚与故障处理。其核心优势在于减少停机时间、增强可靠性和安全性、助力OTA更新及提升用户体验。然而,该方案也面临存储空间需求大、更新管理复杂和功耗性能优化等挑战。文章最后提出了优化存储空间、简化更新管理和优化功耗的具体措施。 适合人群:汽车电子工程师、汽车制造商技术人员、对汽车电子系统感兴趣的工程师和技术爱好者。 使用场景及目标:①理解A/B分区的工作机制及其在汽车电子系统中的应用;②掌握A/B分区在软件更新过程中的具体操作流程;③了解A/B分区带来的优势及其面临的挑战,为实际项目提供参考。 其他说明:A/B分区方案已在新能源汽车和新势力造车中广泛应用,未来将在智能汽车和自动驾驶技术中发挥更大作用。文章强调了长期主义的重要性,鼓励读者在技术发展中保持耐心和持续学习的态度。
内容概要:本文详细介绍了利用粒子群优化(Particle Swarm Optimization, PSO)算法,在光伏电池受到局部阴影遮挡的情况下实现最大功率点跟踪(Maximum Power Point Tracking, MPPT)的方法。文中首先解释了阴影条件下光伏电池输出特性的变化,即P-V曲线由单一峰值变为多峰形态,使得传统的扰动观测法难以找到全局最大功率点。接着阐述了PSO算法的基本原理及其在MPPT中的具体实现方式,包括粒子初始化、速度和位置更新规则以及如何处理电压突变引起的系统震荡等问题。此外还讨论了粒子数量的选择、参数动态调整策略、适应度函数改进等方面的内容,并通过实验验证了该方法的有效性和优越性。 适合人群:从事光伏发电系统研究与开发的技术人员,尤其是关注提高光伏系统在非理想环境下工作效率的研究者。 使用场景及目标:适用于存在局部阴影遮挡情况下的光伏电站或分布式光伏发电系统的优化设计,旨在提高此类条件下光伏系统的能量转化效率。 其他说明:文中不仅提供了详细的理论推导和技术细节,还有具体的代码片段用于辅助理解和实施。同时指出,在实际应用中可以根据不同的应用场景灵活调整相关参数配置,如粒子数目、惯性权重等,从而达到更好的性能表现。
office办公软件培训.pptx
2025免费微信小程序毕业设计成品,包括源码+数据库+往届论文资料,附带启动教程和安装包。 启动教程:https://www.bilibili.com/video/BV1BfB2YYEnS 讲解视频:https://www.bilibili.com/video/BV1BVKMeZEYr 技术栈:Uniapp+Vue.js+SpringBoot+MySQL。 开发工具:Idea+VSCode+微信开发者工具。
内容概要:本文详细介绍了如何使用Matlab进行平行泊车和垂直泊车的路径规划与仿真。首先解释了平行泊车的基本原理,即基于车辆运动学模型,通过控制转向角和速度来规划从初始位置到目标车位的平滑路径。接着展示了具体的Matlab代码实现,包括初始化参数设置、路径规划的循环迭代以及最终的路径绘图。对于垂直泊车,则强调了其独特的路径规划逻辑,分为接近车位和转向进入两个阶段,并给出了相应的代码示例。此外,还讨论了一些高级话题,如使用双圆弧+直线组合方案、五次多项式轨迹生成、PID控制器实现轨迹跟踪等方法来优化路径规划。同时提到了碰撞检测模块的实现方式及其重要性。 适合人群:对自动驾驶技术感兴趣的初学者或有一定编程基础的研发人员。 使用场景及目标:适用于希望深入了解自动驾驶泊车原理和技术细节的人群,特别是那些想要动手实践并掌握Matlab编程技巧的学习者。通过学习本文提供的代码示例,读者能够更好地理解平行泊车和垂直泊车的具体实现过程,从而为进一步研究提供坚实的基础。 其他说明:文中提到的所有代码均为简化版本,旨在帮助读者快速入门。实际应用中可能需要考虑更多因素,例如车辆的实际尺寸、环境感知模块的集成等。此外,作者还分享了许多实用的经验和技巧,如如何避免常见的错误、如何优化代码性能等。
内容概要:本文详细介绍了如何使用连续小波变换(CWT)、卷积神经网络(CNN)和支持向量机(SVM)进行滚动轴承故障诊断的方法。首先,通过对东南大学提供的轴承数据集进行预处理,将一维振动信号转换为时频图。然后,构建了一个CNN-SVM混合模型,其中CNN用于提取时频图的特征,SVM用于分类。文中还讨论了如何选择合适的小波基、尺度范围以及如何防止过拟合等问题。此外,作者提供了T-SNE可视化工具来评估模型性能,并分享了一些实用的避坑指南。 适合人群:从事机械设备故障诊断的研究人员和技术人员,尤其是那些对振动信号处理有一定了解的人。 使用场景及目标:适用于工业环境中对旋转机械设备的故障检测和预测。主要目标是提高故障诊断的准确性,减少误判率,确保设备的安全稳定运行。 其他说明:文中提到的所有代码均已在Matlab环境下验证通过,并附有详细的注释和解释。对于初学者来说,建议逐步跟随代码实现,理解每一步骤背后的原理。
内容概要:本文详细介绍了基于三菱F5U系列PLC的恒压测试设备开发过程,涵盖了ST语言编程和梯形图逻辑控制的综合应用。主要内容包括设备的整体功能概述,如递增调压和恒压保持两大功能;ST语言在数据处理方面的优势,如从触摸屏读取设置数据、处理压力传感器数据等;梯形图在逻辑控制方面的作用,如实现递增和恒压模式的切换;触摸屏程序设计,确保良好的人机交互体验;以及监控曲线和历史记录的实现方法。文中还特别强调了ST语言和梯形图混合编程的优势和注意事项。 适合人群:具备一定PLC编程基础的电气工程师和技术人员。 使用场景及目标:适用于工业自动化领域的恒压测试设备开发,旨在提高系统的灵活性和可靠性,帮助工程师更好地理解和应用ST语言和梯形图编程。 其他说明:文章提供了多个具体的代码示例和实用技巧,如数据类型转换、环形缓冲区设计、急停逻辑等,有助于读者在实际项目中借鉴和应用。
内容概要:本文由一位汽车电子工程师撰写,主要介绍了CAPL语言及其在CANoe中的调试功能。CAPL是一种专用于CANoe的类C编程语言,支持节点仿真、报文收发、自动化测试等功能。CAPL文件分为.can和.cin两种类型,程序结构包含头文件、全局变量、事件函数和自定义函数。CAPL基于事件驱动,常见事件包括系统事件、报文事件、时间事件等。CAPL支持多种数据类型和复杂数据结构。CANoe的CAPL Debug功能允许用户在仿真或测试过程中对CAPL代码进行调试,通过设置断点、单步执行等方式检查代码逻辑和变量值,确保代码满足需求。; 适合人群:具有汽车电子开发背景,尤其是从事汽车总线网络开发、测试和分析的工程师。; 使用场景及目标:①掌握CAPL语言的基本语法和特性,熟悉CAPL文件结构和编程规范;②学会使用CANoe中的CAPL Debug功能,能够设置断点、单步调试并查看变量变化,确保代码正确性和可靠性;③提升对汽车总线网络开发和测试的理解和实践能力。; 阅读建议:本文详细介绍了CAPL语言及其调试功能,建议读者在学习过程中结合实际项目进行实践,逐步掌握CAPL编程技巧和调试方法。同时,注意理解CAPL的事件驱动机制和数据类型,这对编写高效、可靠的CAPL代码至关重要。
内容概要:本文详细介绍了基于SSM(Spring + SpringMVC + MyBatis)框架的ERP生产管理系统的源码实现及其关键特性。首先探讨了系统的权限控制设计,采用Shiro实现按钮级别的权限管理,确保不同角色拥有不同的操作权限。接着分析了设备管理模块,展示了MyBatis动态SQL的应用以及设备状态更新的灵活性。工艺监控模块利用EasyUI DataGrid实现实时数据刷新,结合后端分页查询提高性能。质量监控模块则通过Spring事务注解实现异常数据处理的原子性。此外,系统采用了Shiro进行用户密码加密,增强了安全性。最后讨论了系统的布局设计和数据可视化的实现。 适合人群:具备一定Java开发经验的研发人员,特别是对SSM框架有初步了解并希望深入了解其实战应用的技术人员。 使用场景及目标:适用于需要构建或改进企业内部生产管理系统的开发团队。主要目标是通过研究现有系统的实现细节,掌握SSM框架的最佳实践,提升系统的稳定性和功能性。 其他说明:文中提到的许多技术细节如权限控制、事务管理和数据可视化等,不仅有助于理解SSM框架的工作原理,还能为实际项目提供宝贵的参考。
内容概要:本文继续深入介绍 AUTOSAR BSW 层的关键模块,主要包括诊断模块、硬件I/O抽象模块和操作系统OS。诊断模块包含诊断通信管理器(DCM)、诊断事件管理器(DEM)和功能禁止管理器(FIM),它们分别负责通信协议实现、事件管理和功能控制,确保ECU在不同情况下的正确响应。硬件I/O抽象模块通过将硬件接口抽象化,使上层软件无需关心底层硬件细节,提高了系统的可移植性和维护性。操作系统OS分为SC1到SC4四个等级,从基本任务调度到高级别的内存和时间保护,适应不同功能安全级别的需求,保障了多任务环境下的数据一致性和实时性能。 适合人群:对汽车电子控制系统有一定了解的研发人员,尤其是从事AUTOSAR相关工作的工程师和技术人员。 使用场景及目标:①理解AUTOSAR架构下BSW层各模块的具体功能和相互关系;②掌握诊断模块在汽车ECU中的应用及其重要性;③学习硬件I/O抽象模块的设计思路和实现方法;④了解AUTOSAR OS的不同分类及其在不同安全等级产品中的应用。 阅读建议:由于涉及到较多的专业术语和技术细节,建议读者先熟悉AUTOSAR的基础概念,再逐步深入理解各模块的工作原理和应用场景。同时,结合实际项目经验进行对比学习,有助于更好地掌握本文内容。
多语言笔记系列:操作数据库-C#程序