return value requires annotation @responsebody to upload the data back to the JSP interface----js-----Bodyreturn JSON data back to the JSP interface using void return value Finally, it is a string type, but it is similar to the return value of type void.using string as the return value requires annotation @responsebody to support JSON data back to the JSP interface/** String return value type instead of other type*/@Controller Public classHandleajax {@RequestMapping ("/ajax.do") Public void
1. Introducing the JAR file2. Add Spring MVC Interceptor Configuration to the Springmvc-config.xml filePrinciple: The target filters all spring MVC requests, judging that the request parameters contain the callback parameter, and the response is returned in JSONP format.Note: If there is a better way, please let us kno
The springboot comes with a test module.Annotations require:@SpringApplicationConfiguration (classes = computeserviceapplication. Class)This allows the environment context to be introduced.The complete notes are as follows:@RunWith (Springjunit4classrunner. Class= computeserviceapplication. class ) @WebAppConfiguration@BeforeInitializing an MOCKMVC instance Public void throws Exception { = mockmvcbuilders.webappcontextsetup (WAC). build ();
The following packages are used:Reference aopalliance-1.0.jar
Commons-collections.jar
Commons-dbcp.jar
Commons-logging-1.1.1.jar
Commons-pool.jar
Junit-4.4.jar
Jstl. jar
Log4j-1.2.15.jar
Mysql-connector-java-5.1.6-bin.jar
Spring-aop-2.5.6.jar
Spring-beans-2.5.6.jar
Spring-context-2.5.6.jar
Maven dependencies:
MAVEN will then download the corresponding package.
Configuration one: Use Mybytis-config: This file can configure the alias of the class under the model package, or you can configure the mapper file for the mapped SQL statement:
Great wisdom as shown in the figure
Mybatis-config.xml file
The file is then introduced into the spring configuration file: Where Jdbcdatasource is the data source, the data source can be in a
The general test cases in SPRINGMVC are test service tiers, and today I'll show you how to test the controller layer code directly using SPRINGMVC mock.
1. What is a mock test?A mock test is a
Introduction
Unit Testing of the controller layer can improve the reliability of the application, although this makes the development of the time has increased, there will be lost, here I think to get more than lost. The unit test method after the
sping MVC3.2 version has changed, and unit testing is simpler and more efficient as the functionality improves.
Here is an example of version 4.1 documenting the unit
Brief introduction
The unit test of the controller layer can improve the reliability of the application, although this makes the development of the time has increased, there will be lost, here I think to get more than lost.
The unit test method after the Sping MVC3.2 version has changed, and unit testing is much simpler and more efficient as the functionality improves.
The unit
initial request thread being processed is a servlet or filter in an asynchronous schedule.
Then take a look at how callable handles asynchronous operations:
Controller returns a callable instance;
Spring MVC begins to process asynchronously and commits a callable instance to taskexecutor processing in a separate thread;
Dispatcherservlet and all filter exits the request thread but res
Next to my previous article about restassured testing a restful Web service, restassured also has a feature to test your spring MVC Controllers with the RESTASSUREDMOCKMVC unit, This MOCKMVC is based on spring MOCKMVC, which is designed to make it easier for us to use.Getting Ready ExampleHere's the controller we're go
due to aNewJavaclassFile version that isn ' t supported Yet:file [D:\workspace\stockmgt_maven_project\target\classes\com\liaoze\stockmgt\ Service\impl\userserviceimpl.class]; Nested exception is Java.lang.IllegalArgumentExceptionat Org.springframework.core.type.classreading.simplemetadatareader.) at Org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader ( Simplemetadatareaderfactory.java:80) at Org.springframework.core.type.classreading.CachingMetadataReaderFac
Demonstrates directly in code how to unit test in a Spring MVC project:Package Net.chinaedu.projects.dubhe;import Java.util.list;import Net.chinaedu.projects.dubhe.publisher.ipublisherservice;import Net.chinaedu.projects.venus.domain.Publisher; Import Org.junit.test;import Org.junit.runner.runwith;import Org.springframework.beans.factory.annotation.autowired;impo
@RunWith (Springjunit4classrunner.class)
@ContextConfiguration (locations = {"/config/spring3/ Applicationcontext.xml "})//Start Spring container public
class Testisrmvendorservice {
//inject bean in spring container
@ autowired
private Isrmvendorservice srmvendorservice;
@Test public
void Testhasmatchuser () throws Exception {
list
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.