• 从搭建SpringMVC环境到实现增删改查&&文件上传-文件下载


    目录

    一、搭建SpringMVC环境

    1.1 导入相关pom依赖 

    1.2 导入框架配置文件

    1.4 springmvc的配置文件

    1.5 导入相关工具类

    1.6 逆向生成代码 

    1.7 配置tomcat

    二、实现增删改查

    2.1 配置ClazzMapper.xml

    2.2 编写接口方法

    2.3 创建实现类 

    2.4 导入切面类

    2.5 建立Web层

    三、实现文件上传

    3.1 在springmvc-servlet.xml中添加多功能解析器配置

    3.2 上传文件的jsp页面添加多功能表单设置

    3.3 利用multipartFile类接收文件

    3.4 完成请求图片地址与硬盘地址的映射

    四、实现文件下载

    4.1 通过文件ID查询出文件路径

    4.2 通过文件请求路径转换为文件存放的硬盘地址

    4.3 将硬盘中的文件下载


    一、搭建SpringMVC环境

    1.1 导入相关pom依赖 

    我们第一步就是导入相关的pom依赖;

    但是记得一定要考虑网络问题,如果网络实在不好就一个一个的导入下载。

    pom依赖:

    1. "1.0" encoding="UTF-8"?>
    2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    4. <modelVersion>4.0.0modelVersion>
    5. <groupId>org.examplegroupId>
    6. <artifactId>ssmToartifactId>
    7. <version>1.0-SNAPSHOTversion>
    8. <packaging>warpackaging>
    9. <name>ssmTo Maven Webappname>
    10. <url>http://www.example.comurl>
    11. <properties>
    12. <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
    13. <maven.compiler.source>1.8maven.compiler.source>
    14. <maven.compiler.target>1.8maven.compiler.target>
    15. <maven.compiler.plugin.version>3.7.0maven.compiler.plugin.version>
    16. <spring.version>5.0.2.RELEASEspring.version>
    17. <mybatis.version>3.4.5mybatis.version>
    18. <mysql.version>5.1.44mysql.version>
    19. <pagehelper.version>5.1.2pagehelper.version>
    20. <mybatis.spring.version>1.3.1mybatis.spring.version>
    21. <commons.dbcp2.version>2.1.1commons.dbcp2.version>
    22. <commons.pool2.version>2.4.3commons.pool2.version>
    23. <log4j2.version>2.9.1log4j2.version>
    24. <junit.version>4.12junit.version>
    25. <servlet.version>4.0.0servlet.version>
    26. <lombok.version>1.18.2lombok.version>
    27. properties>
    28. <dependencies>
    29. <dependency>
    30. <groupId>org.springframeworkgroupId>
    31. <artifactId>spring-contextartifactId>
    32. <version>${spring.version}version>
    33. dependency>
    34. <dependency>
    35. <groupId>org.springframeworkgroupId>
    36. <artifactId>spring-ormartifactId>
    37. <version>${spring.version}version>
    38. dependency>
    39. <dependency>
    40. <groupId>org.springframeworkgroupId>
    41. <artifactId>spring-txartifactId>
    42. <version>${spring.version}version>
    43. dependency>
    44. <dependency>
    45. <groupId>org.springframeworkgroupId>
    46. <artifactId>spring-aspectsartifactId>
    47. <version>${spring.version}version>
    48. dependency>
    49. <dependency>
    50. <groupId>org.springframeworkgroupId>
    51. <artifactId>spring-webartifactId>
    52. <version>${spring.version}version>
    53. dependency>
    54. <dependency>
    55. <groupId>org.springframeworkgroupId>
    56. <artifactId>spring-testartifactId>
    57. <version>${spring.version}version>
    58. dependency>
    59. <dependency>
    60. <groupId>org.mybatisgroupId>
    61. <artifactId>mybatisartifactId>
    62. <version>${mybatis.version}version>
    63. dependency>
    64. <dependency>
    65. <groupId>mysqlgroupId>
    66. <artifactId>mysql-connector-javaartifactId>
    67. <version>${mysql.version}version>
    68. dependency>
    69. <dependency>
    70. <groupId>com.github.pagehelpergroupId>
    71. <artifactId>pagehelperartifactId>
    72. <version>${pagehelper.version}version>
    73. dependency>
    74. <dependency>
    75. <groupId>org.mybatisgroupId>
    76. <artifactId>mybatis-springartifactId>
    77. <version>${mybatis.spring.version}version>
    78. dependency>
    79. <dependency>
    80. <groupId>org.apache.commonsgroupId>
    81. <artifactId>commons-dbcp2artifactId>
    82. <version>${commons.dbcp2.version}version>
    83. dependency>
    84. <dependency>
    85. <groupId>org.apache.commonsgroupId>
    86. <artifactId>commons-pool2artifactId>
    87. <version>${commons.pool2.version}version>
    88. dependency>
    89. <dependency>
    90. <groupId>org.apache.logging.log4jgroupId>
    91. <artifactId>log4j-coreartifactId>
    92. <version>${log4j2.version}version>
    93. dependency>
    94. <dependency>
    95. <groupId>org.apache.logging.log4jgroupId>
    96. <artifactId>log4j-apiartifactId>
    97. <version>${log4j2.version}version>
    98. dependency>
    99. <dependency>
    100. <groupId>org.apache.logging.log4jgroupId>
    101. <artifactId>log4j-webartifactId>
    102. <version>${log4j2.version}version>
    103. dependency>
    104. <dependency>
    105. <groupId>junitgroupId>
    106. <artifactId>junitartifactId>
    107. <version>${junit.version}version>
    108. <scope>testscope>
    109. dependency>
    110. <dependency>
    111. <groupId>javax.servletgroupId>
    112. <artifactId>javax.servlet-apiartifactId>
    113. <version>${servlet.version}version>
    114. <scope>providedscope>
    115. dependency>
    116. <dependency>
    117. <groupId>org.projectlombokgroupId>
    118. <artifactId>lombokartifactId>
    119. <version>${lombok.version}version>
    120. <scope>providedscope>
    121. dependency>
    122. <dependency>
    123. <groupId>org.springframeworkgroupId>
    124. <artifactId>spring-webmvcartifactId>
    125. <version>${spring.version}version>
    126. dependency>
    127. <dependency>
    128. <groupId>javax.servlet.jspgroupId>
    129. <artifactId>javax.servlet.jsp-apiartifactId>
    130. <version>2.3.3version>
    131. dependency>
    132. <dependency>
    133. <groupId>jstlgroupId>
    134. <artifactId>jstlartifactId>
    135. <version>1.2version>
    136. dependency>
    137. <dependency>
    138. <groupId>taglibsgroupId>
    139. <artifactId>standardartifactId>
    140. <version>1.1.2version>
    141. dependency>
    142. <dependency>
    143. <groupId>junitgroupId>
    144. <artifactId>junitartifactId>
    145. <version>4.11version>
    146. <scope>testscope>
    147. dependency>
    148. dependencies>
    149. <build>
    150. <finalName>ssmTofinalName>
    151. <resources>
    152. <resource>
    153. <directory>src/main/javadirectory>
    154. <includes>
    155. <include>**/*.xmlinclude>
    156. includes>
    157. resource>
    158. <resource>
    159. <directory>src/main/resourcesdirectory>
    160. <includes>
    161. <include>jdbc.propertiesinclude>
    162. <include>*.xmlinclude>
    163. includes>
    164. resource>
    165. resources>
    166. <pluginManagement>
    167. <plugins>
    168. <plugin>
    169. <groupId>org.apache.maven.pluginsgroupId>
    170. <artifactId>maven-compiler-pluginartifactId>
    171. <version>${maven.compiler.plugin.version}version>
    172. <configuration>
    173. <source>${maven.compiler.source}source>
    174. <target>${maven.compiler.target}target>
    175. <encoding>${project.build.sourceEncoding}encoding>
    176. configuration>
    177. plugin>
    178. <plugin>
    179. <groupId>org.mybatis.generatorgroupId>
    180. <artifactId>mybatis-generator-maven-pluginartifactId>
    181. <version>1.3.2version>
    182. <dependencies>
    183. <dependency>
    184. <groupId>mysqlgroupId>
    185. <artifactId>mysql-connector-javaartifactId>
    186. <version>${mysql.version}version>
    187. dependency>
    188. dependencies>
    189. <configuration>
    190. <overwrite>trueoverwrite>
    191. configuration>
    192. plugin>
    193. <plugin>
    194. <artifactId>maven-clean-pluginartifactId>
    195. <version>3.1.0version>
    196. plugin>
    197. <plugin>
    198. <artifactId>maven-res
  • 相关阅读:
    解决wangeditor点击全屏被遮挡的问题
    React Server Component: 混合式渲染
    Dijkstra与Bellman-Ford算法对比
    Yarp 与 Nginx性能大比拼不出所料它胜利了!
    渗透测试——找寻绝对路径的方法总结
    1-氨丙基-3-甲基咪唑溴盐离子液体修饰碳量子点(L-CQDs)负载TiO2纳米颗粒(试剂)
    网络安全(黑客)—-2024自学手册
    计算机毕设 大数据工作岗位数据分析与可视化 - python flask
    计算机毕业设计php基本微信小程序的贵小团校园社团小程序
    【canvas教程】实现画布拖动、定点缩放,支持手势与鼠标滚轮操作
  • 原文地址:https://blog.csdn.net/qq_63492318/article/details/126412308