ssm整合-动态项目-day13

一.动态web项目与maven项目

  1.动态项目可以调数据和改数据不需要关闭tomcat,每次启动特浪费时间maven项目。

  2.maven项目不需要添加jar包,导入依赖,直接去本地仓库找,没有再去中央仓库找。

  3.运行不同,一个是直接运行tmocat,一个是在pom.xml里配置tomcat,控制台会出现网址,输入网址就可以运行了。

二。动态web项目

  1.首先配置web.xml:配置四个属性一个是spring.xml的位置,一个是applicationContext.xml的位置,还有一个是乱码问题,最后是post请求转化成put和delete请求的操作。

<?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_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>ssm-01</display-name>
  <!-- 配置applicantionContext.xml -->
  <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
      <listener> 
          <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
  <!-- The front controller of this Spring Web application, responsible for handling all application requests -->
    <!-- 配置springmvc.xml -->
    <servlet>
        <servlet-name>springDispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:springmvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <!-- 设置一个拦截器,调整所有的乱码问题,拦截所有文件 -->
    <filter>
        <filter-name>CharacterEncodingFilter</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>CharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>    
    
    <!-- Map all requests to the DispatcherServlet for handling -->
    <servlet-mapping>
        <servlet-name>springDispatcherServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <filter>
    <!-- 配置post请求转put和delete请求 -->
    <filter-name>HiddenHttpMethodFilter</filter-name>
        <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>HiddenHttpMethodFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>

二.配置springmvc.xml,applicationContext.xml,mybatis-config.xml,和log4j.xml,最后导入jdbc.properties.。

  1.springmvc.xml

  2.applicationContext.xml

  3.mybatis-config.xml

  4.log4j.xml

  5.jdbc.properties

三.导入必要的框架开始写实体类即可。

  先写controller,再写service,再写mapper接口,最后写mapper.xml.在mapper.xml里按照数据库的要求来配置实体类。

原文地址:https://www.cnblogs.com/guomingyt/p/8118844.html