• 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

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

  • 相关阅读:
    Apache Commons IO组件简介说明
    Linux文件的各种*id属性
    音视频方法技术有哪些?H.265技术详解
    下载、安装CAN-EYE植被参数工具
    Java题:查找单链表中第 k 个节点元素的值
    基于PHP+MySQL学生创新作品展示系统的设计与实现
    《ToDesk云电脑vs青椒云性能测试,谁更能实现游戏自由?》
    23、基于51单片机的三路超声波测距系统(Proteus仿真+程序+设计报告)
    为什么你的敏捷总是不成功?
    08-RabbitMQ使用中的常见问题
  • 原文地址:https://blog.csdn.net/xiamaocheng/article/details/134022774