本来没得什么问题 但是一到maven问题就多了,IDE都要出问题 各种bug不断啊
1.首先建立一个maven webapp项目:此处省略好多字
目录结构:
<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>
<parent>
<artifactId> qunar-supom-generic</ artifactId>
<groupId> qunar.common</groupId >
<version> 1.3.0</ version>
</parent >
<groupId >com.qunar.examing </groupId>
<artifactId >examing-Thrid</artifactId >
<version >0.0.1-SNAPSHOT </version>
<packaging >war </packaging>
<name >examing-second</ name>
<url >http://tc.corp.quanr.com </url>
<properties >
<project.build.sourceEncoding> UTF-8</ project.build.sourceEncoding>
<bds.bds_mode> nexus</ bds.bds_mode>
</properties >
<dependencyManagement >
<dependencies>
<dependency>
<groupId> com.google.guava</groupId >
<artifactId> guava</artifactId >
<version> 17.0</ version>
</dependency>
</dependencies>
</dependencyManagement >
<dependencies >
<!-- servlet api -->
<dependency>
<groupId> javax.servlet</groupId >
<artifactId> servlet-api</artifactId>
<scope> provided</ scope>
</dependency>
<!-- velocity -->
<dependency>
<groupId> org.apache.velocity</groupId >
<artifactId> velocity</ artifactId>
</dependency>
<dependency>
<groupId> velocity-tools</groupId >
<artifactId> velocity-tools</artifactId >
<version> 1.4</ version>
<scope> runtime</ scope>
</dependency>
<!-- spring module -->
<dependency>
<groupId> org.springframework</groupId >
<artifactId> spring-webmvc </artifactId>
</dependency>
<dependency>
<groupId> org.springframework</groupId >
<artifactId> spring-tx</artifactId >
</dependency>
<dependency>
<groupId> org.springframework</groupId >
<artifactId> spring-jdbc</artifactId >
</dependency>
<dependency>
<groupId> org.springframework</groupId >
<artifactId> spring-context-support</artifactId >
</dependency>
<!-- mybatis module -->
<dependency>
<groupId> org.mybatis</groupId >
<artifactId> mybatis</artifactId >
</dependency>
<dependency>
<groupId> org.mybatis</groupId >
<artifactId> mybatis-spring </artifactId>
</dependency>
<!-- mysql driver -->
<dependency>
<artifactId> mysql-connector-java </artifactId>
<groupId> mysql</groupId >
</dependency>
<dependency>
<groupId> org.apache.tomcat</groupId >
<artifactId> tomcat-jdbc</artifactId>
</dependency>
<!-- common module -->
<dependency>
<groupId> org.codehaus.jackson</groupId >
<artifactId> jackson-mapper-asl</artifactId >
</dependency>
<dependency>
<groupId> org.slf4j</groupId >
<artifactId> jcl-over-slf4j </artifactId>
</dependency>
<dependency>
<groupId> ch.qos.logback</groupId >
<artifactId> logback-classic </artifactId>
</dependency>
<dependency>
<groupId> commons-digester</groupId >
<artifactId> commons-digester</artifactId >
<version> 1.8</ version>
<scope> runtime</ scope>
<exclusions>
<exclusion>
<groupId> commons-logging</groupId >
<artifactId> commons-logging</artifactId >
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId> com.google.guava</groupId >
<artifactId> guava</artifactId >
</dependency>
<dependency>
<groupId> commons-dbcp </groupId>
<artifactId> commons-dbcp </artifactId>
</dependency>
</dependencies >
</project>
3.配置web.xml
|
4.src/main/resources/org/sh/xml中建立applicationContext.xml
|
MapperScannerConfigurer
没有必要在 Spring 的 XML 配置文件中注册所有的映射器。相反,你可以使用一个 MapperScannerConfigurer , 它 将 会 查 找 类 路 径 下 的 映 射 器 并 自 动 将 它 们 创 建 成 MapperFactoryBean。
要创建 MapperScannerConfigurer,可以在 Spring 的配置中添加如下代码:
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" >
<property name= "basePackage" value ="org.sh.dao" />
</bean >
</beans>
5.在src/main/resources/org/sh/xml中建立hello-servlet.xml
命名方式web.xml中DispatcherServlet的名加上 -servlet
|
6.建立mybatis-config.xml
建立好的资源目录如下图所示:
|
7.user.xml
|
7.继续 建立如下图的java文件
|
然后在/WEB-INF/jsp/ 中建立addUser.jsp
将项目打war包,放入tomcat 启动tomcat war包自动解压。可以随意更改文件夹的名字
在浏览器中输入:http://localhost:8080/examing-Thrid-0.0.1-SNAPSHOT/ 或者http://localhost:8080/examing-Thrid-0.0.1-SNAPSHOT/hello/(对于我这个demo而言) 效果如下:
ClassPathb表示当前路径