在ssh框架中,根据JavaBean(实体类)在数据库中创建表

以下是我写好的一个实体类

/**
 * 虫害实体类
 * @author pc
 *
 */
@Entity
@Table(name="t_insect")
public class InsectBean {
    /**
     * 昆虫id
     */
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private int insectId;
    /**
     * 昆虫名称
     */
    private String insectName;
    /**
     * 繁殖
     */
    private String reproduction;
    /**
     * 寄主
     */
    private String hosts;
    /**
     * 天敌
     */
    private String naturalEnemy;
    /**
     * 主要危害
     */
    private String mainHarm;
    /**
     * 防治措施
     */
    private String preventMeasure;
    /**
     * 幼虫图片路径
     */
    private String imagoImgPath;
    /**
     * 成虫图片路径
     */
    private String larvaImgPath;
    public int getInsectId() {
        return insectId;
    }
    public void setInsectId(int insectId) {
        this.insectId = insectId;
    }
    public String getInsectName() {
        return insectName;
    }
    public void setInsectName(String insectName) {
        this.insectName = insectName;
    }

    public String getReproduction() {
        return reproduction;
    }
    public void setReproduction(String reproduction) {
        this.reproduction = reproduction;
    }
    public String getHosts() {
        return hosts;
    }
    public void setHosts(String hosts) {
        this.hosts = hosts;
    }
    public String getNaturalEnemy() {
        return naturalEnemy;
    }
    public void setNaturalEnemy(String naturalEnemy) {
        this.naturalEnemy = naturalEnemy;
    }
    public String getMainHarm() {
        return mainHarm;
    }
    public void setMainHarm(String mainHarm) {
        this.mainHarm = mainHarm;
    }
    public String getPreventMeasure() {
        return preventMeasure;
    }
    public void setPreventMeasure(String preventMeasure) {
        this.preventMeasure = preventMeasure;
    }
    public String getImagoImgPath() {
        return imagoImgPath;
    }
    public void setImagoImgPath(String imagoImgPath) {
        this.imagoImgPath = imagoImgPath;
    }
    public String getLarvaImgPath() {
        return larvaImgPath;
    }
    public void setLarvaImgPath(String larvaImgPath) {
        this.larvaImgPath = larvaImgPath;
    }
    public InsectBean() {
        super();
        // TODO Auto-generated constructor stub
    }
    public InsectBean(String insectName, String reproduction, String hosts,
            String naturalEnemy, String mainHarm, String preventMeasure,
            String imagoImgPath, String larvaImgPath) {
        super();
        this.insectName = insectName;
        this.reproduction = reproduction;
        this.hosts = hosts;
        this.naturalEnemy = naturalEnemy;
        this.mainHarm = mainHarm;
        this.preventMeasure = preventMeasure;
        this.imagoImgPath = imagoImgPath;
        this.larvaImgPath = larvaImgPath;
    }
    @Override
    public String toString() {
        return "InsectBean [reproduction=" + reproduction + ", hosts=" + hosts
                + ", imagoImgPath=" + imagoImgPath + ", insectId=" + insectId
                + ", insectName=" + insectName + ", larvaImgPath="
                + larvaImgPath + ", mainHarm=" + mainHarm + ", naturalEnemy="
                + naturalEnemy + ", preventMeasure=" + preventMeasure + "]";
    }

}

配置文件修改部分


    <bean id="sessionFactoty" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        
        <property name="dataSource" ref="data">property>
        
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialectprop>
                <prop key="hibernate.show_sql">trueprop>
                
                <prop key="hibernate.hbm2ddl.auto">createprop>
            props>
        property>
        
        <property name="packagesToScan">
            <list>
                <value>com.lovo.beanvalue>
            list>
        property>
    bean>

你可能感兴趣的:(开发经验)