• 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.bootgroupId>
        <artifactId>spring-boot-starter-webartifactId>
    dependency>
    <dependency>
      <groupId>org.apache.strutsgroupId>
      <artifactId>struts2-spring-boot-pluginartifactId>
      <version>2.5.22version>
    dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    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;
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    4.编写JSP视图

    DOCTYPE html>
    <html>
        <head>
            <title>Hello Struts 2 with Spring Boottitle>
        head>
        <body>
            <h1>${message}h1>
        body>
    html>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    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

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

  • 相关阅读:
    关于安卓毛玻璃实现(二)动态毛玻璃recyclerview
    Redis的应用
    springboot导出Excel中,文件名带@,没有正常显示,显示为%40
    10. SAP ABAP OData 服务如何支持修改(Update)操作
    期末前端web大作业——我的家乡陕西介绍网页制作源码HTML+CSS+JavaScript
    项目经理如何去拆分复杂项目?
    PowerPC平台移植RTL8822BU
    计算机网络第4章-网络层(1)
    基于最近电平逼近的开环MMC逆变器MATLAB仿真模型
    排序算法——希尔排序
  • 原文地址:https://blog.csdn.net/xiamaocheng/article/details/134022774