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架构:
structs2 重构成SpringBoot架构_第1张图片

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>

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 Boottitle>
    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

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

你可能感兴趣的:(1024程序员节)