我还是SpringMVC的新手(和jstl一样).我正在尝试从对象列表中选择一个选项.我已经找到了一种方法来使用c:forEach,但我一直认为有一种方法可以使表单:选项方法工作.
我浏览了一下,关于items属性的官方文档中我能找到的最接近的东西是>> http://static.springsource.org/spring/docs/2.0.x/reference/spring-form.tld的.html#弹簧form.tld.options
它表示items属性适用于
"用于生成内部'选项'标签的集合,地图或对象数组"
我的困惑是它正在寻找什么样的Collection,Map或对象数组.他们需要采用什么格式?它是否专门寻找String类型的Collection或数组?我可以用吗
List<MyObject>
Run Code Online (Sandbox Code Playgroud)
如果是这样,MyObject必须拥有什么才能使它有效(即方法,变量)?
目前,当我尝试使用MyObject时,我得到一个例外,说 -
ConverterNotFoundException:找不到能够从类型com.example.MyObject转换为java.lang.String类型的转换器
我需要制作转换器吗?那会怎么样?那会怎么样?我用谷歌搜索了这个错误信息,并没有真正发现任何特定于我正在尝试做的事情...(大多数是关于Roo的结果)
MyObject类如下所示:
public class MyObject{
private String company;
private Customer customer;
private Address customerAddress;
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public Address getCustomerAddress() {
return customerAddress;
}
public void setCustomerAddress(Address customerAddress) {
this.customerAddress = customerAddress;
}
}
Run Code Online (Sandbox Code Playgroud)
而我正试图这样使用它:
<form:select path="myObjectList">
<form:option value="0"/>
<form:options …Run Code Online (Sandbox Code Playgroud) 我有一个 XMLGregorianCalendar 对象,我正在尝试将其封送到 xml 字符串中。我通过解组另一个 xml 对象收到了这个对象。两者都是“dateTime”类型,所以它们应该完全相同......
然而,当我对其进行封送时,它在 xml 中显示为空白。
为了说明这个问题,我将所有内容都剥离到了最基本的部分,并在此处的示例中使其通用。2个java文件,复制,粘贴,按原样运行。您应该收到的输出是:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TheObject>
<DOB>2016-09-16</DOB>
</TheObject>
Run Code Online (Sandbox Code Playgroud)
但是,唉,它返回:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TheObject>
<DOB></DOB>
</TheObject>
Run Code Online (Sandbox Code Playgroud)
注意:在 Pastebin 示例中,我动态创建一个 xmlGregorianCalendar,而不是像下面的代码那样从另一个对象中获取一个 xmlGregorianCalendar,因此从技术上讲,这不是同一件事,但我认为最终它说明了完全相同的问题...请纠正我我错了...
要为我的具体问题添加更多背景信息:
//Here are the objects themselves (names changed to protect the innocent)
//complete with annotations...
public class Object1{
...
@XmlElement(name = "DOB")
@XmlSchemaType(name = "dateTime")
protected XMLGregorianCalendar dob;
...
}
public class Object2{
...
@XmlElement(name = "DOB")
@XmlSchemaType(name = "dateTime")
protected XMLGregorianCalendar dob;
...
}
//and …Run Code Online (Sandbox Code Playgroud) 也许我只是在理解php如何处理数组时遇到了麻烦.
我正在尝试使用foreach循环打印出一个数组.我似乎可以摆脱它的是"阵列"这个词.
<?php
$someArray[]=array('1','2','3','4','5','6','7'); // size 7
foreach($someArray as $value){
echo $value;
?>
<br />
<?php
}
?>
Run Code Online (Sandbox Code Playgroud)
这打印出来:
Array
Run Code Online (Sandbox Code Playgroud)
我无法理解为什么会出现这种情况.如果我像上面那样在前面定义一个数组,那么它将打印"Array".我似乎必须手动定义所有内容......这意味着我必须做错事.
这有效:
<?php
$someArray[0] = '1';
$someArray[1] = '2';
$someArray[2] = '3';
$someArray[3] = '4';
$someArray[4] = '5';
$someArray[5] = '6';
$someArray[6] = '7';
for($i=0; $i<7; $i++){
echo $someArray[$i]."<br />";
}
?>
Run Code Online (Sandbox Code Playgroud)
为什么foreach不工作?
这是一个链接,可以看到它在行动>> http://phpclass.hylianux.com/test.php