随笔

一SSM项目的创建

  1、在创建好的maven项目中新建java文件夹和resources文件夹

     ①java文件夹mark directory as sources root

    ②resources文件夹mark directory as resources root

  2、在resources文件夹中新建springmvc-conf.xml文件

  3、在resources文件夹中新建applicationContext.xml文件

  4、在resources文件夹中新建datbase.properties文件

  5、在resources文件夹中新建log4j.properties文件

二、web.xml的配置

①servlet

<servlet>
 <servlet-name>dispatcherServletservlet-name>
 <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
 <init-param>
   <param-name>contextConfigLocationparam-name>
   <param-value>classpath:sprigMVc.xmlparam-value>
 </init-param>
   
  load-on-start元素标记容器是是否在启动的时候就加载这个servlet
  x的值必须是一个整数,表示servlet应该被载入的顺序,当它的值大于或等于0时,表示同期在应用启动时就初始化这个servlet,当它的值小于0时表示容器在该servlet被选择时才会被加载,当值相同时容器自己选择顺序加载
  x的取值12345代表的是优先级
   
 <load-on-startup>xload-on-startup>
servlet>

<servlet-mapping>
 <servlet-name>dispatcherServletservlet-name>
 <url-pattern>/url-pattern>
url是后缀为/的请求都必须经过spring容器
servlet-mapping>

②filter过滤器

<filter>
 <filter-name>encodingFilterfilter-name>
 <filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
 <init-param>
   <param-name>encodingparam-name>
   <param-value>UTF-8param-value>
 init-param>
 <init-param>
   <param-name>forceEncodingparam-name>
   <param-value>trueparam-value>
 init-param>
filter>
<filter-mapping>
 <filter-name>encodingFilterfilter-name>
 <url-pattern>/*url-pattern>
filter-mapping>

三、springmvc-conf.xml的配置

1、页面架构,头文件

version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">

2、页面目录配置(视图解析器)

指定控制页面转向的目录及文件后缀

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
   <property name="prefix" value="/WEB-INF/pages/">property>
   <property name="suffix" value=".jsp">property>
bean>

3、扫描controller包

<context:component-scan base-package="cn.travel.controller">context:component-scan>

4、开启mvc支持

<mvc:annotation-driven>mvc:annotation-driven>

四、导入依赖

(此处为培训所需ssm依赖)

  <properties>
   <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
     指定spring版本
   <spring.version>5.0.2.RELEASEspring.version>
 properties>


<dependencies>
<!--单元测试依赖-->
 <dependency>
   <groupId>junitgroupId>
   <artifactId>junitartifactId>
   <version>4.11version>
   <scope>testscope>
 dependency>
   <!--使用action调用servlet里面get和post方法的时候需要这两个个jar包-->
 <dependency>
   <groupId>javax.servletgroupId>
   <artifactId>javax.servlet-apiartifactId>
   <version>3.1.0version>
   <scope>providedscope>
 dependency>
 <dependency>
   <groupId>javax.servlet.jspgroupId>
   <artifactId>jsp-apiartifactId>
   <version>2.2version>
   <scope>providedscope>
 dependency>
      <!--JSTL-->
   <dependency>
     <groupId>javax.servletgroupId>
     <artifactId>jstlartifactId>
     <version>1.2version>
     <scope>runtimescope>
   dependency>
<!--mysql驱动-->
 <dependency>
   <groupId>mysqlgroupId>
   <artifactId>mysql-connector-javaartifactId>
   <version>5.1.26version>
   <scope>compilescope>
 dependency>
  <!--druid连接池-->
 <dependency>
   <groupId>com.alibabagroupId>
   <artifactId>druidartifactId>
   <version>1.0.9version>
 dependency>
   <!--fastjson-->
 <dependency>
   <groupId>com.alibabagroupId>
   <artifactId>fastjsonartifactId>
   <version>1.2.75version>
 dependency
版权声明:本文为wanli-test1原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/wanli-test1/p/14945057.html