hibernate中数组如何对应到数据库中

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/fancylovejava/article/details/7583127

public class POJO implements java.io.Serializable { private String[] strs; public String[] getStrs() { return strs; } public void setStrs(String[] strs) { this.strs = strs; }}



为什么不换种思维?

Java code
public class POJO implements java.io.Serializable { private Integer id; private String strs; public Integer getId(){ return id; } public void setId(Integer id){ this.id = id; } public String getStrs() { return strs; } public void setStrs(String strs) { this.strs = strs; } } //hbm.xml,假设POJO类路径为com.csdn.bean.POJO <?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"> <!-- Mapping file autogenerated by MyEclipse Persistence Tools --> <hibernate-mapping> <class name="com.csdn.bean.POJO" table="pojo"> <id name="id" type="integer"> <column name="ID" /> <generator class="increment" /> </id> <property name="strval" type="string"> <column name="field_strval" not-null="true"/> </property> </class> </hibernate-mapping>


当要使用strs时:
String strs = pojo.getStrs();
String[] result = strs.split(",");
展开阅读全文

没有更多推荐了,返回首页