制作一个化妆品网站(三)(bean制作和hbm.xml配置)

之前做了一些基础准备,设计了一下数据库,之后就开始制作bean,编写hbm.xml了

首先创建一个web项目,用的是web3.1    java1.8

之后导jar包,关于环境之间已经介绍过了,我就不在赘述了

创建bean:我按数据库设计的模块,放在不同的package下了,方便使用

 

Entity.java是接口,所有bean需要实现,方便之后的dao层编写

  1. Entity.java
  2.  
  3. public interface Entity {
  4.     public abstract Long getId();
  5.     public abstract void setId(Long long1);
  6. }

 

QueryBuilder.java用于分页查询,在dao层会用到

  1. QueryBuilder.java
  2.  
  3. public class QueryBuilder {
  4.     // 是否查询一列 true:查询全部 false:查询alias的值
  5.     public boolean countMode = true;
  6.     // 查询列名
  7.     public String alias = null;
  8.     // 查询表名
  9.     public String tableName = null;
  10.     // 是否排序   true:排序 false:不排序
  11.     public boolean orderMode = false;
  12.     // 排序字段
  13.     public String orderColimn = null;
  14.     // 升序ASC 降序DESC
  15.     public String orderSort = null;
  16.     // public final String ORDER_ASC = "ASC";
  17.     // public final String ORDER_DESC = "DESC";
  18.     // 是否分页    true:分页    false:不分页
  19.     public boolean pageMode = false;
  20.     // 查询条数 第一条 最后一条
  21.     public int firstResult = -1;
  22.     public int lastResult = -1;
  23.     public boolean getCountMode() {
  24.         return countMode;
  25.     }
  26.     public void setCountMode(boolean countMode) {
  27.         this.countMode = countMode;
  28.     }
  29.     public String getAlias() {
  30.         return alias;
  31.     }
  32.     public void setAlias(String alias) {
  33.         this.alias = alias;
  34.     }
  35.     public String getTableName() {
  36.         return tableName;
  37.     }
  38.     public void setTableName(String tableName) {
  39.         this.tableName = tableName;
  40.     }
  41.     public String getOrderColimn() {
  42.         return orderColimn;
  43.     }
  44.     public void setOrderColimn(String orderColimn) {
  45.         this.orderColimn = orderColimn;
  46.     }
  47.     public boolean isPageMode() {
  48.         return pageMode;
  49.     }
  50.     public void setPageMode(boolean pageMode) {
  51.         this.pageMode = pageMode;
  52.     }
  53.     public int getFirstResult() {
  54.         return firstResult;
  55.     }
  56.     public void setFirstResult(int firstResult) {
  57.         this.firstResult = firstResult;
  58.     }
  59.     public int getLastResult() {
  60.         return lastResult;
  61.     }
  62.     public void setLastResult(int lastResult) {
  63.         this.lastResult = lastResult;
  64.     }
  65.     public boolean isOrderMode() {
  66.         return orderMode;
  67.     }
  68.     public void setOrderMode(boolean orderMode) {
  69.         this.orderMode = orderMode;
  70.     }
  71.     public String getOrderSort() {
  72.         return orderSort;
  73.     }
  74.     public void setOrderSort(String orderSort) {
  75.         this.orderSort = orderSort;
  76.     }
  77. }
     

然后编写hbm.xml

放一个出来看看吧  Cosmetics.hbm.xml

  1. Cosmetics.hbm.xml
  2.  
  3. <?xml version="1.0" encoding="UTF-8"?>
  4. <!DOCTYPE hibernate-mapping PUBLIC 
  5.     "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
  6.     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
  7. <hibernate-mapping>
  8.     <class name="com.ldz.model.cosmetic.Cosmetics" table="cosmetic_cosmetics">
  9.         <id name="id" column="id" length="10" type="java.lang.Long">
  10.             <generator class="native"></generator>
  11.         </id>
  12.         <property name="name" column="name" length="50" type="java.lang.String"></property>
  13.         <property name="describes" column="describes" length="500" type="java.lang.String"></property>
  14.         <property name="is_recommend" column="is_recommend" length="1" type="java.lang.Byte"></property>
  15.         
  16.         <many-to-one name="type" column="type_id" class="com.ldz.model.cosmetic.Type"></many-to-one>
  17.         <many-to-one name="function" column="function_id" class="com.ldz.model.cosmetic.Functions"></many-to-one>
  18.         <many-to-one name="result" column="result_id" class="com.ldz.model.test.Result"></many-to-one>
  19.         
  20.         <set name="imageSet" table="cosmetic_image">
  21.             <key column="cosmetics_id"></key>
  22.             <one-to-many class="com.ldz.model.cosmetic.Image"/>
  23.         </set>
  24.         <set name="commentSet" table="cosmetic_comment">
  25.             <key column="cosmetics_id"></key>
  26.             <one-to-many class="com.ldz.model.comment.Comment"/>
  27.         </set>
  28.     </class>
  29. </hibernate-mapping>

今天暂时就写到这里了,下次会写ssh框架的搭建了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值