Maven (3): New Java Webproject__java

Source: Internet
Author: User
1. The whole catalogue after completion

2. New MAVEN Project

Right-click New-> Other Project-> enter search Maven project-> Check create a simple project-> Next-> fill out the group ID and artifact ID. Select War Package->finish


3. Modify dynamic Web module to 3.0

Project Right Key properties-> Search Project Facets-> modify Dynamic Web Module to 3.0

Direct Click Modification cannot be saved, modified. <installed facet= "Jst.web" version= "in the Org.eclipse.wst.common.project.facet.core.xml file under Settings 2.5 "/> Modified version is 3.0
4. Modify the output directory and Export folders and order (1) Modify the output directory

MyEclipse Project Project Right key Bulid path-> Configure Bulid path The following diagram modifies the output directory

(2) Modify the Export folder order

5. Check the unified JDK version

The JDK versions in the following three locations need to be unified and consistent.

6.sping+mybatis Configuration (1) After the completion of the basic catalogue

(2) Pom file

Pom.xml provides the jar packages required for the project.

<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > < Modelversion>4.0.0</modelversion> <groupId>com.now</groupId> <artifactid>maventest </artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <  
      Properties> <!--spring version number--> <spring.version>3.2.8.RELEASE</spring.version> <!--log4j log file Management Pack version--> <slf4j.version>1.6.6</slf4j.version> <log4j.version>1.2.1 7</log4j.version> <!--junit version number--> <junit.version>4.10</junit.version> &L t;! --MyBatis version number--> <mybatis.version>3.2.1</mybatis.version> </properties> <depende ncies> <!--add Spring dependency--> &LT;dependency> <groupId>org.springframework</groupId> <artifactid>spring-core& lt;/artifactid> <version>${spring.version}</version> </dependency> <de Pendency> <groupId>org.springframework</groupId> <artifactid>spring-webmvc&lt ;/artifactid> <version>${spring.version}</version> </dependency> <depe Ndency> <groupId>org.springframework</groupId> <artifactId>spring-context< /artifactid> <version>${spring.version}</version> </dependency> <depen Dency> <groupId>org.springframework</groupId> <artifactid>spring-context-supp ort</artifactid> <version>${spring.version}</version> </dependency> &L  
     T;dependency>     <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId>  
          <version>${spring.version}</version> </dependency> <dependency>  
          <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>${spring.version}</version> </dependency> <dependency> & Lt;groupid>org.springframework</groupid> <artifactId>spring-tx</artifactId> & lt;version>${spring.version}</version> </dependency> <dependency> <gro Upid>org.springframework</groupid> <artifactId>spring-jdbc</artifactId> <v ersion>${spring.version}</version> </dependency> <dependency> <groupid >org.springframework&Lt;/groupid> <artifactId>spring-web</artifactId> &LT;VERSION&GT;${SPRING.VERSION}&L T;/version> </dependency> <!--unit test dependencies--> <dependency> <groupi D>junit</groupid> <artifactId>junit</artifactId> <version>${junit.versi On}</version> <scope>test</scope> </dependency> <!--log file management package  
      ; <!--log start--> <dependency> <groupId>log4j</groupId> <artif 

      Actid>log4j</artifactid> <version>${log4j.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactid>slf4j-api&lt ;/artifactid> <version>${slf4j.version}</version> </dependency> <depen  
  Dency>        <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> </dependency> <!--log End--> <  
          !--Spring Unit Test dependencies--> <dependency> <groupId>org.springframework</groupId>  
          <artifactId>spring-test</artifactId> <version>${spring.version}</version>   
          <scope>test</scope> </dependency> <!--mybatis dependent--> <dependency>  
          <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId>  
      <version>${mybatis.version}</version> </dependency> <!--mybatis/spring package--> <dependency> <groupId>org.mybatis</groupId> &LT;ARTIFACTID&GT;MYBATIS-SPR  Ing</artifactid>
          <version>1.2.0</version> </dependency> <!--mysql driver package--> <d Ependency> <groupId>mysql</groupId> <artifactid>mysql-connector-java</arti Factid> <version>5.1.29</version> </dependency> <!--JAVAEE-API Package Note and The JDK version used for the project corresponds to--> <dependency> <groupId>javax</groupId> <artifactId>javaee-api<  

/artifactid> <version>6.0</version> <scope>provided</scope> </dependency> <!--JAVAEE-WEB-API Package note and the JDK version used for the project corresponds--> <dependency> <groupId>javax</groupId> ;artifactid>javaee-web-api</artifactid> <version>6.0</version> <scope>provided</   scope> </dependency> </dependencies> </project>
(3) Java file-src/main/java directory

User.java

Package com.now.domain;
/**
 * User Mapping class
 * * *
/public class User {
    private Integer ID;
    Private String username;
    private String password;
    private String Email;
    Omit Getter/setter
}
Userdao.java
Package Com.now.dao;
Import Com.now.domain.User;
/**
 * Feature summary: User's DAO Class (DAO interface class, used to correspond to mapper file)/public
interface Userdao {

    /**
     * @param userId
     * @return
     *
    /Public User Selectuserbyid (Integer userId);

}
Userservice.java
Package com.now.service;
Import Com.now.domain.User;
/**
 * Function Summary: UserService interface class * * Public
interface UserService {

    User Selectuserbyid (Integer userId);  
}
Userserviceimpl.java
Package com.now.service;
Import org.springframework.beans.factory.annotation.Autowired;
Import Org.springframework.stereotype.Service;
Import Com.now.dao.UserDao;
Import Com.now.domain.User;

@Service public
class Userserviceimpl implements userservice{  
    @Autowired  
    private Userdao Userdao;  

    Public User Selectuserbyid (Integer userId) {return  
        Userdao.selectuserbyid (userId);     
    }  
}
Mapper File

Usermapper.xml

<?xml version= "1.0" encoding= "UTF-8"?> <!    
DOCTYPE Mapper Public "-//mybatis.org//dtd mapper 3.0//en"    
"HTTP://MYBATIS.ORG/DTD/MYBATIS-3-MAPPER.DTD" >  
<mapper namespace= "Com.now.dao.UserDao" >  
  <!--set the field one by one corresponding to the table in the domain class and the database. Note the field names in the database field and domain class must be consistent-->  
   <resultmap id= "Baseresultmap" type= "Com.now.domain.User" >  
       <id column= "id" property= "id" jdbctype= "INTEGER"/> <result column= "username" property= "username"  
       Char "/>  
       <result column=" password property= "password" jdbctype= "char"/> <result  
       "Email" property= "Email" jdbctype= "CHAR"/>  
   </resultMap>  
   <!--query single record-->  
   <select id= " Selectuserbyid "parametertype=" int "resultmap=" Baseresultmap ">  
       SELECT * from user WHERE id = #{userid}  
   </select>  
</mapper>
(4) Resource allocation-src/main/resources

mybatis configuration file (mybatis-config.xml)

<?xml version= "1.0" encoding= "UTF-8"?> <!    
DOCTYPE configuration Public "-//mybatis.org//dtd Config 3.0//en"    
"HTTP://MYBATIS.ORG/DTD/MYBATIS-3-CONFIG.DTD" >    
<configuration>      
</configuration>
Data Source Configuration jdbc.properties
Jdbc_driverclassname=com.mysql.jdbc.driver
jdbc_url=jdbc\:mysql\://127.0.0.1\:3306/address?useunicode\= True&characterencoding\=utf-8
jdbc_username=root
jdbc_password=abc123
Spring Configuration Application.xml
<?xml version= "1.0" encoding= "UTF-8"?> <beans "xmlns=" xmlns:
    Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:context= "Http://www.springframework.org/schema/context" xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xsi:schemalocation= "http://www.springframework.org /schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.spring FRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop-3.0.xsd HTTP://WWW.S

     Pringframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd "> <!--introduce JDBC profile--> <bean id= "Propertyconfigurer class=" Org.springframework.beans.factory.config.Pro Pertyplaceholderconfigurer "> <property name=" Locations "> <list> <valu E>classpath:properties/*.propertieS</value> <!--If you have multiple matches 

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.