idea搭建Springweb项目

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项目的开发。不过没有配置视图解析器,因为我自己的项目中暂时还没有用到。用到后可以在配置

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值