primefaces_Primefaces,Hibernate和SpringRoo集成

primefaces

SpringRoo is an open source software tool that uses convention-over-configuration concept to facilitate producing Java-Based enterprise software application in a driven command-line way. We’ve introduced set of tutorials that get you around creating an enterprise application. Primefaces, Spring Framework, Hibernate, EclipseLink and a different kinds of data stores are combined selectively to help you creating an enterprise application.

SpringRoo是一个开源软件工具,它使用基于约定的约定概念来促进以驱动命令行方式生成基于Java的企业软件应用程序。 我们介绍了一系列教程,可帮助您围绕创建企业应用程序的过程。 PrimefacesSpring FrameworkHibernate ,EclipseLink和其他类型的数据存储被有选择地组合在一起,以帮助您创建企业应用程序。

This tutorial is different, that is you won’t develop any layers you’ve got developed before. Everything would be assigned for SpringRoo and you will learn the required integration and commands that help you get your first application installed and running.

本教程与众不同,即您不会开发以前开发的任何层。 一切都将分配给SpringRoo,您将学习所需的集成和命令,以帮助您安装和运行第一个应用程序。

最终项目结构 (Final Project Structure)

必备工具 (Required Tools)

  • SpringRoo 1.2.5

    SpringRoo 1.2.5
  • JDK 1.6+

    JDK 1.6以上
  • Apache Tomcat 7

    Apache Tomcat 7
  • Maven 2+

    Maven 2+
  • Eclipse Kepler 4.3

    Eclipse开普勒4.3
  • MySQL 5.x

    MySQL 5.x

Eclipse Spring Roo集成 (Eclipse Spring Roo Integration)

To integrate your Eclipse IDE with a SpringRoo software you have to follow below steps carefully:

要将您的Eclipse IDE与SpringRoo软件集成,您必须仔细遵循以下步骤:

  • Download SpringRoo software into your local directory and unzip. For clarification purpose, we’ve unzipped it into D:\SpringRoo\spring-roo-1.2.5.RELEASE.

    SpringRoo软件下载到您的本地目录并解压缩。 为了澄清起见,我们将其解压缩到D:\ SpringRoo \ spring-roo-1.2.5.RELEASE中
  • Install SpringRoo plugin into your Eclipse IDE. This is can be done by going into Help – Install New Software and type this given https://dist.springsource.com/release/TOOLS/update/e4.3/ into your Work with address input.

    将SpringRoo插件安装到Eclipse IDE中。 可以通过进入“ 帮助-安装新软件”并在您的“使用地址输入的工作”中键入https://dist.springsource.com/release/TOOLS/update/e4.3/来完成此操作。
  • Check both of Core/Spring IDE and Extensions / Spring IDE.

    检查Core / Spring IDEExtensions / Spring IDE
  •   Click Next and finish and wait till the installation process finished.

    单击下一步,然后完成,直到安装过程完成。
  • Make sure you are restarted your Eclipse IDE. In case you’ve installed Spring Roo successfully, then you are about getting welcome screen like below.

    确保您重新启动了Eclipse IDE。 如果您已经成功安装了Spring Roo,那么您将获得如下所示的欢迎屏幕。
  • From Project Explorer, create a new Project and select Spring Roo Project.

    在Project Explorer中,创建一个新项目,然后选择Spring Roo Project
  • Click next and type Primefaces-SpringRoo-Hibernate-Sample into Project name. Name your Top level package name and make sure your Project type is standard.

    单击下一步,然后在项目名称中键入Primefaces-SpringRoo-Hibernate-Sample 。 命名您的顶级包名称 ,并确保您的项目类型是标准的。
  • Click on Configure Roo Installations and Add your downloaded Spring Roo library.

    单击“ 配置Roo安装”,然后添加您下载的Spring Roo库。
  • Make sure you are selecting a WAR packaging way. Click next and Finish. SpringRoo will start building up your Project using the information you provide.

    确保选择WAR包装方式。 单击下一步,然后单击完成。 SpringRoo将使用您提供的信息开始构建您的项目。
  • Once SpringRoo Project created, you must notice that a SpringRoo Shell Command – Plugin Shell – is opened. In case you’ve faced some obstacles in getting it started and ready, just restart your eclipse and activate the SpringRoo shell once again by clicking on Open Roo Shell for projects.

    创建SpringRoo项目后,您必须注意,已打开SpringRoo Shell命令–插件外壳–。 如果您在启动和准备过程中遇到了一些障碍,只需重新启动Eclipse并通过单击Open Roo Shell for projects再次激活SpringRoo Shell
  • Now, you are ready to start building up your project.

    现在,您准备开始构建项目。

