structs2 重构成SpringBoot架构

structs2 重构成SpringBoot架构

Survive by day and develop by night.
talk for import biz , show your perfect code,full busy,skip hardness,make a better result,wait for change,challenge Survive.
happy for hardess to solve denpendies.

目录

1.1 structs2架构:
在这里插入图片描述

1.2 springboot 架构

1.3 演化要点:
1.基于前端的展示层不需要修改
2.HttpServlet 将会有SpringBoot annotation 来处理
3.构建前置的Structs url 转发器,适配
4.ActionSupport将由SpringBoot 进行接管,由于SpringBoot 完成java Bean 的装配完成三层操作。
5.返回的result 模型层将会以通过集合的形式,传递给对应的前端层。
完成流程的扭转。
1.4 操作步骤:

将structs2 改造成 SpringBoot 可以采用以下步骤:

1.导入相关的依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
  <groupId>org.apache.struts</groupId>
  <artifactId>struts2-spring-boot-plugin</artifactId>
  <version>2.5.22</version>
</dependency>

2.在application.properties文件中添加Struts2配置

spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsp

struts.convention.action.packages = com.example.action
struts.enable.DynamicMethodInvocation = true
struts.devMode = true

3.编写Action类

package com.example.action;

import com.opensymphony.xwork2.ActionSupport;

public class HelloAction extends ActionSupport {

    private String message;

    public String execute() throws Exception {
        message = "Hello Struts 2 with Spring Boot!";
        return SUCCESS;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}

4.编写JSP视图

<!DOCTYPE html>
<html>
    <head>
        <title>Hello Struts 2 with Spring Boot</title>
    </head>
    <body>
        <h1>${message}</h1>
    </body>
</html>

5.启动Spring Boot应用程序并访问 http://localhost:8080/hello,应该看到 “Hello Struts 2 with Spring Boot!” 文字。

注意:以上步骤仅适用于 Struts 2.5.x 或更高版本。如果您使用的是旧版本的 Struts2,则可能需要使用 struts2-spring-plugin 进行集成。

参考资料和推荐阅读

参考资料
官方文档
开源社区
博客文章
书籍推荐
参考资料:

  1. https://blog.csdn.net/huzia/article/details/124345353
  2. https://blog.csdn.net/qq_29423387/article/details/88654018

欢迎阅读,各位老铁,如果对你有帮助,点个赞加个关注呗!同时,期望各位大佬的批评指正~

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

执于代码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值