appfuse2-eclips开发-建立新表(2)

1.完成eclips开发-建立新表(1)后,开始新建表。基本流程是建立POJO,然后自动生成数据库,生成DAO,CRUD等资源文件。

2.在src/main/java/**/model 下建立POJO类。

package com.kaxu.app.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "app_person")
public class Person extends BaseObject implements Serializable {

 private Long id;
 private String firstName;
 private String lastName;

 public void setId(Long id) {
  this.id = id;
 }

 public void setFirstName(String firstName) {
  this.firstName = firstName;
 }

 public void setLastName(String lastName) {
  this.lastName = lastName;
 }

 @Id
 @GeneratedValue(strategy = GenerationType.AUTO)
 public Long getId() {
  return id;
 }

 @Column(name = "first_name", length = 50)
 public String getFirstName() {
  return firstName;
 }

 @Column(name = "last_name", length = 50)
 public String getLastName() {
  return lastName;
 }

 @Override
 public boolean equals(Object o) {
  // TODO Auto-generated method stub
  return false;
 }

 @Override
 public int hashCode() {
  // TODO Auto-generated method stub
  return 0;
 }

 @Override
 public String toString() {
  // TODO Auto-generated method stub
  return null;
 }

}

3.打开src/main/resources/hibernate.cfg.xml增加一行:

<mapping class="&amp;lt;span"></mapping>"org.appfuse.tutorial.model.Person"/>
"org.appfuse.tutorial"根据你的工程来定。
再执行命令  mvn test-compile hibernate3:hbm2ddl

已经成功在数据库生成新表。

4.输入命令:

mvn appfuse:gen

输入Person,已经生成了相关的资源文件

mvn appfuse:install -Dentity=Person

mvn jetty:run-war

地址栏输入http://localhost:8080将看到


你可能感兴趣的:(DAO,xml,Hibernate,Appfuse)