目录
1.4、在接下来的面板中选择你的本地的maven的安装路径以及配置maven时设置的setting文件,选择完成后点击【Next】;
1.5、在接下来的界面中填写项目名,填写完成后点击【Finish】;
分析:出现以下报错原因是因为找不到配置文件,可能是因为以下2种原因引起的:
分析:这是在maven进行clean的时候报的错(clean也就是删除target)
使用的编辑器:idea+maven
使用的框架ssm(spring+springMVC+mybatis)
使用的服务器:tomcat
创建整个项目的顺序:
1、在idea上搭建一个基于maven的web项目
1.1、点击file-->new--->project
1.2、在“New Project”页面左侧选中maven选项,我们创建的是一个最简单的maven项目,需要做的是勾选图示所示的“Create From Archetype”复选框,在下面的下拉选项中我们选择“webapp”,之后点击【Next】;
1.3、在接下来的面板中,我们填写maven的坐标,“groupId”,“artifactId”,以及“version”,其中groupId是公司域名的反写,而artifactId是项目名或模块名,而version就是该项目或模块所对应的版本号。填写完之后,点击【Next】;
1.4、在接下来的面板中选择你的本地的maven的安装路径以及配置maven时设置的setting文件,选择完成后点击【Next】;
1.5、在接下来的界面中填写项目名,填写完成后点击【Finish】;
2、开始创建项目的目录结构,创建的结构如下图
2.1、 这是总体的结构
2.2 、这个是展开的结构
3、创建各个配置文件
3.1 、 web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Archetype Created Web Application</display-name>
<!--可以使其找到配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-config.xml</param-value>
</context-param>
<!-- 解决工程编码过滤器 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring配置(监听器) -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- SpringMVC配置 -->
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/index.jsp</url-pattern><!--浏览器访问地址-->
</servlet-mapping>
<!-- 添加do请求 -->
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- 添加json请求 -->
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>*.json</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
3.2 、 spring-config.xml
<?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: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.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"
default-autowire="byName">
<context:component-scan base-package="com.job" />
<aop:aspectj-autoproxy/>
<!-- 属性文件读入 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:prop/*.properties</value>
</list>
</property>
</bean>
<import resource="classpath:spring/spring-*.xml"/>
</beans>
3.3 、spring-config-mvc.xml
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 -->
<context:component-scan base-package="com.job.controller"/>
<mvc:annotation-driven/>
<!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->
<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
<!-- 启动SpringMVC的注解功能,完成请求和注解POJO的映射 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="mappingJacksonHttpMessageConverter"/>
<!-- JSON转换器 -->
</list>
</property>
<