论坛
潜水/灌水快乐,沉淀知识,认识更多同行。
ToB圈子
加入IT圈,遇到更多同好之人。
朋友圈
看朋友圈动态,了解ToB世界。
ToB门户
了解全球最新的ToB事件
博客
Blog
排行榜
Ranklist
文库
业界最专业的IT文库,上传资料也可以赚钱
下载
分享
Share
导读
Guide
相册
Album
记录
Doing
搜索
本版
文章
帖子
ToB圈子
用户
免费入驻
产品入驻
解决方案入驻
公司入驻
案例入驻
登录
·
注册
只需一步,快速开始
账号登录
立即注册
找回密码
用户名
Email
自动登录
找回密码
密码
登录
立即注册
首页
找靠谱产品
找解决方案
找靠谱公司
找案例
找对的人
专家智库
悬赏任务
圈子
SAAS
IT评测·应用市场-qidao123.com
»
论坛
›
物联网
›
物联网
›
重构测试项目为spring+springMVC+Mybatis框架
重构测试项目为spring+springMVC+Mybatis框架
李优秀
金牌会员
|
2025-2-18 13:12:46
|
显示全部楼层
|
阅读模式
楼主
主题
680
|
帖子
680
|
积分
2040
重构测试项目为spring+springMVC+Mybatis框架
配景
继前次将自动化测试时的医药管理信息系统项目用idea运行乐成后,由于项目结构有些乱,一部分代码好像也重复,于是计划重新重构以下该项目,这次先利用spring+springMVC+Mybatis框架
一、计划项目目录结构
按ssm框架重新计划了目录结构,删除了一些重复代码
├─.idea
├─src
│ └─main
│ ├─java
│ │ └─mms
│ │ ├─controller
│ │ ├─interceptors
│ │ ├─mapper
│ │ ├─pojo
│ │ └─services
│ ├─resources
│ │ ├─mybatis
│ │ │ ├─mybatis-config.xml
│ │ │ └─mappers
│ │ ├─spring
│ │ │ ├─applicationContext.xml
│ │ │ ├─applicationContext-mybatis.xml
│ │ │ └─springMVCConfig.xml
│ │ ├─jdbc.properties
│ │ ├─log4j.properties
│ │ └─static
│ │ ├─css
│ │ ├─images
│ │ ├─js
│ │ └─myjavascript
│ └─webapp
│ └─WEB-INF
│ └─templates
│ ├─agency
│ ├─client
│ └─medicine
└─target
复制代码
同时也修改了文件名(tabs–>templates),如果你也修改了记得将对应的代码也进行修改
二、将war包中的class
由于老师给的是项目打包后的war包,代码都是.class文件,我们需要利用工具JD-GUI将.class文件转换为.java文件,转换后将.java文件放入对应的包下。
三、修改配置文件springMVCConfig.xml并添加控制器
由于资源文件位置发生了改变,重启项目后会出现资源访问404的错误,我们需要对相关的配置文件springMVCConfig.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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 注解驱动 -->
<mvc:annotation-driven />
<!-- 定义Controller的扫描包 -->
<context:component-scan base-package="mms.controller" />
<!-- 定义静态资源映射 -->
<mvc:resources mapping="/static/**" location="classpath:/static/" />
<!-- 定义视图解析器 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/templates/" />
<property name="suffix" value=".html" />
</bean>
<!-- 处理静态资源被“/”所拦截的问题 -->
<mvc:default-servlet-handler />
<!-- 定义拦截器 -->
<mvc:interceptors>
<mvc:interceptor>
<!-- 所有的请求都进入 -->
<mvc:mapping path="/**"/>
<!-- 不拦截登陆页面 -->
<mvc:exclude-mapping path="/login.html" />
<mvc:exclude-mapping path="/static/css/*" />
<mvc:exclude-mapping path="/static/js/**" />
<mvc:exclude-mapping path="/static/images/*" />
<!-- 不拦截处理登陆的业务 -->
<mvc:exclude-mapping path="/Login/loginUser" />
<bean class="mms.interceptors.MyHandlerInterceptor"/>
</mvc:interceptor>
</mvc:interceptors>
</beans>
复制代码
由于之前的html文件都是直接袒露在根目录下的静态资源,因此可以直接通过 URL 访问。而现在我们将html文件移动到 WEB-INF 目录下,需要视图解析器通过控制器返回视图名去访问,因此我们还需要添加控制器IndexController
package mms.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @author Orange peel
* @create 2025-02-16 19:08
*/
@Controller
public class IndexController {
@RequestMapping("/index")
public String showIndex() {
return "index"; // 返回的视图名称
}
@RequestMapping("/templates/client/Search")
public String clientSearch() {
return "client/Search";
}
@RequestMapping("/templates/agency/Search")
public String agencySearch() {
return "agency/Search";
}
@RequestMapping("/templates/medicine/Search")
public String medicineSearch() {
return "medicine/Search";
}
@RequestMapping("/templates/client/Entry")
public String clientEntry() {
return "client/Entry";
}
@RequestMapping("/templates/agency/Entry")
public String agencyEntry() {
return "agency/Entry";
}
@RequestMapping("/templates/medicine/Entry")
public String medicineEntry() {
return "medicine/Entry";
}
@RequestMapping("/templates/client/Delete")
public String clientDelete() {
return "client/Delete";
}
@RequestMapping("/templates/agency/Delete")
public String agencyDelete() {
return "agency/Delete";
}
@RequestMapping("/templates/medicine/Delete")
public String medicineDelete() {
return "medicine/Delete";
}
@RequestMapping("/templates/client/Modify")
public String clientModify() {
return "client/Modify";
}
@RequestMapping("/templates/agency/Modify")
public String agencyModify() {
return "agency/Modify";
}
@RequestMapping("/templates/medicine/Modify")
public String medicineModify() {
return "medicine/Modify";
}
@RequestMapping("/templates/client/Browse")
public String clientBrowse() {
return "client/Browse";
}
@RequestMapping("/templates/agency/Browse")
public String agencyBrowse() {
return "agency/Browse";
}
@RequestMapping("/templates/medicine/Browse")
public String medicineBrowse() {
return "medicine/Browse";
}
@RequestMapping("/templates/client/Report")
public String clientReport() {
return "client/Report";
}
@RequestMapping("/templates/agency/Report")
public String agencyReport() {
return "agency/Report";
}
@RequestMapping("/templates/medicine/Report")
public String medicineReport() {
return "medicine/Report";
}
@RequestMapping("/templates/User")
public String User() {
return "User";
}
}
复制代码
四、配置tomcat后直接启动即可
等下次有空再重构成springboot项目,加纳~
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
本帖子中包含更多资源
您需要
登录
才可以下载或查看,没有账号?
立即注册
x
回复
使用道具
举报
0 个回复
倒序浏览
返回列表
快速回复
高级模式
B
Color
Image
Link
Quote
Code
Smilies
您需要登录后才可以回帖
登录
or
立即注册
本版积分规则
发表回复
回帖并转播
回帖后跳转到最后一页
发新帖
回复
李优秀
金牌会员
这个人很懒什么都没写!
楼主热帖
什么是API密钥及其安全利用指南? ...
【Java结业计划】基于JavaWeb的在线购 ...
基于GLM生成SQL,基于MOSS生成SQL,其 ...
Docker Compose - 安装和基本使用 ...
mac安装java17(jdk17)
【云原生 | 从零开始学Kubernetes】二 ...
[Qt][Qt 网络][下]具体讲解
Linux体系(CentOS)下安装设置 Nginx 超 ...
C#使用NModbus4库创建Modbus TCP Slave ...
在 ubuntu20.04 中安装 XTdrone 心路历 ...
标签云
AI
运维
CIO
存储
服务器
浏览过的版块
IOS
linux
前端开发
移动端开发
运维.售后
Mysql
数据仓库与分析
程序人生
.Net
Postrge-SQL技术社区
快速回复
返回顶部
返回列表