Stripes MVC 模型数据

发布于 2024-09-27 02:12:49 字数 354 浏览 2 评论 0原文

我对 Spring MVC 有经验,正在尝试 Stripes 来决定是否在新项目中尝试它。

在 Spring MVC 中,我将准备模型数据并将其传递到视图,方法是将其添加到控制器创建的 ModelAndView 实例中的映射中。我很难找到与 Stripes 相同的内容。

似乎最接近的相似之处是让 ActionBean 准备我的模型数据并将其添加到 HttpSession。 ForwardRedirect 用于加载视图并从会话访问数据。

Stripes 是否对前端控制器提供了更好的支持,或者这是与 Spring MVC 完全不同的设计原理? (即我必须使用 EL 从视图中调用方法来检索数据,正如某些示例所做的那样)

谢谢!

I am experienced with Spring MVC and am trying out Stripes to decide whether to try it out for a new project.

In Spring MVC I would prepare model data and pass it to the view by adding it to a map in the ModelAndView instance created by my controller. I am having trouble finding the equivalent of this for Stripes.

It seems like the closest parallel is to have an ActionBean prepare my model data and add it to the HttpSession. A ForwardRedirect is used to load the view and the data is accessed from the session.

Is there better support for a front controller provided by Stripes, or is this a totally different design principle than Spring MVC? (ie I have to invoke methods from the view using EL to retrieve data, as some of the examples do)

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

℡寂寞咖啡 2024-10-04 02:12:49

Stripes 中的典型 MVC 设计类似于下面的代码。

JPA 实体由 Stripersist 提供的 Stripes 拦截器自动加载(但是这也可以轻松地自己实现 如果你愿意的话)。因此,在此示例中,请求 http://your.app/show-order-12.html 将从数据库加载 id 为 12 的订单并将其显示在页面上。

控制器 (OrderAction.java):

@UrlBinding("/show-order-{order=}.html")
public class OrderAction implements ActionBean {
    private ActionBeanContext context;
    private Order order;

    public ActionBeanContext getContext() {
        return context;
    }

    public void setContext(ActionBeanContext context) {
        this.context = context;
    }

    public void setOrder(Order order) {
        this.order = order;
    }

    public String getOrder() {
        return order;
    }

    @DefaultHandler
    public Resolution view() {
        return new ForwardResolution(“/WEB-INF/jsp/order.jsp”);
    }
}

视图 (order.jsp):强>

<html><body>
    Order id: ${actionBean.order.id}<br/>
    Order name: ${actionBean.order.name)<br/>
    Order total: ${actionBean.order.total)<br/>
</body></html>

模型(Order.java):

@Entity
public class Order implements Serializable {
    @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    private String name;
    private Integer total;

    public String getName() {
        return name;
    }

    public Integer getTotal() {
        return total;
    }   
}

顺便说一句,有一本关于 Stripes 的非常优秀的短书(!),涵盖了所有这些内容:

Stripes:...Java Web 开发再次变得有趣

A typical MVC design in Stripes would look like something like the code below.

The JPA entity is automaticaly loaded by a Stripes interceptor provided by Stripersist (but this can also easily implemented on your own if you wish). Thus in this example, requesting http://your.app/show-order-12.html will load a order with id 12 from the database and will show it on the page.

Controller (OrderAction.java):

@UrlBinding("/show-order-{order=}.html")
public class OrderAction implements ActionBean {
    private ActionBeanContext context;
    private Order order;

    public ActionBeanContext getContext() {
        return context;
    }

    public void setContext(ActionBeanContext context) {
        this.context = context;
    }

    public void setOrder(Order order) {
        this.order = order;
    }

    public String getOrder() {
        return order;
    }

    @DefaultHandler
    public Resolution view() {
        return new ForwardResolution(“/WEB-INF/jsp/order.jsp”);
    }
}

View (order.jsp):

<html><body>
    Order id: ${actionBean.order.id}<br/>
    Order name: ${actionBean.order.name)<br/>
    Order total: ${actionBean.order.total)<br/>
</body></html>

Model (Order.java):

@Entity
public class Order implements Serializable {
    @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    private String name;
    private Integer total;

    public String getName() {
        return name;
    }

    public Integer getTotal() {
        return total;
    }   
}

BTW there is an really excellent short(!) book on Stripes that covers all these things:

Stripes: ...and Java Web Development Is Fun Again

能否归途做我良人 2024-10-04 02:12:49

好吧,我已经弄清楚了。 页面中可用

添加到 HttpServletRequest(从上下文中检索)的属性在接收 ForwardRedirect IE 的
context.getRequest().setAttribute("attr1", "请求属性1");
返回新的 ForwardResolution("/WEB-INF/pages/hello.jsp");

在 hello.jsp 中
${attr1}
可用...耶!

Okay I have figured it out. Attributes added to the HttpServletRequest (retrieved from context) ARE available in the page receiving the ForwardRedirect

IE
context.getRequest().setAttribute("attr1", "request attribute 1");
return new ForwardResolution("/WEB-INF/pages/hello.jsp");

In hello.jsp
${attr1}
is available... yay!

累赘 2024-10-04 02:12:49

nopCommerce 3.20 (MVC) 有一个很好的解决方案。它是一个支付插件,支持授权、授权/捕获、退款和部分退款。包括 PCI 合规性,数据库上不存储 CC 信息
http://shop.wama-net.com/en/stripe - payment-plugin-for-nopcommerce

Jacky

There is on one nice solution for nopCommerce 3.20 (MVC). It's a payment plugin supporting, authorize, authorize/capture, refund and partially refund. PCI compliance included, no CC info is stored on db
http://shop.wama-net.com/en/stripe-payment-plugin-for-nopcommerce

Jacky

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文