zoukankan      html  css  js  c++  java
  • 实战3--设计管理模块, 第一步: 设计实体类和表

    1. 设计实体类/表

    2. 分析有几个功能, 对应几个请求

    3. 实现功能

        1. 写action

        2. 写service

        3. 写Dao

        4. 写jsp

    1. 先设计岗位类Role

        建实体类--> hbm.xml-->建表  (创建sessionFactory)  

    package cn.itcast.oa.domain;
    
    public class Role {
    	private Long id;
    	private String name;
    	private String description;
    	
    	public Long getId() {
    		return id;
    	}
    	public String getName() {
    		return name;
    	}
    	public String getDescription() {
    		return description;
    	}
    	public void setId(Long id) {
    		this.id = id;
    	}
    	public void setName(String name) {
    		this.name = name;
    	}
    	public void setDescription(String description) {
    		this.description = description;
    	}		
    }
    

    2. Role.hbm.xml:

        

    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
            "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
            "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    
    <hibernate-mapping package="cn.itcast.oa.domain">
    	<class name="Role" table="itcast_role">
    		<id name="id">
    			<generator class="native"></generator>
    		</id>
    		<property name="name" />
    		<property name="description" />
    	</class>
    </hibernate-mapping>
    

    3. hibernate.cfg.xml:

    <?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">
    <hibernate-configuration>
    	<session-factory>
    		<!-- Database connection settings -->
    		<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    					
    		<!-- 2. other configuration -->
    		<property name="show_sql">true</property>
    		<property name="hbm2ddl.auto">update</property>
    		<property name="connection.pool_size">1</property>
    
    		<!--3. mapping -->
    		<mapping resource="cn/itcast/oa/domain/User.hbm.xml" />
    		<mapping resource="cn/itcast/oa/domain/Role.hbm.xml" />		
    	</session-factory>
    </hibernate-configuration>
    

    4. 测试数据表有没有新建, 数据表在新建sessionFactory的时候创建:

     

    package cn.itcast.oa.test;
    
    import org.hibernate.SessionFactory;
    import org.junit.Test;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    public class SpringTest {
    	private ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
    	@Test
    	public void testSessionFactory() throws Exception{
    		SessionFactory sessionFactory = (SessionFactory)ac.getBean("sessionFactory");
    		System.out.println(sessionFactory);
    		
    	}
    	
    }
    

    然后去数据库检查表有没有生成

     

     

  • 相关阅读:
    ssh端口转发
    linux git命令安装
    linux git命令
    linux cpio命令
    linux 抓包工具
    js 深拷贝 ,浅拷贝
    vue $router 打开新窗口
    excel常用操作
    Kafka Topic的增删改查操作
    linux上删除文件名乱码的文件
  • 原文地址:https://www.cnblogs.com/wujixing/p/5497380.html
Copyright © 2011-2022 走看看