数据库视图 (Database View)

SpringRoo has facilitated a known paradigm for getting your JPA entities ready for use at a glance. Your Database’s Tables can be reversed engineered in order to eliminate the need of getting additional commands executed. So let’s see what’s the business Tables we’re truly want to implement.

SpringRoo促进了一种已知的范例,使您的JPA实体一目了然地可以使用。 您可以对数据库的表进行反向工程,以消除执行其他命令的需要。 因此,让我们看看我们真正想要实现的业务表是什么。

In general, we have two Tables; Employee and Phone which are associated in a One-To-Many association type. Phone Table contains a foreign key refers employeeId field in Employee Table. Following below required SQL create scripts.

总的来说,我们有两个表。 以一对多关联类型关联的Employee和Phone。 电话表在雇员表中包含一个外键引用的EmployeeId字段。 以下是必需SQL创建脚本。

EmployeeTable.sql

EmployeeTable.sql

CREATE TABLE `employee` (
  `EMP_ID` int(11) NOT NULL AUTO_INCREMENT,
  `EMP_NAME` varchar(45) DEFAULT NULL,
  `EMP_HIRE_DATE` varchar(30) DEFAULT NULL,
  `EMP_SALARY` decimal(11,4) DEFAULT NULL,
  PRIMARY KEY (`EMP_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8;

PhoneTable.sql

PhoneTable.sql

CREATE TABLE `phone` (
  `PH_ID` int(11) NOT NULL AUTO_INCREMENT,
  `PH_NO` varchar(30) DEFAULT NULL,
  `EMP_ID` int(11) DEFAULT NULL,
  PRIMARY KEY (`PH_ID`),
  KEY `PH_EMP_ID_idx` (`EMP_ID`),
  CONSTRAINT `PH_EMP_ID` FOREIGN KEY (`EMP_ID`) REFERENCES `employee` (`EMP_ID`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

开发SpringRoo应用程序 (Developing SpringRoo Application)

Developing an enterprise application using a SpringRoo software does contain executing of more than one command against SpringRoo shell. Following a clarified steps for creating wanted application.

使用SpringRoo软件开发企业应用程序确实包含对SpringRoo Shell执行多个命令。 按照明确的步骤创建所需的应用程序。

  • Setup used persistence framework by executing persistence setup --database MYSQL --provider HIBERNATE --hostName localhost --userName root --password root --databaseName journaldev --persistenceUnit hibernate.jpa

    安装程序通过执行persistence setup --database MYSQL --provider HIBERNATE --hostName localhost --userName root --password root --databaseName journaldev --persistenceUnit hibernate.jpa来使用持久性框架- persistence setup --database MYSQL --provider HIBERNATE --hostName localhost --userName root --password root --databaseName journaldev --persistenceUnit hibernate.jpa
  • Install MySQL driver, that would help your SpringRoo software to load the required driver when the process of reverse engineering get started. We have a MySQL driver located on D:\mysql-connector-java-5.1.18-bin.jar. Executing of osgi install --url file:\\\D:\mysql-connector-java-5.1.18-bin.jar would be fair enough. In case you’ve missed out executing this instruction you will get JDBC driver not available for ‘com.mysql.jdbc.Driver’ message when it comes to connect your MySQL database for reverse engineering phase.

    安装MySQL驱动程序,这将在逆向工程开始时帮助您的SpringRoo软件加载所需的驱动程序。 我们在D:\ mysql-connector-java-5.1.18-bin.jar上有一个MySQL驱动程序。 执行osgi install --url file:\\\D:\mysql-connector-java-5.1.18-bin.jar就足够了。 如果您错过了执行该指令的时间 ,则在连接MySQL数据库进行逆向工程阶段时,您将获得JDBC驱动程序,不适用于'com.mysql.jdbc.Driver'消息。
  • Create JPA entities, SpringRoo provides you an easy way to create your entities. By executing database reverse engineer --schema journaldev  --package ~.jpa.data --disableVersionFields --activeRecord true --disableGeneratedIdentifiers SpringRoo will scan your database and creating the entities by reversing defined Tables there.

    创建JPA实体,SpringRoo为您提供了一种创建实体的简便方法。 通过执行database reverse engineer --schema journaldev --package ~.jpa.data --disableVersionFields --activeRecord true --disableGeneratedIdentifiers SpringRoo将扫描您的数据库并通过反转定义的表来创建实体。
  • Create Primefaces Web layer, one of the options that SpringRoo provides is creating the presentation layer using a JSF implementation. Executing of web jsf setup --implementation ORACLE_MOJARRA --library PRIMEFACES --theme BLUESKY will create all required files for your presentation tier including of required forms like: Employee Registration, Phone Registration, Manage Employees and Manage Phones.

    创建Primefaces Web层,SpringRoo提供的选项之一是使用JSF实现创建表示层。 执行web jsf setup --implementation ORACLE_MOJARRA --library PRIMEFACES --theme BLUESKY将为您的演示文稿层创建所有必需的文件,包括所需的形式,例如:员工注册,电话注册,管理员工和管理电话。
  • Create all web stuffs, including utilities beans, required managed beans, converters, messages etc. Executing of web jsf all --package ~.web will help you create all of these stuffs.

    创建所有Web东西,包括实用程序Bean,必需的托管Bean,转换器,消息等。执行web jsf all --package ~.web将帮助您创建所有这些东西。
  • For avoiding identifier generation exception, open Employee_Roo_Jpa_Entity.aj and Phone_Roo_Jpa_Entity.aj using Eclipse CTRL+SHIFT+R like below:

    为避免标识符生成异常, 使用Eclipse CTRL + SHIFT + R如下所示打开Employee_Roo_Jpa_Entity.ajPhone_Roo_Jpa_Entity.aj
  • Add @GeneratedValue(strategy=GenerationType.Auto) annotation onto both of Employee’s identifier and Phone’s identifier.

    @GeneratedValue(strategy = GenerationType.Auto)批注添加到Employee的标识符和Phone的标识符上。

Employee_Roo_Jpa_Entity.aj

Employee_Roo_Jpa_Entity.aj

// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
// You may push code into the target .java compilation unit if you wish to edit any member(s).

package com.journaldev.jpa.data;

import com.journaldev.jpa.data.Employee;

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

privileged aspect Employee_Roo_Jpa_Entity {
    
    declare @type: Employee: @Entity;
    
    declare @type: Employee: @Table(name = "employee");
    
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name = "EMP_ID")
    private Integer Employee.empId;
    
    public Integer Employee.getEmpId() {
        return this.empId;
    }
    
    public void Employee.setEmpId(Integer id) {
        this.empId = id;
    }
}

Phone_Roo_Jpa_Entity.aj

Phone_Roo_Jpa_Entity.aj

// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
// You may push code into the target .java compilation unit if you wish to edit any member(s).

package com.journaldev.jpa.data;

import com.journaldev.jpa.data.Phone;

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

privileged aspect Phone_Roo_Jpa_Entity {
    
    declare @type: Phone: @Entity;
    
    declare @type: Phone: @Table(name = "phone");
    
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name = "PH_ID")
    private Integer Phone.phId;
    
    public Integer Phone.getPhId() {
        return this.phId;
    }
    
    public void Phone.setPhId(Integer id) {
        this.phId = id;
    }   
}
  • Execute mvn clean package in order to generate some Java files required by SpringRoo AspectJ does generates and to generate the required WAR for next coming deployment task.

    执行mvn clean软件包 ,以生成SpringRoo AspectJ确实生成的一些Java文件,并生成下一个部署任务所需的WAR。
  • Copy your generated WAR file into Apache Tomcat home/webapp folder.

    将生成的WAR文件复制到Apache Tomcat home / webapp文件夹中。
  • Start up your Apache Tomcat and type the given URL that’s shown below.

    启动您的Apache Tomcat,然后输入如下所示的给定URL。

演示版 (Demo)

Now, you have started your Apache Tomcat and you are staying on the home page for the SpringRoo application. As you’ve noticed, four forms are developed automatically; Create Employee, Create Phone, List All Employees and List All Phones. Let’s take a look before getting started creating new employees and phones.

现在,您已经启动了Apache Tomcat,并且停留在SpringRoo应用程序的主页上。 正如您所注意到的,将自动开发四种形式。 创建员工,创建电话,列出所有员工和列出所有电话。 在开始创建新员工和电话之前,让我们看一下。

持续记录 (Persisted Records)

Now, let’s see the records that are persisted into your MySQL database.

现在,让我们看看保存在MySQL数据库中的记录。

摘要 (Summary)

SpringRoo has used for Rapid Application Development (RAD), it’s used conventionally for developing an enterprise application in which a Hibernate is the persistence layer and the Primefaces is the presentation layer. Contribute us by commenting below and find downloaded source code.

SpringRoo已用于快速应用程序开发(RAD),通常用于开发企业应用程序,其中Hibernate是持久性层,而Primefaces是表示层。 通过在下面评论来贡献我们,并找到下载的源代码。

翻译自: https://www.journaldev.com/4260/primefaces-hibernate-and-springroo-integration

primefaces

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值