posts - 2,comments - 0,trackbacks - 0
利用myeclipse的反向工程导入hibernate后,配置文件hibernate.cfg.xml放在src的根目录下,工程会自己加载:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"
>

<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>

<session-factory>
<property name="connection.username">root</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/shtest
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="myeclipse.connection.profile">mysql</property>
<property name="connection.password">fjtianxia</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<mapping resource="com/sh/entity/Manager.hbm.xml" />
</session-factory>

</hibernate-configuration>
<mapping resource="com/sh/entity/Manager.hbm.xml" />是寻找hbm.xml文件的路径映射,可以更改路径。
Manager.hbm.xml配置如下:
<?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.sh.entity.Manager" table="Manager">
<id name="manaId" type="java.lang.Integer">
<column name="ManaId" />
<generator class="native" />
</id>
<property name="manaName" type="java.lang.String">
<column name="ManaName" length="50" not-null="true" />
</property>
<property name="manaPass" type="java.lang.String">
<column name="ManaPass" length="50" not-null="true" />
</property>
<property name="manaEmail" type="java.lang.String">
<column name="ManaEmail" length="50" />
</property>
</class>
</hibernate-mapping>
实体类Manager.java:
package com.sh.entity;

public class Manager {
private Integer manaId;
private String manaName;
private String manaPass;
private String manaEmail;
public Integer getManaId() {
return manaId;
}
public void setManaId(Integer manaId) {
this.manaId = manaId;
}
public String getManaName() {
return manaName;
}
public void setManaName(String manaName) {
this.manaName = manaName;
}
public String getManaPass() {
return manaPass;
}
public void setManaPass(String manaPass) {
this.manaPass = manaPass;
}
public String getManaEmail() {
return manaEmail;
}
public void setManaEmail(String manaEmail) {
this.manaEmail = manaEmail;
}
}
下面就是我们执行的代码了,今天之弄过简单的获取数据列表的例子:
package com.sh.test;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import com.sh.entity.Manager;

public class test1 {
SessionFactory factory;
@SuppressWarnings(
"unchecked")
public List getAllManager(){
factory
= new Configuration().configure().buildSessionFactory();
Session session
=factory.openSession();
List
<Manager> l=new ArrayList<Manager>();
l
= session.createCriteria(Manager.class).list();
// session.save(m);
return l;
}
/**
*
@param args
*/
@SuppressWarnings(
"unchecked")
public static void main(String[] args) {
test1 t
=new test1();
t.getAllManager();
List
<Manager> l=new ArrayList<Manager>();
l
=t.getAllManager();
for(Manager m:l){
System.out.println(m.getManaName()
+"..."+m.getManaPass()+"..."+m.getManaEmail());
}
}

}
第一天就这样了,做个准备工作,搭建个成功的环境。
posted @ 2008-10-25 18:59 jestane 阅读(130) | 评论 (0)编辑 收藏
1.新闻列表显示.
2.后台管理新闻.
3.用户管理.

数据库分析:
Manager表:

中文名称 字段名 数据类型 默认值 备注
标识 ManaId int
用户名 ManaName varchar(50)
密码 ManaPass varchar(50)
邮箱 email varcahr(50) 注册激活发送密码
News表:
中文名称 字段名 数据类型 默认值 备注
标识 NewsId int
标题 NewsTitle varchar(100)
内容 NewsContent text
发表时间 NewsBirth date
分类 NewsClass int
作者 NewsAuthor varchar(50)
标签 NewsTag varchar(100)
访问次数 NewsVisitor int
NewsClass表:
中文名称 字段名 数据类型 默认值 备注
分类标识 ClassId int
分类名称 ClassName varchar(30)
Remark表:
中文名称 字段名 数据类型 默认值 备注
标识 RemarkID int
评论内容 RemarkContent varchar(500)
文章标识 NewsId int
文章评分 RemarkScore int

 




posted @ 2008-10-24 16:04 jestane 阅读(382) | 评论 (0)编辑 收藏
仅列出标题