SPRING+MYBATIS+SPRINGMVC Project Setup

Source: Internet
Author: User
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

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.