81,091
社区成员
发帖
与我相关
我的任务
分享
/**
* 投票内容
*
* @author Tan
*
*/
public class vote_subject {
private Integer vs_id;
private String vs_title;
private Integer vs_type;
private Set<vote_option> options = new HashSet<vote_option>();
public vote_subject() {
}
public vote_subject(Integer vs_id, String vs_title, int vs_type) {
this.vs_id = vs_id;
this.vs_title = vs_title;
this.vs_type = vs_type;
}
/**
*
* @return ID
*/
public Integer getVs_id() {
return vs_id;
}
public void setVs_id(Integer vs_id) {
this.vs_id = vs_id;
}
/**
*
*
* @return 投票内容
*/
public String getVs_title() {
return vs_title;
}
public void setVs_title(String vs_title) {
this.vs_title = vs_title;
}
/**
*
*
* @return 投票类型
*/
public Integer getVs_type() {
return vs_type;
}
public void setVs_type(Integer vs_type) {
//投票类型 1:单选 2:多选 默认:1
if (vs_type == 1 || vs_type == 2) {
this.vs_type = vs_type;
}else{
vs_type=1;
}
}
/**
*
* @return
*/
public Set<vote_option> getOptions() {
return options;
}
public void setOptions(Set<vote_option> options) {
this.options = options;
}
public class vote_option {
private Integer vo_id;
private String vo_option;
private vote_subject vs_id;
private String vo_order;
public vote_option() {
}
public vote_option(Integer vo_id, String vo_option, vote_subject vs_id,
String vo_order) {
this.vo_id = vo_id;
this.vo_option = vo_option;
this.vs_id = vs_id;
this.vo_order = vo_order;
}
/**
*
* @return ID
*/
public Integer getVo_id() {
return vo_id;
}
public void setVo_id(Integer vo_id) {
this.vo_id = vo_id;
}
/**
* 投票选项
* @return
*/
public String getVo_option() {
return vo_option;
}
public void setVo_option(String vo_option) {
this.vo_option = vo_option;
}
/**
* 投票内容ID
* @return
*/
public vote_subject getVs_id() {
return vs_id;
}
public void setVs_id(vote_subject vs_id) {
this.vs_id = vs_id;
}
/**
* 显示顺序
* @return
*/
public String getVo_order() {
return vo_order;
}
public void setVo_order(String vo_order) {
this.vo_order = vo_order;
}
public class vote_subjectAction extends ActionSupport {
private vote_subject subject = new vote_subject(); // 投票
private String[] options; //选项
public String[] getOptions() {
return options;
}
public void setOptions(String[] options) {
this.options = options;
}
/* 实例化*/
private vote_subjectServicesDao sdao = new vote_subjectServicesDaoImpl();
public vote_subject getSubject() {
return subject;
}
public void setSubject(vote_subject subject) {
this.subject = subject;
}
/**
* 添加投票
*
* @return
* @throws Exception
*/
public String save() throws Exception {
//选项
String[] order={"A","B","C","D","E","F"};
try {
for(int i=0;i<this.options.length;i++){
vote_option op = new vote_option();
op.setVo_option(this.options[i]);/*选项*/
op.setVo_order(order[i]); /*排序*/
op.setVs_id(this.subject);
this.subject.getOptions().add(op);
sdao.save(this.subject);
}
return SUCCESS;
} catch (Exception e) {
e.printStackTrace();
return ERROR;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.vote.entity.vote_subject" table="vote_subject">
<id name="vs_id" type="java.lang.Integer">
<column name="vs_id"></column>
<generator class="increment"></generator>
</id>
<property name="vs_title" type="java.lang.String">
<column name="vs_title"></column>
</property>
<property name="vs_type" type="java.lang.Integer">
<column name="vs_type"></column>
</property>
<set name="options" table="vote_option" cascade="all" lazy="false" inverse="false">
<key>
<column name="vs_id"></column>
</key>
<one-to-many class="com.vote.entity.vote_subject"/>
</set>
</class>
</hibernate-mapping>
’
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.vote.entity.vote_option" table="vote_option">
<id name="vo_id" type="java.lang.Integer">
<column name="vo_id"></column>
<generator class="increment"></generator>
</id>
<property name="vo_option" type="java.lang.String">
<column name="vo_option"></column>
</property>
<many-to-one name="vs_id" class="com.vote.entity.vote_subject">
<column name="vs_id"></column>
</many-to-one>
<property name="vo_order" type="java.lang.String">
<column name="vo_order"></column>
</property>
</class>
</hibernate-mapping>