概述
1、File–>new–>Project
2、填写项目名称
3、选择maven版本
4、选择了项目保存路径后,点击finash完成项目建立
5、导包spring-webmvc4.3.9.RELEASE,jackson-annotations2.8.5,jackson-core2.8.5,jackson-databind 2.8.5,mybatis3.4.5,mybatis-spring1.3.1,spring-jdbc4.3.10.RELEASE,commons-dbcp1.4,junit4.12, mysql-connnector-java5.1.6
6、上一步包导入完成后,后面测试还少一个包,先导入进来
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
7、新建4个文件夹
8、设置新文件夹的作用
最后点击apply ok确认
9、配置Tomcat
10、Tomcat启动后可以看到响应的网页信息
11、新建wfc文件夹和jdbc.properties spring-mvc.xml两个配置文件
12、jdbc中的配置为
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/cloud_note
user=root
password=123456
maxActive=20
13、spring-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:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa" 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.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<context:component-scan base-package="wfc"/>
<mvc:annotation-driven/>
</beans>
14、在wfc目录下新建dao、controller、service、entity等目录。在resources下新建目录mapper并在mapper里面新建userMapper.xml文件。修改spring-mvc.xml文件,增加如下内容
<util:properties id="jdbc" location="classpath:conf/jdbc.properties"/>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="#{jdbc.driver}"/>
<property name="url" value="#{jdbc.url}"/>
<property name="username" value="#{jdbc.user}"/>
<property name="password" value="#{jdbc.password}"/>
<property name="maxActive" value="#{jdbc.maxActive}"/>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mapperLocations" value="classpath:mapper/*.xml"/>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="wfc.dao"/>
</bean>
15、在dao文件夹下新建UserDao接口,在userMapper.xml中配置如下内容
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
<mapper namespace="wfc.dao.UserDao">
</mapper>
16、配置DispatcherServlet增加如下内容
<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:conf/spring-*.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
17、至此,框架基本搭建完成,可以进行web项目的开发。不过没有配置视图解析器,因为我自己的项目中暂时还没有用到。用到后可以在配置
最后
以上就是务实身影为你收集整理的idea搭建Springweb项目的全部内容,希望文章能够帮你解决idea搭建Springweb项目所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复