Java full stack Development -- Java ERP system development: the establishment of commercial ERP database and the construction of the project

6, Database ORACLE

(1) Table space creation

1. Using PLSQL

--Tablespace--
CREATE TABLESPACE ERP_TS 
DATAFILE 'c:\ts\erp.dbf'
SIZE 100M
AUTOEXTEND ON
NEXT 10M; 

Created successfully

(2) Create user

-- Create users and associate default tablespaces
CREATE USER ERPUSER IDENTIFIED BY itzheng DEFAULT TABLESPACE ERP_TS;

(3) Assign permissions to users

-- Give users permission, maximum permission
grant dba to ERPUSER;

(4) Log out and log in to the user just created

Log out

Log in to ERPUSER

(5) Create table (using PowerDesigner)

1. PowerDesigner generate database


2. Use PLSQL to import data (first put the files generated above into disk C)

Database file download: https://download.csdn.net/download/qq_44757034/12910524
Unzip and put it into disk C
Create data table


Import succeeded


7, SSH2 framework construction

(1) Create Maven parent project

(1) Create Maven parent project (erp_parent)


Click Next

Click Next

Click Finish

Project creation completed
In pox Modify the content in 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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.itheima</groupId>
  <artifactId>erp_parent</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  <modules>
  	<module>erp_entity</module>
  	<module>erp_dao</module>
  	<module>erp_web</module>
  	<module>erp_biz</module>
  </modules>
  <!-- Define version constants -->
  <properties>
  	<spring.version>4.2.4.RELEASE</spring.version>
  	<struts.version>2.3.24</struts.version>
  	<hibernate.version>5.0.7.Final</hibernate.version>
  </properties>
  
  <dependencies>
  	<dependency>
  		<groupId>org.apache.struts</groupId>
  		<artifactId>struts2-core</artifactId>
  		<version>${struts.version}</version>
  		<!-- Exclude dependencies -->
  		<exclusions>
  			<exclusion>
  				<artifactId>javassist</artifactId>
  				<groupId>javassist</groupId>
  			</exclusion>
  		</exclusions>
  	</dependency>
  	<dependency>
  		<groupId>org.hibernate</groupId>
  		<artifactId>hibernate-core</artifactId>
  		<version>${hibernate.version}</version>
  	</dependency>
  	
  	<!-- The first principle: the first statement takes precedence -->
  	
  	<!-- introduce spring-beans-4.2.2 -->
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-context</artifactId>
  		<version>4.2.2.RELEASE</version>
  	</dependency>
  	<!-- introduce spring-beans-3.0.5 -->
  	<dependency>
  		<groupId>org.apache.struts</groupId>
  		<artifactId>struts2-spring-plugin</artifactId>
  		<version>${struts.version}</version>
  	</dependency>
	<!-- The second principle: the closer the path, the better -->
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-beans</artifactId>
  		<version>${spring.version}</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-core</artifactId>
  		<version>${spring.version}</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-context-support</artifactId>
  		<version>${spring.version}</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-aop</artifactId>
  		<version>${spring.version}</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-tx</artifactId>
  		<version>${spring.version}</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-orm</artifactId>
  		<version>${spring.version}</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-web</artifactId>
  		<version>${spring.version}</version>
  	</dependency>
  	<dependency>
  		<groupId>org.aspectj</groupId>
  		<artifactId>aspectjweaver</artifactId>
  		<version>1.8.7</version>
  	</dependency>
  	<dependency>
  		<groupId>org.slf4j</groupId>
  		<artifactId>slf4j-api</artifactId>
  		<version>1.7.12</version>
  	</dependency>
  	<dependency>
  		<groupId>org.slf4j</groupId>
  		<artifactId>slf4j-log4j12</artifactId>
  		<version>1.7.12</version>
  	</dependency>
  	<dependency>
  		<groupId>c3p0</groupId>
  		<artifactId>c3p0</artifactId>
  		<version>0.9.1.2</version>
  	</dependency>
  	<dependency>
  		<groupId>jstl</groupId>
  		<artifactId>jstl</artifactId>
  		<version>1.2</version>
  	</dependency>
  	<dependency>
  		<groupId>javax.servlet</groupId>
  		<artifactId>servlet-api</artifactId>
  		<version>2.5</version>
  		<scope>provided</scope>
  	</dependency>
  	<dependency>
  		<groupId>com.oracle</groupId>
  		<artifactId>ojdbc6</artifactId>
  		<version>11.2.0.3</version>
  	</dependency>
  	<dependency>
  		<groupId>com.alibaba</groupId>
  		<artifactId>fastjson</artifactId>
  		<version>1.2.8</version>
  	</dependency>
  </dependencies>
  	<!-- Version locking  -->
    <dependencyManagement>
		<dependencies>
			<dependency>
		  		<groupId>junit</groupId>
		  		<artifactId>junit</artifactId>
		  		<version>4.9</version>
		  		<scope>test</scope>
	  		</dependency>
		</dependencies>
    </dependencyManagement>
    <build>
    	<plugins>
    		<plugin>
    			<groupId>org.apache.tomcat.maven</groupId>
    			<artifactId>tomcat7-maven-plugin</artifactId>
    			<version>2.2</version>
    			<configuration>
    				<port>8080</port>
    				<path>/erp</path>
    			</configuration>
    		</plugin>
    	</plugins>
    </build>
