您的位置:首页 > 编程语言 > Java开发

Myeclipse创建Maven-web项目,并整合springmvc+mybatis

2018-02-17 23:24 816 查看
先创建maven-web项目:    1、右键-new-other,选择maven project,点击next2、选择项目存储位置 3、选择webapp4、输入组名和项目名注意:如果项目目录下面没有src/main/java的资源文件夹,则需要按如下步骤进行处理项目目录:1、右键-build path-configure build path2、删除(missing)的资源目录3、重新新建src/main/java资源目录项目创建完成后,先整合springMVC1、在pom.xml文件里添加springmvc包<dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>4.1.2.RELEASE</version><scope>compile</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>4.1.2.RELEASE</version><scope>compile</scope></dependency>2、创建springmvc配置文件3、配置springmvc<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:task="http://www.springframework.org/schema/task"xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.2.xsd">        
        <!-- 注册映射器和解析器 -->
<mvc:annotation-driven></mvc:annotation-driven>
        <!-- 扫描包 --><context:component-scan base-package="com.tang.dayone.controller"> </context:component-scan>
        <!--配置前缀和后缀 --><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/"></property><property name="suffix" value=".jsp"></property></bean></beans>
4、在web.xml注册springmvc<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"><!-- 注册springmvc --><servlet><servlet-name>springmvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring/springmvc.xml</param-value></init-param></servlet><!-- 配置拦截器 --><servlet-mapping><servlet-name>springmvc</servlet-name><url-pattern>*.html</url-pattern></servlet-mapping></web-app>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