Briefly
1. Spring and MyBatis are integrated into unit testing to confirm that the integration is correct.
2. Integration of the SPRINGMVC.
1.1, import the package you want. The required package is shown in Figure 1:
Figure 1
1.2, generate model, mapping, DAO interface
Note: The Mapper.xml file is the same as the DAO interface name
1.3, put in the project
Write Service interface and implementation class, call DAO for database operation.
Write configuration file Spring-mybatis.xml.
Note: namespace is the DAO file path, mapper the corresponding DAO file.
1.4, write test class
Package com.shop.test;
Import Javax.annotation.Resource;
Import Org.apache.log4j.Logger;
Import Org.junit.Test;
Import Org.junit.runner.RunWith;
Import org.springframework.test.context.ContextConfiguration;
Import Org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
Import Com.alibaba.fastjson.JSON;
Import Com.shop.model.User;
Import Com.shop.service.IUserService;
The @RunWith (springjunit4classrunner.class) //representation inherits the Springjunit4classrunner class
@ContextConfiguration ( Locations = {"Classpath:conf/spring-mybatis.xml"}) public
class Tests {
private static Logger Logger = Logger.getlogger (tests.class);
@Resource
private Iuserservice userservice = null;
@Test public
void Test1 () {
User user = Userservice.getuserbyid (1L);
System.out.println ("Syso:" +json.tojsonstring (user));
Logger.debug ("log4j:" +json.tojsonstring (user));
}
The above test passes, carries on the SPRINGMVC conformity, otherwise, carries on the necessary debugging.
2.1, write Spring-mvc.xml file
2.2, modify Web.xml. Read configuration file, Spring-mybaits, SPRING-MVC, add code Filter, monitor, SPRINGMVC intercept;
2.3, write Usercontroller.java file.
Complete
SOURCE Download Address: http://download.csdn.net/download/roguestudys/9222987
database table structure SQL download address: http://download.csdn.net/detail/roguestudys/9223003
Record your own study. Devon