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);
    		
    	}
    	
    }
    

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

     

     

  • 相关阅读:
    dajngo 访问静态资源 图片
    springboot Shiro
    Jmeter集合点(线程组和同步定时器)
    Jmeter中的线程租的参数讲解
    人工智能必备数学知识学习笔记9:初等矩阵和矩阵的可逆性
    人工智能必备数学知识学习笔记8:线性系统
    在 web 中 后台 推送消息 页面 的消息提醒 注意
    web页面实现文件下载的几种方式
    ant desgin pro 的表格组件中的 使用 之自动刷新
    ant desgin 项目中 弹框modlel 模态框中展示 form 表单 将 form 表单 的提交按钮 关联到 模态框的 确定按钮上 在hook的写法中 在 class 的组件中 要加上 this
  • 原文地址:https://www.cnblogs.com/wujixing/p/5497380.html
Copyright © 2011-2022 走看看