Spring:在java类和populateDatabase中声明变量XML

时间:2017-02-01 12:31:32

标签: java xml spring spring-mvc

我想在我的域模型中引入一个String变量。变量的内容将是一个xml文本,这就是问题出现的地方。

我想在我的Bpmsn类中输入字符串变量:

@Entity
@Access(AccessType.PROPERTY)
public class Bpmsn extends DomainEntity {

// Attributes ---------------------------------------------------------
private String ticker;
private String title;
private String summary;
private Date authoredMoment;
private boolean public_;
private int likes;      //Derived
private int dislikes;   //Derived


@NotBlank
@NotNull
@Pattern(regexp = "^(\\d{6})\\-([a-zA-Z]{4})$")
@Column(unique=true)
@SafeHtml
public String getTicker() {
    return ticker;
}

public void setTicker(String ticker) {
    this.ticker = ticker;
}

@NotBlank
@NotNull
@SafeHtml
public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

@NotBlank
@NotNull
@SafeHtml
public String getSummary() {
    return summary;
}

public void setSummary(String summary) {
    this.summary = summary;
}

@NotNull
@Past
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(pattern="dd/MM/yyyy HH:mm")
public Date getAuthoredMoment() {
    return authoredMoment;
}

public void setAuthoredMoment(Date authoredMoment) {
    this.authoredMoment = authoredMoment;
}

public boolean getIsPublic_() {
    return public_;
}

public void setIsPublic_(boolean public_) {
    this.public_ = public_;
}

@Min(0)
public int getLikes() {
    return likes;
}
public void setLikes(int likes){
    this.likes = likes;
}

@Min(0)
public int getDislikes() {
    return dislikes;
}
public void setDislikes(int dislikes){
    this.dislikes = dislikes;
}

第一个问题是我是否需要@XML类型的任何注释....

private String textXML;

public String getTextXML() {
  return textXML;
}

public void setTextXML(String textXML) {
  this.textXML = textXML;
}

完成此操作后,我需要在数据库中输入一些数据来进行测试。 为此,我使用Spring提供的PopulateDatabase.xml文件。我的另一个问题是如何在PopulateDatabase.xml文件中声明一个带有xml文本的String属性,如下所示:

<bean id="bpmsn1" class="domain.Bpmsn">
    <property name="ticker" value="161018-aaaa" />
    <property name="title" value="Test" />
    <property name="summary" value="Testeando un poco" />
    <property name="authoredMoment" value="10/18/2016 13:45" />
    <property name="likes" value="2" />
    <property name="dislikes" value="0" />
    <property name="user" ref="user1" />
    <property name="isPublic_" value="true" />
    <property name="opinions">
        <list>
            <ref bean="opinion1" />
            <ref bean="opinion2" />
        </list>
    </property>
    <property name="comments">
        <list>
            <ref bean="comment2" />
        </list>
    </property>
</bean>

这是怎么回事

<property name="textXML" value="
  <?xml%20version='1.0'%20encoding='UTF-8'?>
  <note>
   <to>Tove</to>
   <from>Jani</from>
   <heading>Reminder</heading>
   <body>Don't forget me this weekend!</body>
  </note>
 ">

0 个答案:

没有答案