</project>

(2) Create Maven sub module

1. Create erp_parent




Click finish

2. Create other subproject projects in the same way as above

3. Create ERP_ Web (store action class and front-end source code)

4. In ERP_ In the web project, expand the src\main\webapp directory, create the WEB-INF folder, and create the web XML to WEB-INF folder




web. Content in XML

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
	
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath*:applicationContext*.xml</param-value>
	</context-param>
	<filter>
   		<filter-name>openSessionInView</filter-name>
   		<filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>openSessionInView</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>	
</web-app>
5. In erp_dao Xia

The ApplicationContext in the spring configuration file_ datasource. XML and
applicationContext_dao.xml creation to ERP_ Under src/main/resources of Dao project.

applicationContext_datasource.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop.xsd
		">  
	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
		<property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:ORCL"/>
		<property name="username" value="user name"/>
		<property name="password" value="password"/>
	</bean>
	<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource"/>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
				<prop key="hibernate.show_sql">true</prop>
				<prop key="hibernate.format_sql">false</prop>
			</props>
		</property>
		<property name="mappingLocations">
			<value>classpath:Package of entity class/*.hbm.xml</value>
		</property>
	</bean>
</beans>

applicationContext_dao.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop.xsd
		">  
</beans>
6. In erp_biz lower

Create to ERP_ Under src/main/resources of Biz project.
Create ApplicationContext in spring configuration file_ Tx.xml and applicationContext_biz.xml

applicationContext_tx.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop.xsd
		">  
	<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"/>
	</bean>
	<tx:advice id="advice" transaction-manager="transactionManager">
	    <tx:attributes>	     
	      <tx:method name="do*" propagation="REQUIRED"/>
	      <tx:method name="add*" propagation="REQUIRED"/>
	      <tx:method name="update*" propagation="REQUIRED"/>
	      <tx:method name="save*" propagation="REQUIRED"/>
	      <tx:method name="delete*" propagation="REQUIRED"/>
	      <tx:method name="*" read-only="true"/>
	    </tx:attributes>
	</tx:advice>
	<aop:config>
		<aop:pointcut id="serviceMethod" expression="execution(* Package of business logic.*.*(..))"/>
		<aop:advisor pointcut-ref="serviceMethod" advice-ref="advice" />
	</aop:config>
</beans>

applicationContext_biz.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop.xsd
		">  
</beans>
7. In ERP_ Under Web

src/main/resources of the project.
Put struts ApplicationContext in XML and spring configuration files_ action. XML creation to erp_web

applicationContext_action.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop.xsd
		">  
</beans>

(3) Create packages in each module




(4) Modify Spring's configuration file

1. Modify ERP_ ApplicationContext of Dao project_ datasource. XML, change the ip account password to its own corresponding

2. Modify ERP_ ApplicationContext of Biz project_ tx.xml


(5) Add easyUI to ERP_ Under Web Engineering

Relevant file download link:

(6) Set the dependency of each module


Add dependency in POM Click add in the dependencies in XML, and fill in the above contents in the middle selection box

8, [Department Management] realize list query

(1) Demand

Display these data in the database on the page

(2) In erp_entity src/main/java com itzheng. erp. Create Dep class under entity

package com.itzheng.erp.entity;
/*
 * department
 */
public class Dep {
	/* Department number */
	private Long uuid;
	/*
	 * Department name
	 */
	private String name;
	/*
	 * contact number
	 */
	private String tele;
	public Long getUuid() {
		return uuid;
	}
	public void setUuid(Long uuid) {
		this.uuid = uuid;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getTele() {
		return tele;
	}
	public void setTele(String tele) {
		this.tele = tele;
	}
}

Create corresponding profile

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.itzheng.erp.entity.Dep" table="Dep" >
        <id name="uuid" >           
        </id>
        <property name="name" />      
        <property name="tele" />     
    </class>
</hibernate-mapping>

(3) In ERP_ Editing data access layer in Dao

1. Create interface

package com.itzheng.erp.dao;
import java.util.List;
import com.itzheng.erp.entity.Dep;
public interface IDepDao {
	public List<Dep> getList();
}
2. Create dao implementation class
package com.itzheng.erp.dao.impl;
import java.util.List;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import com.itzheng.erp.dao.IDepDao;
import com.itzheng.erp.entity.Dep;
/*
 * Data access rights of the Department
 */
public class DepDao extends HibernateDaoSupport implements IDepDao {
	/*
	 * Query all department information
	 */
	@Override
	public List<Dep> getList() {
		return (List<Dep>) this.getHibernateTemplate().find("from Dep");
	}
}
3. Configure the corresponding applicationContext_dao.xml

