parent
3640480dfd
commit
fa301a349f
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="melibrary.com.genuitec.eclipse.j2eedt.core.MYECLIPSE_JAVAEE_5_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
|
||||
<classpathentry kind="con" path="melibrary.com.genuitec.eclipse.hibernate.MYECLIPSE_HIBERNATE3_3_CORE"/>
|
||||
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/mysql-connector-java-5.1.47.jar"/>
|
||||
<classpathentry kind="output" path="WebRoot/WEB-INF/classes"/>
|
||||
</classpath>
|
@ -0,0 +1,25 @@
|
||||
#MyEclipse Hibernate Properties
|
||||
#Sat Jan 04 23:52:24 CST 2020
|
||||
sessionFactoryName=hib.HibernateSessionFactory
|
||||
genBasicCompId=false
|
||||
profile=
|
||||
daoSFId=
|
||||
version=3.3
|
||||
jndiPath=
|
||||
detectM2M=false
|
||||
reStrategyClass=
|
||||
detectO2O=false
|
||||
springDaoFile=
|
||||
useJavaTypes=true
|
||||
keyGenerator=
|
||||
libInstallFolder=WebRoot/WEB-INF/lib
|
||||
addLibs2Project=true
|
||||
genVersionTag=false
|
||||
sessionFactoryId=
|
||||
basePersistenceClass=
|
||||
genAnnotations=false
|
||||
reSettingsFile=
|
||||
configFile=/pagebean/src/hibernate.cfg.xml
|
||||
createConfigFile=true
|
||||
addLibs2Classpath=true
|
||||
baseDaoClass=BaseHibernateDAO
|
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project-module
|
||||
type="WEB"
|
||||
name="pagebean"
|
||||
id="myeclipse.1578151183785"
|
||||
context-root="/pagebean"
|
||||
j2ee-spec="5.0"
|
||||
archive="pagebean.war">
|
||||
<attributes>
|
||||
<attribute name="webrootdir" value="WebRoot" />
|
||||
</attributes>
|
||||
</project-module>
|
||||
|
@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>pagebean</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.genuitec.eclipse.j2eedt.core.WebClasspathBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.genuitec.eclipse.j2eedt.core.J2EEProjectValidator</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.genuitec.eclipse.j2eedt.core.DeploymentDescriptorValidator</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.genuitec.eclipse.hibernate.HibernateBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.genuitec.eclipse.ast.deploy.core.DeploymentBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.genuitec.eclipse.ast.deploy.core.deploymentnature</nature>
|
||||
<nature>com.genuitec.eclipse.hibernate.hibernatenature</nature>
|
||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||
<nature>com.genuitec.eclipse.j2eedt.core.webnature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="WebRoot"/>
|
||||
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
|
||||
<attributes>
|
||||
<attribute name="hide" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
|
||||
<classpathentry kind="output" path=""/>
|
||||
</classpath>
|
@ -0,0 +1,12 @@
|
||||
#Sat Jan 04 23:57:23 CST 2020
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project-modules id="moduleCoreId" project-version="1.5.0">
|
||||
<wb-module deploy-name="pagebean">
|
||||
<wb-resource deploy-path="/" source-path="/WebRoot"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
|
||||
<property name="context-root" value="/pagebean"/>
|
||||
<property name="java-output-path" value="/pagebean/WebRoot/WEB-INF/classes"/>
|
||||
</wb-module>
|
||||
</project-modules>
|
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<fixed facet="wst.jsdt.web"/>
|
||||
<installed facet="java" version="1.5"/>
|
||||
<installed facet="jst.web" version="2.5"/>
|
||||
<installed facet="wst.jsdt.web" version="1.0"/>
|
||||
</faceted-project>
|
@ -0,0 +1 @@
|
||||
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
|
@ -0,0 +1 @@
|
||||
Window
|
@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Class-Path:
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,36 @@
|
||||
<?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">
|
||||
<!--
|
||||
Mapping file autogenerated by MyEclipse Persistence Tools
|
||||
-->
|
||||
<hibernate-mapping>
|
||||
<class name="hib.Products" table="products" catalog="myday">
|
||||
<composite-id name="id" class="hib.ProductsId">
|
||||
<key-property name="proId" type="java.lang.Integer">
|
||||
<column name="proId" />
|
||||
</key-property>
|
||||
<key-property name="userId" type="java.lang.Integer">
|
||||
<column name="userId" />
|
||||
</key-property>
|
||||
<key-property name="proName" type="java.lang.String">
|
||||
<column name="proName" />
|
||||
</key-property>
|
||||
<key-property name="contact" type="java.lang.String">
|
||||
<column name="contact" />
|
||||
</key-property>
|
||||
<key-property name="price" type="java.lang.Float">
|
||||
<column name="price" precision="12" scale="0" />
|
||||
</key-property>
|
||||
<key-property name="oprice" type="java.lang.Float">
|
||||
<column name="oprice" precision="12" scale="0" />
|
||||
</key-property>
|
||||
<key-property name="type" type="java.lang.Integer">
|
||||
<column name="type" />
|
||||
</key-property>
|
||||
<key-property name="classifyId" type="java.lang.Integer">
|
||||
<column name="classifyId" />
|
||||
</key-property>
|
||||
</composite-id>
|
||||
</class>
|
||||
</hibernate-mapping>
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1,26 @@
|
||||
<?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">
|
||||
|
||||
<!-- Generated by MyEclipse Hibernate Tools. -->
|
||||
<hibernate-configuration>
|
||||
|
||||
<session-factory>
|
||||
<property name="dialect">
|
||||
org.hibernate.dialect.MySQLDialect
|
||||
</property>
|
||||
<property name="connection.url">
|
||||
jdbc:mysql://localhost:3306/myday
|
||||
</property>
|
||||
<property name="connection.username">root</property>
|
||||
<property name="connection.password">mysql123</property>
|
||||
<property name="connection.driver_class">
|
||||
com.mysql.jdbc.Driver
|
||||
</property>
|
||||
<property name="myeclipse.connection.profile">myday</property>
|
||||
<mapping resource="hib/Products.hbm.xml" />
|
||||
|
||||
</session-factory>
|
||||
|
||||
</hibernate-configuration>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,11 @@
|
||||
<?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">
|
||||
<display-name></display-name>
|
||||
<welcome-file-list>
|
||||
<welcome-file>index.jsp</welcome-file>
|
||||
</welcome-file-list>
|
||||
</web-app>
|
@ -0,0 +1,26 @@
|
||||
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
|
||||
<%
|
||||
String path = request.getContextPath();
|
||||
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
|
||||
%>
|
||||
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<base href="<%=basePath%>">
|
||||
|
||||
<title>My JSP 'index.jsp' starting page</title>
|
||||
<meta http-equiv="pragma" content="no-cache">
|
||||
<meta http-equiv="cache-control" content="no-cache">
|
||||
<meta http-equiv="expires" content="0">
|
||||
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
|
||||
<meta http-equiv="description" content="This is my page">
|
||||
<!--
|
||||
<link rel="stylesheet" type="text/css" href="styles.css">
|
||||
-->
|
||||
</head>
|
||||
|
||||
<body>
|
||||
This is my JSP page. <br>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,31 @@
|
||||
package action;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import model.PageBean;
|
||||
|
||||
import service.ProductService;
|
||||
|
||||
|
||||
public class ProductAction {
|
||||
|
||||
|
||||
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
|
||||
int pageNum = Integer.valueOf(request.getParameter("pageNum"));
|
||||
int pageSize=10;
|
||||
ProductService ps = new ProductService();
|
||||
//获取一个PageBean对象
|
||||
PageBean pb = ps.showAllProductWithPage(pageNum, pageSize);
|
||||
|
||||
//将pb放入request域中
|
||||
request.setAttribute("pageBean",pb);
|
||||
request.getRequestDispatcher("/page.jsp").forward(request,response);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package dao;
|
||||
|
||||
/**
|
||||
* AbstractProducts entity provides the base persistence definition of the
|
||||
* Products entity. @author MyEclipse Persistence Tools
|
||||
*/
|
||||
|
||||
public abstract class AbstractProducts implements java.io.Serializable {
|
||||
|
||||
// Fields
|
||||
|
||||
private ProductsId id;
|
||||
|
||||
// Constructors
|
||||
|
||||
/** default constructor */
|
||||
public AbstractProducts() {
|
||||
}
|
||||
|
||||
/** full constructor */
|
||||
public AbstractProducts(ProductsId id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
// Property accessors
|
||||
|
||||
public ProductsId getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(ProductsId id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,173 @@
|
||||
package dao;
|
||||
|
||||
/**
|
||||
* AbstractProductsId entity provides the base persistence definition of the
|
||||
* ProductsId entity. @author MyEclipse Persistence Tools
|
||||
*/
|
||||
|
||||
public abstract class AbstractProductsId implements java.io.Serializable {
|
||||
|
||||
// Fields
|
||||
|
||||
private Integer proId;
|
||||
private Integer userId;
|
||||
private String proName;
|
||||
private String contact;
|
||||
private Float price;
|
||||
private Float oprice;
|
||||
private Integer type;
|
||||
private Integer classifyId;
|
||||
|
||||
// Constructors
|
||||
|
||||
/** default constructor */
|
||||
public AbstractProductsId() {
|
||||
}
|
||||
|
||||
/** minimal constructor */
|
||||
public AbstractProductsId(Integer proId, Integer userId) {
|
||||
this.proId = proId;
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
/** full constructor */
|
||||
public AbstractProductsId(Integer proId, Integer userId, String proName,
|
||||
String contact, Float price, Float oprice, Integer type,
|
||||
Integer classifyId) {
|
||||
this.proId = proId;
|
||||
this.userId = userId;
|
||||
this.proName = proName;
|
||||
this.contact = contact;
|
||||
this.price = price;
|
||||
this.oprice = oprice;
|
||||
this.type = type;
|
||||
this.classifyId = classifyId;
|
||||
}
|
||||
|
||||
// Property accessors
|
||||
|
||||
public Integer getProId() {
|
||||
return this.proId;
|
||||
}
|
||||
|
||||
public void setProId(Integer proId) {
|
||||
this.proId = proId;
|
||||
}
|
||||
|
||||
public Integer getUserId() {
|
||||
return this.userId;
|
||||
}
|
||||
|
||||
public void setUserId(Integer userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getProName() {
|
||||
return this.proName;
|
||||
}
|
||||
|
||||
public void setProName(String proName) {
|
||||
this.proName = proName;
|
||||
}
|
||||
|
||||
public String getContact() {
|
||||
return this.contact;
|
||||
}
|
||||
|
||||
public void setContact(String contact) {
|
||||
this.contact = contact;
|
||||
}
|
||||
|
||||
public Float getPrice() {
|
||||
return this.price;
|
||||
}
|
||||
|
||||
public void setPrice(Float price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public Float getOprice() {
|
||||
return this.oprice;
|
||||
}
|
||||
|
||||
public void setOprice(Float oprice) {
|
||||
this.oprice = oprice;
|
||||
}
|
||||
|
||||
public Integer getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(Integer type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Integer getClassifyId() {
|
||||
return this.classifyId;
|
||||
}
|
||||
|
||||
public void setClassifyId(Integer classifyId) {
|
||||
this.classifyId = classifyId;
|
||||
}
|
||||
|
||||
public boolean equals(Object other) {
|
||||
if ((this == other))
|
||||
return true;
|
||||
if ((other == null))
|
||||
return false;
|
||||
if (!(other instanceof AbstractProductsId))
|
||||
return false;
|
||||
AbstractProductsId castOther = (AbstractProductsId) other;
|
||||
|
||||
return ((this.getProId() == castOther.getProId()) || (this.getProId() != null
|
||||
&& castOther.getProId() != null && this.getProId().equals(
|
||||
castOther.getProId())))
|
||||
&& ((this.getUserId() == castOther.getUserId()) || (this
|
||||
.getUserId() != null && castOther.getUserId() != null && this
|
||||
.getUserId().equals(castOther.getUserId())))
|
||||
&& ((this.getProName() == castOther.getProName()) || (this
|
||||
.getProName() != null && castOther.getProName() != null && this
|
||||
.getProName().equals(castOther.getProName())))
|
||||
&& ((this.getContact() == castOther.getContact()) || (this
|
||||
.getContact() != null && castOther.getContact() != null && this
|
||||
.getContact().equals(castOther.getContact())))
|
||||
&& ((this.getPrice() == castOther.getPrice()) || (this
|
||||
.getPrice() != null && castOther.getPrice() != null && this
|
||||
.getPrice().equals(castOther.getPrice())))
|
||||
&& ((this.getOprice() == castOther.getOprice()) || (this
|
||||
.getOprice() != null && castOther.getOprice() != null && this
|
||||
.getOprice().equals(castOther.getOprice())))
|
||||
&& ((this.getType() == castOther.getType()) || (this.getType() != null
|
||||
&& castOther.getType() != null && this.getType()
|
||||
.equals(castOther.getType())))
|
||||
&& ((this.getClassifyId() == castOther.getClassifyId()) || (this
|
||||
.getClassifyId() != null
|
||||
&& castOther.getClassifyId() != null && this
|
||||
.getClassifyId().equals(castOther.getClassifyId())));
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result = 17;
|
||||
|
||||
result = 37 * result
|
||||
+ (getProId() == null ? 0 : this.getProId().hashCode());
|
||||
result = 37 * result
|
||||
+ (getUserId() == null ? 0 : this.getUserId().hashCode());
|
||||
result = 37 * result
|
||||
+ (getProName() == null ? 0 : this.getProName().hashCode());
|
||||
result = 37 * result
|
||||
+ (getContact() == null ? 0 : this.getContact().hashCode());
|
||||
result = 37 * result
|
||||
+ (getPrice() == null ? 0 : this.getPrice().hashCode());
|
||||
result = 37 * result
|
||||
+ (getOprice() == null ? 0 : this.getOprice().hashCode());
|
||||
result = 37 * result
|
||||
+ (getType() == null ? 0 : this.getType().hashCode());
|
||||
result = 37
|
||||
* result
|
||||
+ (getClassifyId() == null ? 0 : this.getClassifyId()
|
||||
.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package dao;
|
||||
|
||||
import org.hibernate.Session;
|
||||
|
||||
|
||||
/**
|
||||
* Data access object (DAO) for domain model
|
||||
* @author MyEclipse Persistence Tools
|
||||
*/
|
||||
public class BaseHibernateDAO implements IBaseHibernateDAO {
|
||||
|
||||
public Session getSession() {
|
||||
return HibernateSessionFactory.getSession();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,118 @@
|
||||
package dao;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
||||
/**
|
||||
* Configures and provides access to Hibernate sessions, tied to the
|
||||
* current thread of execution. Follows the Thread Local Session
|
||||
* pattern, see {@link http://hibernate.org/42.html }.
|
||||
*/
|
||||
public class HibernateSessionFactory {
|
||||
|
||||
/**
|
||||
* Location of hibernate.cfg.xml file.
|
||||
* Location should be on the classpath as Hibernate uses
|
||||
* #resourceAsStream style lookup for its configuration file.
|
||||
* The default classpath location of the hibernate config file is
|
||||
* in the default package. Use #setConfigFile() to update
|
||||
* the location of the configuration file for the current session.
|
||||
*/
|
||||
private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
|
||||
private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();
|
||||
private static Configuration configuration = new Configuration();
|
||||
private static org.hibernate.SessionFactory sessionFactory;
|
||||
private static String configFile = CONFIG_FILE_LOCATION;
|
||||
|
||||
static {
|
||||
try {
|
||||
configuration.configure(configFile);
|
||||
sessionFactory = configuration.buildSessionFactory();
|
||||
} catch (Exception e) {
|
||||
System.err
|
||||
.println("%%%% Error Creating SessionFactory %%%%");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private HibernateSessionFactory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ThreadLocal Session instance. Lazy initialize
|
||||
* the <code>SessionFactory</code> if needed.
|
||||
*
|
||||
* @return Session
|
||||
* @throws HibernateException
|
||||
*/
|
||||
public static Session getSession() throws HibernateException {
|
||||
Session session = (Session) threadLocal.get();
|
||||
|
||||
if (session == null || !session.isOpen()) {
|
||||
if (sessionFactory == null) {
|
||||
rebuildSessionFactory();
|
||||
}
|
||||
session = (sessionFactory != null) ? sessionFactory.openSession()
|
||||
: null;
|
||||
threadLocal.set(session);
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild hibernate session factory
|
||||
*
|
||||
*/
|
||||
public static void rebuildSessionFactory() {
|
||||
try {
|
||||
configuration.configure(configFile);
|
||||
sessionFactory = configuration.buildSessionFactory();
|
||||
} catch (Exception e) {
|
||||
System.err
|
||||
.println("%%%% Error Creating SessionFactory %%%%");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the single hibernate session instance.
|
||||
*
|
||||
* @throws HibernateException
|
||||
*/
|
||||
public static void closeSession() throws HibernateException {
|
||||
Session session = (Session) threadLocal.get();
|
||||
threadLocal.set(null);
|
||||
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* return session factory
|
||||
*
|
||||
*/
|
||||
public static org.hibernate.SessionFactory getSessionFactory() {
|
||||
return sessionFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* return session factory
|
||||
*
|
||||
* session factory will be rebuilded in the next call
|
||||
*/
|
||||
public static void setConfigFile(String configFile) {
|
||||
HibernateSessionFactory.configFile = configFile;
|
||||
sessionFactory = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* return hibernate configuration
|
||||
*
|
||||
*/
|
||||
public static Configuration getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package dao;
|
||||
|
||||
import org.hibernate.Session;
|
||||
|
||||
|
||||
/**
|
||||
* Data access interface for domain model
|
||||
* @author MyEclipse Persistence Tools
|
||||
*/
|
||||
public interface IBaseHibernateDAO {
|
||||
public Session getSession();
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?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">
|
||||
<!--
|
||||
Mapping file autogenerated by MyEclipse Persistence Tools
|
||||
-->
|
||||
<hibernate-mapping>
|
||||
<class name="hib.Products" table="products" catalog="myday">
|
||||
<composite-id name="id" class="hib.ProductsId">
|
||||
<key-property name="proId" type="java.lang.Integer">
|
||||
<column name="proId" />
|
||||
</key-property>
|
||||
<key-property name="userId" type="java.lang.Integer">
|
||||
<column name="userId" />
|
||||
</key-property>
|
||||
<key-property name="proName" type="java.lang.String">
|
||||
<column name="proName" />
|
||||
</key-property>
|
||||
<key-property name="contact" type="java.lang.String">
|
||||
<column name="contact" />
|
||||
</key-property>
|
||||
<key-property name="price" type="java.lang.Float">
|
||||
<column name="price" precision="12" scale="0" />
|
||||
</key-property>
|
||||
<key-property name="oprice" type="java.lang.Float">
|
||||
<column name="oprice" precision="12" scale="0" />
|
||||
</key-property>
|
||||
<key-property name="type" type="java.lang.Integer">
|
||||
<column name="type" />
|
||||
</key-property>
|
||||
<key-property name="classifyId" type="java.lang.Integer">
|
||||
<column name="classifyId" />
|
||||
</key-property>
|
||||
</composite-id>
|
||||
</class>
|
||||
</hibernate-mapping>
|
@ -0,0 +1,19 @@
|
||||
package dao;
|
||||
|
||||
/**
|
||||
* Products entity. @author MyEclipse Persistence Tools
|
||||
*/
|
||||
public class Products extends AbstractProducts implements java.io.Serializable {
|
||||
|
||||
// Constructors
|
||||
|
||||
/** default constructor */
|
||||
public Products() {
|
||||
}
|
||||
|
||||
/** full constructor */
|
||||
public Products(ProductsId id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
package dao;
|
||||
|
||||
import java.util.List;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.criterion.Example;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* A data access object (DAO) providing persistence and search support for
|
||||
* Products entities. Transaction control of the save(), update() and delete()
|
||||
* operations can directly support Spring container-managed transactions or they
|
||||
* can be augmented to handle user-managed Spring transactions. Each of these
|
||||
* methods provides additional information for how to configure it for the
|
||||
* desired type of transaction control.
|
||||
*
|
||||
* @see hib.Products
|
||||
* @author MyEclipse Persistence Tools
|
||||
*/
|
||||
|
||||
public class ProductsDAO extends BaseHibernateDAO {
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(ProductsDAO.class);
|
||||
|
||||
// property constants
|
||||
|
||||
public void save(Products transientInstance) {
|
||||
log.debug("saving Products instance");
|
||||
try {
|
||||
getSession().save(transientInstance);
|
||||
log.debug("save successful");
|
||||
} catch (RuntimeException re) {
|
||||
log.error("save failed", re);
|
||||
throw re;
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(Products persistentInstance) {
|
||||
log.debug("deleting Products instance");
|
||||
try {
|
||||
getSession().delete(persistentInstance);
|
||||
log.debug("delete successful");
|
||||
} catch (RuntimeException re) {
|
||||
log.error("delete failed", re);
|
||||
throw re;
|
||||
}
|
||||
}
|
||||
|
||||
public Products findById(dao.ProductsId id) {
|
||||
log.debug("getting Products instance with id: " + id);
|
||||
try {
|
||||
Products instance = (Products) getSession().get("hib.Products", id);
|
||||
return instance;
|
||||
} catch (RuntimeException re) {
|
||||
log.error("get failed", re);
|
||||
throw re;
|
||||
}
|
||||
}
|
||||
|
||||
public List findByExample(Products instance) {
|
||||
log.debug("finding Products instance by example");
|
||||
try {
|
||||
List results = getSession().createCriteria("hib.Products")
|
||||
.add(Example.create(instance)).list();
|
||||
log.debug("find by example successful, result size: "
|
||||
+ results.size());
|
||||
return results;
|
||||
} catch (RuntimeException re) {
|
||||
log.error("find by example failed", re);
|
||||
throw re;
|
||||
}
|
||||
}
|
||||
|
||||
public List findByProperty(String propertyName, Object value) {
|
||||
log.debug("finding Products instance with property: " + propertyName
|
||||
+ ", value: " + value);
|
||||
try {
|
||||
String queryString = "from Products as model where model."
|
||||
+ propertyName + "= ?";
|
||||
Query queryObject = getSession().createQuery(queryString);
|
||||
queryObject.setParameter(0, value);
|
||||
return queryObject.list();
|
||||
} catch (RuntimeException re) {
|
||||
log.error("find by property name failed", re);
|
||||
throw re;
|
||||
}
|
||||
}
|
||||
|
||||
public List findAll() {
|
||||
log.debug("finding all Products instances");
|
||||
try {
|
||||
String queryString = "from Products";
|
||||
Query queryObject = getSession().createQuery(queryString);
|
||||
return queryObject.list();
|
||||
} catch (RuntimeException re) {
|
||||
log.error("find all failed", re);
|
||||
throw re;
|
||||
}
|
||||
}
|
||||
|
||||
public Products merge(Products detachedInstance) {
|
||||
log.debug("merging Products instance");
|
||||
try {
|
||||
Products result = (Products) getSession().merge(detachedInstance);
|
||||
log.debug("merge successful");
|
||||
return result;
|
||||
} catch (RuntimeException re) {
|
||||
log.error("merge failed", re);
|
||||
throw re;
|
||||
}
|
||||
}
|
||||
|
||||
public void attachDirty(Products instance) {
|
||||
log.debug("attaching dirty Products instance");
|
||||
try {
|
||||
getSession().saveOrUpdate(instance);
|
||||
log.debug("attach successful");
|
||||
} catch (RuntimeException re) {
|
||||
log.error("attach failed", re);
|
||||
throw re;
|
||||
}
|
||||
}
|
||||
|
||||
public void attachClean(Products instance) {
|
||||
log.debug("attaching clean Products instance");
|
||||
try {
|
||||
getSession().lock(instance, LockMode.NONE);
|
||||
log.debug("attach successful");
|
||||
} catch (RuntimeException re) {
|
||||
log.error("attach failed", re);
|
||||
throw re;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package dao;
|
||||
|
||||
/**
|
||||
* ProductsId entity. @author MyEclipse Persistence Tools
|
||||
*/
|
||||
public class ProductsId extends AbstractProductsId implements
|
||||
java.io.Serializable {
|
||||
|
||||
// Constructors
|
||||
|
||||
/** default constructor */
|
||||
public ProductsId() {
|
||||
}
|
||||
|
||||
/** minimal constructor */
|
||||
public ProductsId(Integer proId, Integer userId) {
|
||||
super(proId, userId);
|
||||
}
|
||||
|
||||
/** full constructor */
|
||||
public ProductsId(Integer proId, Integer userId, String proName,
|
||||
String contact, Float price, Float oprice, Integer type,
|
||||
Integer classifyId) {
|
||||
super(proId, userId, proName, contact, price, oprice, type, classifyId);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?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">
|
||||
|
||||
<!-- Generated by MyEclipse Hibernate Tools. -->
|
||||
<hibernate-configuration>
|
||||
|
||||
<session-factory>
|
||||
<property name="dialect">
|
||||
org.hibernate.dialect.MySQLDialect
|
||||
</property>
|
||||
<property name="connection.url">
|
||||
jdbc:mysql://localhost:3306/myday
|
||||
</property>
|
||||
<property name="connection.username">root</property>
|
||||
<property name="connection.password">mysql123</property>
|
||||
<property name="connection.driver_class">
|
||||
com.mysql.jdbc.Driver
|
||||
</property>
|
||||
<property name="myeclipse.connection.profile">myday</property>
|
||||
<mapping resource="hib/Products.hbm.xml" />
|
||||
|
||||
</session-factory>
|
||||
|
||||
</hibernate-configuration>
|
@ -0,0 +1,56 @@
|
||||
package model;
|
||||
|
||||
|
||||
public class Product {
|
||||
private int proId;
|
||||
private int userId;
|
||||
private String proName; //物品名称
|
||||
private String contact; //卖家联系方式
|
||||
private float price; //转卖价
|
||||
private float oprice; //原价
|
||||
private int classifyId; //分类
|
||||
private int type;
|
||||
|
||||
public int getProId() {
|
||||
return proId;
|
||||
}
|
||||
public void setProId(int proId) {
|
||||
this.proId = proId;
|
||||
}
|
||||
public int getUserId() {
|
||||
return userId;
|
||||
}
|
||||
public void setUserId(int userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
public String getProName() {
|
||||
return proName;
|
||||
}
|
||||
public void setProName(String proName) {
|
||||
this.proName = proName;
|
||||
}
|
||||
public String getContact() {
|
||||
return contact;
|
||||
}
|
||||
public void setContact(String contact) {
|
||||
this.contact = contact;
|
||||
}
|
||||
public float getPrice() {
|
||||
return price;
|
||||
}
|
||||
public void setPrice(float price) {
|
||||
this.price = price;
|
||||
}
|
||||
public float getOprice() {
|
||||
return oprice;
|
||||
}
|
||||
public void setOprice(float oprice) {
|
||||
this.oprice = oprice;
|
||||
}
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package service;
|
||||
import dao.ProductsDAO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import model.PageBean;
|
||||
import model.Product;
|
||||
|
||||
|
||||
public class ProductService {
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public PageBean<Product> showAllProductWithPage(int pageNum,int pageSize){
|
||||
ProductsDAO pro=new ProductsDAO();
|
||||
List<Product> allProduct = pro.findAll();
|
||||
int totalRecord = allProduct.size();
|
||||
|
||||
PageBean pb= new PageBean(pageNum,pageSize,totalRecord);
|
||||
|
||||
int startIndex = pb.getStartIndex();
|
||||
|
||||
// pb.setList(ProductsDAO.findAll(startIndex,pageSize));
|
||||
pb.setList(pro.findAll());
|
||||
return pb;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue