今天学了挺多东西,半抄半写的把简单的demo复现了一下,借着写博客的机会再整理一下思路
创建Maven Web项目,添加依赖
idea打开新建Project->Maven->maven-archetype-webapp
选好自己的maven地址
接着在pom.xml中的dependencies下添加依赖:
<!--SpringMVC 提供了构建Web应用程序的全功能MVC模块-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.7.RELEASE</version>
</dependency>
<!--SpringJDBC 对原始JdbcAPI对象的简单封装-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.2.7.RELEASE</version>
</dependency>
<!--SpringAOP 面向切面编程,解决横切性问题达到与著业务逻辑解耦的目的-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>5.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>5.2.7.RELEASE</version>
</dependency>
<!--Mybatis 持久层框架-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.5</version>
</dependency>
<!--Mybatis整合Spring-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.0.5</version>
</dependency>
<!-- mysql驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.20</version>
</dependency>
<!-- c3p0 连接池技术 -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.4</version>
</dependency>
<!-- JSTL jsp standred Tag library -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- Servlet API 配合jsp使用-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
然后看一下一个非常简单的ssm框架的的目录
其中resources中:
- config.xml用来辅助mybatis,例如配置别名与打印logging
- spring.xml用来整合mybatis与spring
- springmvc.xml用来配置视图解析器
接下来配置web.xml
<!-- Spring -->
<!-- 1. 启动Spring -->
<!-- context 上下文 ==》 运行环境 -->
<!-- 1.1 配置全局参数 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<!-- classpath 相当于 resources路径 -->
<param-value>classpath:spring.xml</param-value>
</context-param>
<!-- 1.2 配置监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- SpringMVC -->
<!-- 2. 启动 SpringMVC -->
<!-- 2.1. 配置核心servlet DispathcerServlet-->
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 2.1.1 引入 SpringMVC 的配置文件 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
</servlet>
<!-- 2.2 配置servlet的映射 -->
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<!-- 允许所有url请求通过 -->
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- 字符编码过滤器-->
<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>
<!-- 4. 加载静态资源 -->
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>
先写到这里,明天更从界面到数据库的详细过程