English 中文(简体)
在春天将物体用作请求Param的简单方式
原标题:Simplest way to use composed object as RequestParam in Spring
  • 时间:2012-01-11 11:50:18
  •  标签:
  • spring-mvc

下面是......假守则...... 说明我所期待的:

// Setters and Getters ommitted to keep the example short here:
class Address
{
  private String street;
  private String city;
}

class AddressBookEntry
{
  private String name;
  private Address address;
}

class MyController
{
  public void render(@RenderParam AddressBookEntry entry)
  {
    ...
  }
}

各位可以看到,有两家公共汽车公司(地址和地址BookEntry)。 现在,我要把地址BookEntry作为请求参数送交我的主计长。 我想,URL看上去:/target?enter.name=Random-Guy&enter.address.street=Random-Street&enter.address.city=Random-City

就我所知,@RenderParam没有这样做。 我必须创建一名财产管理人,采取单一举动和构建我的目标。 反对意见,这意味着我每个(次)财产都有一个单独的URL部分。

@ModelAttribute比较接近,但我无法发现,如果和如何将物体放入与这一说明合作的话。 此外,这一说明没有“在我前面的《URL》中预先确定,这意味着我需要确保我不会有多个《示范Attributes分享财产名称,这是正确的吗? 这种压力是巨大的。

我如何解决这一问题?

最佳回答

它描述了你使用<代码>@ModelAttribute的情况。 它支持你想要的nes子。

如果您需要多个<代码>@ModelAttribute,你可以将其编成特殊类别(例如,你的情况是,类别中可以包含一个名为<代码>的栏目的栏目<>代码>的栏目/code>的栏目,因此参数名称不变)。

问题回答

暂无回答




相关问题
multi-staged form using spring

please forgive me for this stupid questions. I just started developing web application using spring yesterday. The project that i worked on, have a multi staged form, that require users to complete ...

Rewrite spring-security redirect URLs

I m trying to get Tuckey UrlRewriteFilter to tidy up URLs for my webapp. One problem I ve got is that when spring-security notices that an anonymous user is trying to access a protected resource it ...

Spring Advice - submitting a form

I am having serious problems with code I have written with Spring so I have decided to start from scratch and ask for advice. Here are my requirements: When the page first loads I need a list of ...

How to implement Logout feature using Spring Web Mvc

I am new to Spring Web MVC.. Can I get some example or online link that shows me how to implement logout feature using spring web mvc ? I don t want to use the in built feature of spring security (i....

Exception thrown after processing onSubmitAction

I am very new to Spring and I have a simpleFormController with 2 methods. referenceData() with is called when the page loads and onSubmitAction() which is called on the submit of a form. I am ...

热门标签