教你搭建SpringMVC框架( 附源码)
一、项目目录结构
二、SpringMVC需要使用的jar包
- commons-logging-1.2.jar
- junit-4.10.jar
- log4j-api-2.0.2.jar
- log4j-core-2.0.2.jar
- log4j-web-2.0.2.jar
- spring-beans-3.2.4.RELEASE.jar
- spring-context-3.2.4.RELEASE.jar
- spring-core-4.0.5.RELEASE.jar
- spring-expression-3.2.4.RELEASE.jar
- spring-web-4.0.5.RELEASE.jar
- spring-webmvc-3.2.9.RELEASE.jar
三、在Web.xml配置SpringMVC控制器
在不设置contextConfigLocation参数的情况下,SpringMVC框架默认在WEB-INF路径下查找文件名为XXX-servlet.xml(XXX是web.xml中配置的SpringMVC框架控制器的名称)。可以通过设置contextConfigLocation参数,自定义SpringMVC-servlet.xml的路径。
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>SpringMVC</display-name> <!-- 添加Spring控制器及映射规则 -->
<servlet>
<servlet-name>SpringMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 不设置contextConfigLocation,SpringMVC 会在WEB-INF文件夹下查找<servlet-name/>-servlet.xml,设置
contextConfigLocation,可自定义SpringMVC-servlet.xml的位置 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/SpringMVC-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SpringMVC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> <!-- 首页文件列表 -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
四、配置SpringMVC-servlet.xml
在路径/SpringMVCDemo/src/comm/config/配置SpringMVC-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans" 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-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
"> <!-- 自动扫描的包名 -->
<context:component-scan base-package="com.candy.dao"></context:component-scan>
<context:component-scan base-package="com.candy.service"></context:component-scan>
<context:component-scan base-package="com.candy.web"></context:component-scan> <!-- 添加注解驱动 -->
<mvc:annotation-driven/> <!-- 模型视图名称解析 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value></value>
</property>
</bean> <!-- 对静态资源文件的访问 方案 -->
<mvc:default-servlet-handler />
</beans>
五、编写Controller
BaseController:
package com.candy.web; import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List; import javax.servlet.http.HttpServletRequest; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.propertyeditors.CustomCollectionEditor;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder; @Controller
public class BaseController { protected final Logger log = LogManager.getLogger(); /**
* 处理页面参数序列化后数据类型的问题
*
* @author Candy
* @date 2014-11-3
* @version V1.0
* @param binder
*/
@InitBinder
public void initBinder(WebDataBinder binder) {
log.debug("initBinder");
SimpleDateFormat dataSdf = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat dataTimesdf = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
binder.registerCustomEditor(Date.class, new CustomDateEditor(dataSdf,
true));
binder.registerCustomEditor(Timestamp.class, new CustomDateEditor(
dataTimesdf, true));
binder.registerCustomEditor(List.class, new CustomCollectionEditor(
List.class, true));
} /**
* 获取客户端真实IP地址
*
* @author Candy
* @date 2014-11-3
* @version V1.0
* @param request
* @return
*/
public String getIpAddr(HttpServletRequest request) {
log.debug("getIpAddr");
if (request == null) {
return null;
}
String ip = request.getRemoteAddr(); if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("x-forwarded-for");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
return ip;
}
}
TestController:
/**
* @projectName SpringMVC
* @package com.candy.web.IndexController.java
* @Copyright Copyright(c) 2014 Candy工会
* @author Candy
* @date 2014-11-3
* @version V1.0
*/
package com.candy.web.test; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView; import com.candy.service.TestService;
import com.candy.web.BaseController; /**
* 测试Controller
*
* @author Candy
* @date 2014-11-3
* @version V1.0
*/
@Controller
public class TestController extends BaseController { @Autowired
private TestService testService;
/**
* 测试跳转
*
* @author Candy
* @date 2014-11-3
* @return
*/
@RequestMapping("/transfer")
public ModelAndView testTransfer() {
log.debug("控制器查找到请求的路径!");
String viewName =testService.testTransfer();
return new ModelAndView(viewName);
} }
六、编写测试页面
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html>
<html lang="zh"> <head>
<base href="<%=basePath%>"> <title>SpringMVCDemo-首页</title> <meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/css/styles.css"> </head> <body>
<div class="container">
<div class="header"></div>
<div class="content">
<a href="${pageContext.request.contextPath}/transfer">发起请求</a>,后台响应,跳转到指定页面!
</div>
<div class="footer"></div>
</div>
</body>
</html>
在路径/SpringMVCDemo/WebContent/WEB-INF/jsp/下编写success.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html>
<html lang="zh"> <head>
<base href="<%=basePath%>"> <title>SpringMVCDemo-成功页面</title> <meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/css/styles.css"> </head> <body>
<div class="container">
<div class="header"></div>
<div class="content">
<h3>跳转成功!</h3>
<p>当你看到这些文字时,说明SpringMVC配置成功了!</p>
</div>
<div class="footer"></div>
</div>
</body>
</html>
七、访问测试
在浏览器中访问http://localhost:8080/SpringMVCDemo/,根据Web.xml中的配置默认显示index.jsp
<!-- 首页文件列表 -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
点击index.jsp中的“发起请求”链接,根据index.jsp代码,此时,浏览器会向服务器发出请求访问路径为“/SpringMVCDemo/transfer"的资源。
<a href="${pageContext.request.contextPath}/transfer">发起请求</a>,后台响应,跳转到指定页面!
SpringMVC框架通过Web.xml中定义的控制器及映射规则,读取SpringMVC-servlet中的配置。
<!-- 添加Spring3控制器及映射规则 -->
<servlet>
<servlet-name>SpringMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 不设置contextConfigLocation,SpringMVC 会在WEB-INF文件夹下查找<servlet-name/>-servlet.xml,设置
contextConfigLocation,可自定义SpringMVC-servlet.xml的位置 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/SpringMVC-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SpringMVC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
SpringMVC框架扫描各个包,查找注解为“@Controller”的类,并扫描注解为"@RequestMapping("/transfer")"对应的方法。
<!-- 自动扫描的包名 -->
<context:component-scan base-package="com.candy.dao"></context:component-scan>
<context:component-scan base-package="com.candy.service"></context:component-scan>
<context:component-scan base-package="com.candy.web"></context:component-scan> <!-- 添加注解驱动 -->
<mvc:annotation-driven/>
此时SpringMVC框架已经定位到了com.candy.web.test.TestController.testTransfer()方法。
在TestController的testTransfer()方法中,SpringMVC框架根据注解和自动扫描配置,查找类名为“TestService”,类注解为“@Component”的类,完成自动注入(Autowired)。
此时,TestController的testTransfer()方法返回一个ModelAndView的对象。SpringMVC框架根据SpringMVC-servlet.xml中的配置,在路径/WEB-INF-jsp中查找success.jsp文件,并返回给客户端。
<!-- 模型视图名称解析 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value></value>
</property>
</bean>
此时,你就可以看到成功访问的信息了。
注:以上博文中,简单的贴了下配置,并在第七步“访问测试”中,按照自己的理解,通过简单易懂的文字,描述了框架的执行顺序。
其实在项目启动时,SpringMVC框架就完成了以下工作:
- 读取web.xml,获取到contextConfigLocation中配置的SpringMVC-servlet.xml路径。
- 读取SpringMVC-servlet.xml,扫描配置的各个包。
- 根据注解,加载所有的Controller、Service等组件,并完成自动注入。
- 根据注解,计算可能多的访问路径。
源码下载地址:http://pan.baidu.com/s/1c0gZUXa
以下是搭建环境时,遇到的各种问题笔记。
- 搭建JUnit环境时,测试Controller时,提示“Caused by: javax.validation.ValidationException: Unable to instantiate Configuration.”
2014-11-3 18:06:46 org.springframework.context.support.FileSystemXmlApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@f81843: startup date [Mon Nov 03 18:06:46 CST 2014]; root of context hierarchy
2014-11-3 18:06:46 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from file [D:\Workspaces\SpringMVCDemo\WebContent\WEB-INF\SpringMVC-servlet.xml]
2014-11-3 18:06:46 org.springframework.context.annotation.ClassPathBeanDefinitionScanner registerDefaultFilters
信息: JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
2014-11-3 18:06:46 org.springframework.context.annotation.ClassPathBeanDefinitionScanner registerDefaultFilters
信息: JSR-330 'javax.inject.Named' annotation found and supported for component scanning
2014-11-3 18:06:46 org.springframework.context.annotation.ClassPathBeanDefinitionScanner registerDefaultFilters
信息: JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
2014-11-3 18:06:46 org.springframework.context.annotation.ClassPathBeanDefinitionScanner registerDefaultFilters
信息: JSR-330 'javax.inject.Named' annotation found and supported for component scanning
2014-11-3 18:06:46 org.springframework.context.annotation.ClassPathBeanDefinitionScanner registerDefaultFilters
信息: JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
2014-11-3 18:06:46 org.springframework.context.annotation.ClassPathBeanDefinitionScanner registerDefaultFilters
信息: JSR-330 'javax.inject.Named' annotation found and supported for component scanning
2014-11-3 18:06:46 org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor <init>
信息: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2014-11-3 18:06:46 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@dda25b: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,baseController,testController,mvcContentNegotiationManager,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,viewResolver,org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler#0,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
2014-11-3 18:06:46 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
信息: Mapped "{[/transfer],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.candy.web.test.TestController.referLogin()
2014-11-3 18:06:46 org.hibernate.validator.util.Version <clinit>
信息: Hibernate Validator bean-validator-3.0-JBoss-4.0.2
2014-11-3 18:06:46 org.springframework.beans.factory.support.DefaultListableBeanFactory destroySingletons
信息: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@dda25b: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,baseController,testController,mvcContentNegotiationManager,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,viewResolver,org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler#0,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
java.lang.ExceptionInInitializerError
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0': Invocation of init method failed; nested exception is javax.validation.ValidationException: Unable to instantiate Configuration.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84)
at com.candy.web.BaseController.<clinit>(BaseController.java:25)
Caused by: javax.validation.ValidationException: Unable to instantiate Configuration.
at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:272)
at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet(LocalValidatorFactoryBean.java:188)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479)
... 12 more
Caused by: java.lang.NullPointerException
at java.util.ResourceBundle.getBundle(ResourceBundle.java:950)
at org.hibernate.validator.engine.ResourceBundleMessageInterpolator.loadBundle(ResourceBundleMessageInterpolator.java:202)
at org.hibernate.validator.engine.ResourceBundleMessageInterpolator.getFileBasedResourceBundle(ResourceBundleMessageInterpolator.java:182)
at org.hibernate.validator.engine.ResourceBundleMessageInterpolator.<init>(ResourceBundleMessageInterpolator.java:81)
at org.hibernate.validator.engine.ResourceBundleMessageInterpolator.<init>(ResourceBundleMessageInterpolator.java:73)
at org.hibernate.validator.engine.ConfigurationImpl.<init>(ConfigurationImpl.java:57)
at org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:43)
at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:269)
... 15 more
Exception in thread "main"解决方案:删除JavaEE6中自带的jar包:bean-validator.jar
- 如何删除JavaEE6中自带的jar包?
在MyEclipse的菜单:Window-->Properties-->MyEclipse-->Java Enterprise Project-->Library Sets中,选择到Java EE6.0选项卡(默认选中),然后选择bean-validator.jar,点击右侧的“Remove”按钮,然后点“OK”按钮即可。 - Log4j2输出到控制台的log是乱码。
解决方案:在使用的PatternLayout中加入属性:charset="GBK"即可。 - ……
教你搭建SpringMVC框架( 附源码)的更多相关文章
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(2)-easyui构建前端页面框架[附源码]
原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(2)-easyui构建前端页面框架[附源码] 开始,我们有了一系列的解决方案,我们将动手搭建新系统吧. 用 ...
- javaweb异常提示信息统一处理(使用springmvc,附源码)
一.前言 后台出现异常如何友好而又高效地回显到前端呢?直接将一堆的错误信息抛给用户界面,显然不合适. 先不考虑代码实现,我们希望是这样的: (1)如果是页面跳转的请求,出现异常了,我们希望跳转到一个异 ...
- 教你搭建SpringMVC框架( 更新中、附源码)
一.项目目录结构 二.SpringMVC需要使用的jar包 commons-logging-1.2.jar junit-4.10.jar log4j-api-2.0.2.jar log4j-core- ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(2)-easyui构建前端页面框架[附源码]
系列目录 前言 为了符合后面更新后的重构系统,本文于2016-10-31日修正一些截图,文字 我们有了一系列的解决方案,我们将动手搭建新系统吧. 后台系统没有多大的UI视觉,这次我们采用的是标准的左右 ...
- Ext.NET 4.1 系统框架的搭建(后台) 附源码
Ext.NET 4.1 系统框架的搭建(后台) 附源码 代码运行环境:.net 4.5 VS2013 (代码可直接编译运行) 预览图: 分析图: 上面系统的构建包括三块区域:North.West和C ...
- MVC系列——MVC源码学习:打造自己的MVC框架(二:附源码)
前言:上篇介绍了下 MVC5 的核心原理,整篇文章比较偏理论,所以相对比较枯燥.今天就来根据上篇的理论一步一步进行实践,通过自己写的一个简易MVC框架逐步理解,相信通过这一篇的实践,你会对MVC有一个 ...
- Mybatis+SpringMVC实现分页查询(附源码)
Maven+Mybatis+Spring+SpringMVC实现分页查询(附源码) 一.项目搭建 关于项目搭建,小宝鸽以前写过一篇Spirng+SpringMVC+Maven+Mybatis+MySQ ...
- 基于Python接口自动化测试框架+数据与代码分离(进阶篇)附源码
引言 在上一篇<基于Python接口自动化测试框架(初级篇)附源码>讲过了接口自动化测试框架的搭建,最核心的模块功能就是测试数据库初始化,再来看看之前的框架结构: 可以看出testcase ...
- 开源方案搭建可离线的精美矢量切片地图服务-8.mapbox 之sprite大图图标文件生成(附源码)
项目成果展示(所有项目文件都在阿里云的共享云虚拟主机上,访问地图可以会有点慢,请多多包涵). 01:中国地图:http://test.sharegis.cn/mapbox/html/3china.ht ...
随机推荐
- UVA-11280 Flying to Fredericton
题意 给定一些国家,和两个国家间的花费,现在有一些询问,询问每次最多转k次飞机,最小花费 分析 最短路的裸题,跑spfa或者dijsktra什么的都行 多开一维来记录转k次飞机时的最短路是什么(拆点? ...
- Redis安装文档
1.前置条件 前置条件:linux已经可以上网,参考:https://www.cnblogs.com/ZenoLiang/p/10201875.html 2.安装redis 2.1依赖包检查 1. ...
- Tensorflow训练结果测试
代码参考(https://blog.csdn.net/disiwei1012/article/details/79928679) import osimport sysimport randomimp ...
- CMake 自定义编译选项
自定义编译选项 CMake 允许为项目增加编译选项,从而可以根据用户的环境和需求选择最合适的编译方案. 例如,可以将 MathFunctions 库设为一个可选库,如果该选项为 ON ,就使用该库定义 ...
- Debian上SCST的设置
一)创建SCST,无infiniband支持 1:载入最小化支持 #aptitude install build-essentials linux-headers checkinstall #wget ...
- 跨平台的图形软件Dia
一款非常不错的软件Dia,软件很小,免费.好用.跨平台(linux.windows.mac).可导出多种格式图片,除了流程图.UML建模图,还可以绘制其他很多图. ubuntu下可以直接通过命令行su ...
- 在slam_gmapping中使用Log数据创建地图
本文介绍使用机器人记录的tf变换和激光扫描数据来建立2D地图.并在ROS的图形化模拟环境rviz中通过重新回放记录的数据作为机器人真实传感器采集的输入,来观测地图动态创建过程. 1.ROS gmapp ...
- Tarjan算法求出强连通分量(包含若干个节点)
[功能] Tarjan算法的用途之一是,求一个有向图G=(V,E)里极大强连通分量.强连通分量是指有向图G里顶点间能互相到达的子图.而如果一个强连通分量已经没有被其它强通分量完全包含的话,那么这个强连 ...
- 使用Monkey对APP进行随机测试
Monkey测试简介 Monkey测试是Android平台自动化测试的一种手段,通过Monkey程序模拟用户触摸屏幕.滑动Trackball.按键等操作来对设备上的程序进行压力测试,检测程序多久的时间 ...
- datagrid 自定义 pager
$(document).ready(function(){ var p = $('.easyui-datagrid').datagrid('getPager'); $(p).pagination({ ...