Spring MVC+hibernate 开发系统(一)
来源:互联网 发布:matlab读取数据和文件 编辑:程序博客网 时间:2024/05/01 09:28
第一次写博客,不好之处见谅。
这篇文章主要讨论实际项目从系统设计到系统实现过程中涉及到的问题,因为项目用了很多企业开发公用的技术,所以用文字的形式记录分享给大家。本系统显示 Hibernate 的多对多实例,在 Spring MVC CRUD Web应用程序中连接表。我将同时讨论管理多对多关系在后端。 我们将使用应用程序的Web界面创建,更新,删除和查询。本系统是利用 Spring 的 org.springframework.core.convert.converter.Converter 接口,它帮助我们在项目的数据库中实现实体的映射标识。对于dao层的处理是使用hibernate完成基本Dao的封装;对于数据库的连接采用的是阿里巴巴druid连接池;系统中还增加了自定义异常类和工具类;同时为极大的提升开发效率,系统还利用了热加载技术。
使用以下技术:
- Spring 4.3.2.RELEASE
- Hibernate Core 4.3.10.Final
- validation-api 1.1.0.Final
- hibernate-validator 5.1.3.Final
- Oracle 11g
- Maven 3
- JDK 1.8
- Tomcat 7.0.21
- eclipse-jee-neon
- JRebel
- Log4j
- JUnit
- druid
第一步:环境搭建
Maven安装:Maven安装配置
SpringMVC +Hibernate开发环境搭建:SpringMVC +hibernate开发环境
Log4j安装配置:Log4j安装配置
jerbel插件安装: jerbel插件安装
按照上述步骤搭建环境,新建一个java Dynamic Web Project,可以尝试运行项目;
第二步:创建多对多关联表(由于实际项目表太多,举例几张简单表做演示)
APP_USER :包含用户。一个用户可以有多个配置[USER,ADMIN,DB·A]。
USER_PROFILE : 包含用户配置文件。配置文件可以链接到多个用户。
APP_USER_USER_PROFILE : 这是一个连接表连接APP_USER&USER_PROFILE中的多对多关系。
第三步:创建目录结构
第四步:更新pom.xml,包括所需的依赖关系
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>china-soa.com</groupId> <artifactId>Mdm</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name></name> <url>http://maven.apache.org</url> <properties> <springframework.version>4.3.2.RELEASE</springframework.version> <hibernate.version>5.2.2.Final</hibernate.version> </properties> <dependencies> <!-- 添加junit支持 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version></dependency> <!-- 添加spring支持 --><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>${springframework.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-beans</artifactId><version>${springframework.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-tx</artifactId><version>${springframework.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>${springframework.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context-support</artifactId><version>${springframework.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>${springframework.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-aop</artifactId><version>${springframework.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-aspects</artifactId><version>${springframework.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>${springframework.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>${springframework.version}</version></dependency> <!-- 添加hibernate支持 --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>${hibernate.version}</version></dependency><dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>${springframework.version}</version></dependency><!-- <dependency> <groupId>org.springframework</groupId> <artifactId>spring-hibernate</artifactId> <version>1.2.9</version></dependency> --><dependency> <groupId>org.hibernate.common</groupId> <artifactId>hibernate-commons-annotations</artifactId> <version>5.0.1.Final</version></dependency> <dependency> <groupId>org.hibernate.javax.persistence</groupId> <artifactId>hibernate-jpa-2.1-api</artifactId> <version>1.0.0.Final</version></dependency><!-- apache公共包 --><dependency><groupId>commons-codec</groupId><artifactId>commons-codec</artifactId><version>1.9</version></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.4</version></dependency><dependency><groupId>commons-beanutils</groupId><artifactId>commons-beanutils</artifactId><version>1.9.2</version></dependency><dependency><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId><version>1.2</version></dependency><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.5</version></dependency><dependency><groupId>net.sf.ezmorph</groupId><artifactId>ezmorph</artifactId><version>1.0.6</version></dependency><dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.3.1</version></dependency> <!-- 添加servlet+Jsp+jstl支持 --><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>3.1.0</version></dependency><dependency><groupId>javax.servlet.jsp</groupId><artifactId>javax.servlet.jsp-api</artifactId><version>2.3.1</version></dependency><dependency><groupId>javax.servlet</groupId><artifactId>jstl</artifactId><version>1.2</version></dependency><!-- 数据库驱动 --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>6.0.3</version></dependency> <!-- 添加oracle jdbc driver --> <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>11.2.0</version> </dependency><!-- 添加阿里巴巴连接池druid支持 --><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.0.25</version></dependency> <!-- JSON支持 --> <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</artifactId> <version>2.4</version> </dependency> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>1.9.13</version></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>2.5.3</version></dependency> <!-- 添加日志log4j支持 --><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.17</version></dependency><dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.6.2</version></dependency><dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.6.2</version></dependency> <dependency> <groupId>ognl</groupId> <artifactId>ognl</artifactId> <version>3.1.12</version></dependency> <!-- http客户端工具 --><dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.2</version></dependency><dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpmime</artifactId> <version>4.5.2</version></dependency> </dependencies> <build> <finalName>Mdm</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build></project>
第五步:准备实体类(model)
/** * */package com.soa.mdm.entity;import java.util.Date;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.Id;import javax.persistence.JoinColumn;import javax.persistence.ManyToOne;import javax.persistence.Table;import org.hibernate.annotations.GenericGenerator;@Entity@Table(name = "code_segment")public class CodeSegment {private String segmentId; private String parentId;private String rulesName; private String segmentName;private Integer segmentSequence; private String outputName; private String segmentAlias; private Integer minLength;private Integer maxLength;private String segmentSource; private String sourceContent; private String validateSwitch;private String statusSwitch;private String linkageSwitch; private String description;private String remark;private String creator;private Date createtime;private Date updatetime;private String version;private String extendOne;private String extendTwo;private String extendThree;private String extendFour;private String extendFive;private CodeRules codeRules; @ManyToOne@JoinColumn(name = "rulesId")public CodeRules getCodeRules() {return codeRules;}public void setCodeRules(CodeRules codeRules) {this.codeRules = codeRules;}@Id@GeneratedValue(generator = "system-uuid")@GenericGenerator(name = "system-uuid", strategy = "uuid")public String getSegmentId() {return segmentId;}public void setSegmentId(String segmentId) {this.segmentId = segmentId;}public String getParentId() {return parentId;}public void setParentId(String parentId) {this.parentId = parentId;}public String getRulesName() {return rulesName;}public void setRulesName(String rulesName) {this.rulesName = rulesName;}public String getSegmentName() {return segmentName;}public void setSegmentName(String segmentName) {this.segmentName = segmentName;}public Integer getSegmentSequence() {return segmentSequence;}public void setSegmentSequence(Integer segmentSequence) {this.segmentSequence = segmentSequence;}public String getOutputName() {return outputName;}public void setOutputName(String outputName) {this.outputName = outputName;}public String getSegmentAlias() {return segmentAlias;}public void setSegmentAlias(String segmentAlias) {this.segmentAlias = segmentAlias;}public Integer getMinLength() {return minLength;}public void setMinLength(Integer minLength) {this.minLength = minLength;}public Integer getMaxLength() {return maxLength;}public void setMaxLength(Integer maxLength) {this.maxLength = maxLength;}public String getSegmentSource() {return segmentSource;}public void setSegmentSource(String segmentSource) {this.segmentSource = segmentSource;}public String getSourceContent() {return sourceContent;}public void setSourceContent(String sourceContent) {this.sourceContent = sourceContent;}public String getValidateSwitch() {return validateSwitch;}public void setValidateSwitch(String validateSwitch) {this.validateSwitch = validateSwitch;}public String getStatusSwitch() {return statusSwitch;}public void setStatusSwitch(String statusSwitch) {this.statusSwitch = statusSwitch;}public String getLinkageSwitch() {return linkageSwitch;}public void setLinkageSwitch(String linkageSwitch) {this.linkageSwitch = linkageSwitch;}public String getDescription() {return description;}public void setDescription(String description) {this.description = description;}public String getRemark() {return remark;}public void setRemark(String remark) {this.remark = remark;}public String getCreator() {return creator;}public void setCreator(String creator) {this.creator = creator;}public Date getCreatetime() {return createtime;}public void setCreatetime(Date createtime) {this.createtime = createtime;}public Date getUpdatetime() {return updatetime;}public void setUpdatetime(Date updatetime) {this.updatetime = updatetime;}public String getVersion() {return version;}public void setVersion(String version) {this.version = version;}public String getExtendOne() {return extendOne;}public void setExtendOne(String extendOne) {this.extendOne = extendOne;}public String getExtendTwo() {return extendTwo;}public void setExtendTwo(String extendTwo) {this.extendTwo = extendTwo;}public String getExtendThree() {return extendThree;}public void setExtendThree(String extendThree) {this.extendThree = extendThree;}public String getExtendFour() {return extendFour;}public void setExtendFour(String extendFour) {this.extendFour = extendFour;}public String getExtendFive() {return extendFive;}public void setExtendFive(String extendFive) {this.extendFive = extendFive;}@Overridepublic String toString() {return "CodeSegment [segmentId=" + segmentId + ", parentId=" + parentId + ", rulesName=" + rulesName+ ", segmentName=" + segmentName + ", segmentSequence=" + segmentSequence + ", outputName=" + outputName+ ", segmentAlias=" + segmentAlias + ", minLength=" + minLength + ", maxLength=" + maxLength+ ", segmentSource=" + segmentSource + ", sourceContent=" + sourceContent + ", validateSwitch="+ validateSwitch + ", statusSwitch=" + statusSwitch + ", linkageSwitch=" + linkageSwitch+ ", codeRules=" + codeRules + ", description=" + description + ", remark=" + remark + ", creator="+ creator + ", createtime=" + createtime + ", updatetime=" + updatetime + ", version=" + version+ ", extendOne=" + extendOne + ", extendTwo=" + extendTwo + ", extendThree=" + extendThree+ ", extendFour=" + extendFour + ", extendFive=" + extendFive + "]";}}
本章主要介绍该系统用到的工具、技术以及环境的搭建,对于技术选型、表现层(UI)、业务逻辑层(BLL)、数据访问层(DAL)没有做任何描述。我将在接下来的章节进行详细的说明。
1 0
- Spring MVC+hibernate 开发系统(一)
- 搭建Spring+Spring MVC+Hibernate开发框架
- Spring MVC+Hibernate框架项目开发流程
- 基于Hibernate+Spring+Spring MVC+Bootstrap的管理系统实现
- 基于Hibernate+Spring+Spring MVC+Bootstrap的管理系统实现
- 基于Hibernate+Spring+Spring MVC+Bootstrap的管理系统实现
- spring mvc高级篇(一):Spring+SpringMVC+Hibernate整合
- 搭建Spring Mvc+Spring+Hibernate开发框架详细说明
- 搭建Spring Mvc+Spring+Hibernate开发框架详细说明
- Spring + Spring MVC + Hibernate项目开发集成(注解)
- Spring + Spring MVC + Hibernate项目开发集成(注解)
- SSH网站开发实录(1)Spring+Spring MVC+Hibernate
- Java 开发之Spring MVC(一)
- 利用spring mvc,hibernate重构系统(3)
- 利用spring mvc,hibernate重构系统(4)--JPA
- [置顶] 利用spring mvc,hibernate重构系统(1)
- [置顶] 利用spring mvc,hibernate重构系统(2)
- Spring MVC + Hibernate JPA + Bootstrap 搭建的博客系统
- sqlserver绑定主键的聚焦索引和非聚焦索引的更换
- 大牛的好文章 ip
- VNC的安装配置
- 前端也该了解的一些后端知识
- MyBatis Generator 详解
- Spring MVC+hibernate 开发系统(一)
- spring读取加载properties文件
- Linux git服务器http方式搭建
- iOS设置状态栏颜色
- 数据库的事务、事务并发以及隔离级别
- SQL state [99999]; error code [17001]; 问题处理
- Partition List
- 关于Java的File.separator
- Java日期与String转换等处理
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
哈尔滨到海参崴
海参崴火車站
海参崴自助游攻略
绥芬河到海参崴旅游报价
海参崴性旅游
海参崴酒店价格
海参崴跟团游
海参崴免税店
海参崴玩俄妞
海参崴旅行团
到海参崴旅游
海参崴海鲜
海参崴是哪里
海参崴签证怎么办
海参崴港
海参崴几月份去好
海参崴人口
海参崴是不冻港吗
海叁威
弗拉迪沃斯托克
海生葳
海深威
海参炖排骨
海参烧法
干海参和鲜海参
清汤海参
海参的烹饪方法
炖海参的做法
海参豆腐的家常做法
海参的家常做法大全集
海参煲汤大全
家常海参做法
海参怎么煲汤
海参蛋花汤的家常做法
海参虫草汤
海参炖汤做法
海参乌鸡汤的功效
海参煲什么汤好
羊肉海参汤怎么做
鸽子海参汤的做法大全
海参萝卜汤