	<bean id="depDao" class="com.itzheng.erp.dao.impl.DepDao" >
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
4. Create test class

package com.itzheng.erp.test.dao;
public class DepDaoTest {
	@Test
	public void testDep() {	
	}
}
5. Add test location


6. Modify test class
package com.itzheng.erp.test.dao;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.itzheng.erp.dao.impl.DepDao;
public class DepDaoTest {
	@Test
	public void testDep() {
		ApplicationContext ac = new ClassPathXmlApplicationContext("classpath*:applicationContext_*.xml");
		DepDao depDao = (DepDao) ac.getBean("depDao");
		System.out.println(depDao.getList().size());
		ac.getBean("sessionFactory");
	}
}

(4) Add content ERP in the business layer_ Biz middle

1. Create an interface: IDepBiz
package com.itzheng.erp.biz;
import java.util.List;
import com.itzheng.erp.entity.Dep;
/*
 * Department business interface
 */
public interface IDepBiz {
	/*
	 * Query all department lists
	 */
	List<Dep> getList();
}
2. Create implementation class
package com.itzheng.erp.biz.impl;
import java.util.List;
import com.itzheng.erp.biz.IDepBiz;
import com.itzheng.erp.dao.IDepDao;
import com.itzheng.erp.entity.Dep;
/*
 * Department business realization
 */
public class DepBiz implements IDepBiz {
	/*
	 * Call layer data access
	 */
	private IDepDao depDao;
	public void setDepDao(IDepDao depDao) {
		this.depDao = depDao;
	}
	@Override
	public List<Dep> getList() {
		// TODO Auto-generated method stub
		return depDao.getList();
	}
}

(5) Add in the action web layer

1. Create Action

package com.itzheng.erp.action;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import com.alibaba.fastjson.JSON;
import com.itzheng.erp.biz.IDepBiz;
import com.itzheng.erp.entity.Dep;
/*
 * Department Action
 */
public class DeptAction {
	private IDepBiz depBiz;
	public void setDepBiz(IDepBiz depBiz) {
		this.depBiz = depBiz;
	}
	/*
	 * Query all departments
	 */
	public void list() {
		/*
		 * Call the business of the business department to query the information of all departments
		 */
		List<Dep> list = depBiz.getList();
		//Convert Department list to JSON string
		String listString = JSON.toJSONString(list);
		try {
			//Response object
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("text/html;charset=utf-8");
			//Output to page
			response.getWriter().write(listString);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
2. In ERP_ biz applicationContext_ biz. Configuring dao in XML
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop.xsd
		">  
	<bean id="depBiz" class="com.itzheng.erp.biz.impl.DepBiz" >
		<property name="daoDao" ref="depDao" ></property>
	</bean>
</beans>
3. In ERP_ ApplicationContext in Web_ action. xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop.xsd
		">  
	<bean id="depAction" class="com.itzheng.erp.action.DeptAction">
		<property name="depBiz" ref="depBiz" ></property>
	</bean>
</beans>
	

4. In ERP_ Struts in web xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
	"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
    <package name="default" namespace="/" extends="struts-default">  
    	
    	<action name="dep_*" class="depAction" method="{1}" ></action>
    	  	   	
    </package>
</struts>

(6) Run and test the project

Access the corresponding

(7) Implementation of front end

1. In ERP_ Introducing easy into webapp under Web_ UI related files


File download address:

2. In ERP_ Create dep.html under webapp under Web

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Department management</title>
<link rel="stylesheet" type="text/css" href="ui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="ui/themes/icon.css">
<script type="text/javascript" src="ui/jquery.min.js"></script>
<script type="text/javascript" src="ui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="ui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
	$(function(){
		$('#grid').datagrid({    
				url:'dep_list',    
				columns:[[    
					 {field:'uuid',title:'Department number',width:100},    
					{field:'name',title:'Department name',width:100},    
					 {field:'tele',title:'Department contact number',width:100,align:'right'}    
				]]    
		}); 		
	});
</script>
</head>
<body>
	<table id="grid">
	</table>
</body>
</html>
3. Visit the corresponding page http://localhost:8080/erp/dep.html

Visit successful

Tags: Java Database Hibernate Maven Spring

Posted by johnbrayn on Fri, 13 May 2022 05:39:24 +0300