Created
June 21, 2018 02:26
-
-
Save coolcoolercool/ebf50e2b41fa028212a8e7cabe6f07a9 to your computer and use it in GitHub Desktop.
dao部分
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> | |
| <component name="FacetManager"> | |
| <facet type="Spring" name="Spring"> | |
| <configuration /> | |
| </facet> | |
| <facet type="web" name="Web"> | |
| <configuration> | |
| <descriptors> | |
| <deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml" /> | |
| </descriptors> | |
| <webroots> | |
| <root url="file://$MODULE_DIR$/src/main/webapp" relative="/" /> | |
| </webroots> | |
| <sourceRoots> | |
| <root url="file://$MODULE_DIR$/src/main/java" /> | |
| <root url="file://$MODULE_DIR$/src/main/resources" /> | |
| </sourceRoots> | |
| </configuration> | |
| </facet> | |
| </component> | |
| <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7"> | |
| <output url="file://$MODULE_DIR$/target/classes" /> | |
| <output-test url="file://$MODULE_DIR$/target/test-classes" /> | |
| <content url="file://$MODULE_DIR$"> | |
| <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | |
| <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> | |
| <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> | |
| <sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" /> | |
| <excludeFolder url="file://$MODULE_DIR$/target" /> | |
| </content> | |
| <orderEntry type="inheritedJdk" /> | |
| <orderEntry type="sourceFolder" forTests="false" /> | |
| <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.11" level="project" /> | |
| <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" /> | |
| <orderEntry type="module" module-name="jk28_utils" /> | |
| <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.4" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4" level="project" /> | |
| <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" /> | |
| <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.9" level="project" /> | |
| <orderEntry type="library" name="Maven: com.alibaba:fastjson:1.1.37" level="project" /> | |
| <orderEntry type="library" name="Maven: commons-beanutils:commons-beanutils:1.9.1" level="project" /> | |
| <orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.1" level="project" /> | |
| <orderEntry type="library" name="Maven: org.quartz-scheduler:quartz:2.2.1" level="project" /> | |
| <orderEntry type="library" name="Maven: commons-fileupload:commons-fileupload:1.3.1" level="project" /> | |
| <orderEntry type="library" name="Maven: commons-io:commons-io:2.2" level="project" /> | |
| <orderEntry type="library" name="Maven: jstl:jstl:1.2" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.shiro:shiro-all:1.2.3" level="project" /> | |
| <orderEntry type="library" name="Maven: org.aspectj:aspectjweaver:1.6.8" level="project" /> | |
| <orderEntry type="library" name="Maven: org.springframework:spring-aop:4.2.4.RELEASE" level="project" /> | |
| <orderEntry type="library" name="Maven: aopalliance:aopalliance:1.0" level="project" /> | |
| <orderEntry type="library" name="Maven: org.springframework:spring-context:4.2.4.RELEASE" level="project" /> | |
| <orderEntry type="library" name="Maven: org.springframework:spring-expression:4.2.4.RELEASE" level="project" /> | |
| <orderEntry type="library" name="Maven: org.springframework:spring-context-support:4.2.4.RELEASE" level="project" /> | |
| <orderEntry type="library" name="Maven: org.springframework:spring-web:4.2.4.RELEASE" level="project" /> | |
| <orderEntry type="library" name="Maven: org.springframework:spring-orm:4.2.4.RELEASE" level="project" /> | |
| <orderEntry type="library" name="Maven: org.springframework:spring-jdbc:4.2.4.RELEASE" level="project" /> | |
| <orderEntry type="library" name="Maven: org.springframework:spring-tx:4.2.4.RELEASE" level="project" /> | |
| <orderEntry type="library" name="Maven: org.springframework:spring-beans:4.2.4.RELEASE" level="project" /> | |
| <orderEntry type="library" name="Maven: org.springframework:spring-core:4.2.4.RELEASE" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.struts:struts2-core:2.3.24" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.struts.xwork:xwork-core:2.3.24" level="project" /> | |
| <orderEntry type="library" name="Maven: asm:asm-commons:3.3" level="project" /> | |
| <orderEntry type="library" name="Maven: asm:asm-tree:3.3" level="project" /> | |
| <orderEntry type="library" name="Maven: org.freemarker:freemarker:2.3.22" level="project" /> | |
| <orderEntry type="library" name="Maven: ognl:ognl:3.0.6" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.struts:struts2-spring-plugin:2.3.24" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.2" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.struts:struts2-json-plugin:2.3.24" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.struts:struts2-convention-plugin:2.3.24" level="project" /> | |
| <orderEntry type="library" name="Maven: org.hibernate:hibernate-core:5.0.7.Final" level="project" /> | |
| <orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.3.0.Final" level="project" /> | |
| <orderEntry type="library" name="Maven: org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final" level="project" /> | |
| <orderEntry type="library" name="Maven: org.javassist:javassist:3.18.1-GA" level="project" /> | |
| <orderEntry type="library" name="Maven: antlr:antlr:2.7.7" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1.1" level="project" /> | |
| <orderEntry type="library" name="Maven: org.jboss:jandex:2.0.0.Final" level="project" /> | |
| <orderEntry type="library" name="Maven: org.hibernate.common:hibernate-commons-annotations:5.0.1.Final" level="project" /> | |
| <orderEntry type="library" name="Maven: org.hibernate:hibernate-entitymanager:5.0.7.Final" level="project" /> | |
| <orderEntry type="library" name="Maven: org.hibernate:hibernate-validator:5.2.1.Final" level="project" /> | |
| <orderEntry type="library" name="Maven: javax.validation:validation-api:1.1.0.Final" level="project" /> | |
| <orderEntry type="library" name="Maven: com.fasterxml:classmate:1.1.0" level="project" /> | |
| <orderEntry type="library" name="Maven: c3p0:c3p0:0.9.1.2" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-frontend-jaxws:3.0.1" level="project" /> | |
| <orderEntry type="library" name="Maven: xml-resolver:xml-resolver:1.2" level="project" /> | |
| <orderEntry type="library" name="Maven: asm:asm:3.3.1" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.cxf:cxf-core:3.0.1" level="project" /> | |
| <orderEntry type="library" name="Maven: org.codehaus.woodstox:woodstox-core-asl:4.4.0" level="project" /> | |
| <orderEntry type="library" name="Maven: org.codehaus.woodstox:stax2-api:3.1.4" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.ws.xmlschema:xmlschema-core:2.1.0" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-bindings-soap:3.0.1" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-wsdl:3.0.1" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-databinding-jaxb:3.0.1" level="project" /> | |
| <orderEntry type="library" name="Maven: com.sun.xml.bind:jaxb-impl:2.2.10-b140310.1920" level="project" /> | |
| <orderEntry type="library" name="Maven: com.sun.xml.bind:jaxb-core:2.2.10-b140310.1920" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-bindings-xml:3.0.1" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-frontend-simple:3.0.1" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-ws-addr:3.0.1" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-ws-policy:3.0.1" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.neethi:neethi:3.0.3" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-transports-http:3.0.1" level="project" /> | |
| <orderEntry type="library" name="Maven: log4j:log4j:1.2.12" level="project" /> | |
| <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.6.6" level="project" /> | |
| <orderEntry type="library" name="Maven: org.slf4j:slf4j-log4j12:1.6.6" level="project" /> | |
| <orderEntry type="library" name="Maven: javax.mail:mail:1.4.4" level="project" /> | |
| <orderEntry type="library" name="Maven: javax.activation:activation:1.1" level="project" /> | |
| <orderEntry type="library" name="Maven: commons-lang:commons-lang:2.6" level="project" /> | |
| <orderEntry type="library" name="Maven: org.codehaus.xfire:xfire-core:1.2.6" level="project" /> | |
| <orderEntry type="library" name="Maven: wsdl4j:wsdl4j:1.6.1" level="project" /> | |
| <orderEntry type="library" name="Maven: jaxen:jaxen:1.1-beta-9" level="project" /> | |
| <orderEntry type="library" name="Maven: xerces:xmlParserAPIs:2.6.2" level="project" /> | |
| <orderEntry type="library" name="Maven: xerces:xercesImpl:2.6.2" level="project" /> | |
| <orderEntry type="library" name="Maven: stax:stax-api:1.0.1" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.ws.commons:XmlSchema:1.1" level="project" /> | |
| <orderEntry type="library" name="Maven: org.codehaus.woodstox:wstx-asl:3.2.0" level="project" /> | |
| <orderEntry type="library" name="Maven: jdom:jdom:1.0" level="project" /> | |
| <orderEntry type="library" name="Maven: commons-httpclient:commons-httpclient:3.0" level="project" /> | |
| <orderEntry type="library" name="Maven: dom4j:dom4j:1.6" level="project" /> | |
| <orderEntry type="library" name="Maven: xml-apis:xml-apis:1.0.b2" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.poi:poi:3.11" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml:3.11" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml-schemas:3.11" level="project" /> | |
| <orderEntry type="library" name="Maven: org.apache.xmlbeans:xmlbeans:2.6.0" level="project" /> | |
| <orderEntry type="library" name="Maven: com.oracle:ojdbc14:10.2.0.4.0" level="project" /> | |
| <orderEntry type="library" scope="PROVIDED" name="Maven: javax.servlet:servlet-api:2.5" level="project" /> | |
| <orderEntry type="library" scope="PROVIDED" name="Maven: javax.servlet.jsp:jsp-api:2.0" level="project" /> | |
| <orderEntry type="library" name="Maven: net.sf.ehcache:ehcache-core:2.6.6" level="project" /> | |
| </component> | |
| </module> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <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"> | |
| <parent> | |
| <artifactId>jk28_parent</artifactId> | |
| <groupId>cn.itcast.jk</groupId> | |
| <version>0.0.1-SNAPSHOT</version> | |
| </parent> | |
| <modelVersion>4.0.0</modelVersion> | |
| <groupId>cn.itcast.jk</groupId> | |
| <artifactId>jk28_dao</artifactId> | |
| <version>0.0.1-SNAPSHOT</version> | |
| <packaging>war</packaging> | |
| <name>jk28_dao Maven Webapp</name> | |
| <!-- FIXME change it to the project's website --> | |
| <url>http://www.example.com</url> | |
| <properties> | |
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
| <maven.compiler.source>1.7</maven.compiler.source> | |
| <maven.compiler.target>1.7</maven.compiler.target> | |
| </properties> | |
| <dependencies> | |
| <dependency> | |
| <groupId>junit</groupId> | |
| <artifactId>junit</artifactId> | |
| <version>4.11</version> | |
| <scope>test</scope> | |
| </dependency> | |
| <dependency> | |
| <groupId>cn.itcast.jk</groupId> | |
| <artifactId>jk28_utils</artifactId> | |
| <version>0.0.1-SNAPSHOT</version> | |
| </dependency> | |
| </dependencies> | |
| <build> | |
| <finalName>jk28_dao</finalName> | |
| <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> | |
| <plugins> | |
| <plugin> | |
| <artifactId>maven-clean-plugin</artifactId> | |
| <version>3.0.0</version> | |
| </plugin> | |
| <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --> | |
| <plugin> | |
| <artifactId>maven-resources-plugin</artifactId> | |
| <version>3.0.2</version> | |
| </plugin> | |
| <plugin> | |
| <artifactId>maven-compiler-plugin</artifactId> | |
| <version>3.7.0</version> | |
| </plugin> | |
| <plugin> | |
| <artifactId>maven-surefire-plugin</artifactId> | |
| <version>2.20.1</version> | |
| </plugin> | |
| <plugin> | |
| <artifactId>maven-war-plugin</artifactId> | |
| <version>3.2.0</version> | |
| </plugin> | |
| <plugin> | |
| <artifactId>maven-install-plugin</artifactId> | |
| <version>2.5.2</version> | |
| </plugin> | |
| <plugin> | |
| <artifactId>maven-deploy-plugin</artifactId> | |
| <version>2.8.2</version> | |
| </plugin> | |
| </plugins> | |
| </pluginManagement> | |
| </build> | |
| </project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package cn.itcast.jk.dao; | |
| import cn.itcast.jk.utils.Page; | |
| import java.io.Serializable; | |
| import java.util.Collection; | |
| import java.util.List; | |
| /** | |
| * @Description: | |
| * @Author: 传智播客 java学院 传智.宋江 | |
| * @Company: http://java.itcast.cn | |
| * @CreateDate: 2014年10月31日 | |
| */ | |
| public interface BaseDao { | |
| //查询所有,带条件查询 | |
| public <T> List<T> find(String hql, Class<T> entityClass, Object[] params); | |
| //获取一条记录 | |
| public <T> T get(Class<T> entityClass, Serializable id); | |
| //分页查询,将数据封装到一个page分页工具类对象 | |
| public <T> Page<T> findPage(String hql, Page<T> page, Class<T> entityClass, Object[] params); | |
| //新增和修改保存 | |
| public <T> void saveOrUpdate(T entity); | |
| //批量新增和修改保存 | |
| public <T> void saveOrUpdateAll(Collection<T> entitys); | |
| //单条删除,按id | |
| public <T> void deleteById(Class<T> entityClass, Serializable id); | |
| //批量删除 | |
| public <T> void delete(Class<T> entityClass, Serializable[] ids); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package cn.itcast.jk.dao.impl; | |
| import java.io.Serializable; | |
| import java.util.Collection; | |
| import java.util.List; | |
| import cn.itcast.jk.utils.Page; | |
| import org.hibernate.Query; | |
| import org.hibernate.Session; | |
| import org.hibernate.SessionFactory; | |
| import cn.itcast.jk.dao.BaseDao; | |
| /** | |
| * @Description: | |
| * @Author: 传智播客 java学院 传智.宋江 | |
| * @Company: http://java.itcast.cn | |
| * @CreateDate: 2014年10月31日 | |
| */ | |
| public class BaseDaoImpl implements BaseDao{ | |
| private SessionFactory sessionFactory; | |
| public void setSessionFactory(SessionFactory sessionFactory) { | |
| this.sessionFactory = sessionFactory; | |
| } | |
| public Session getSession() { | |
| return sessionFactory.getCurrentSession(); | |
| } | |
| //带条件查询 | |
| public <T> List<T> find(String hql, Class<T> entityClass, Object[] params) { | |
| Query query = this.getSession().createQuery(hql); | |
| if(params!=null){ | |
| for (int i = 0; i < params.length; i++) { | |
| query.setParameter(i, params[i]); | |
| } | |
| } | |
| return (List<T>) query.list(); | |
| } | |
| //获取一条,根据主键id | |
| public <T> T get(Class<T> entityClass, Serializable id) { | |
| return (T) this.getSession().get(entityClass, id); | |
| } | |
| //分页查询,查询两次,一次查询总数,一次查询分页记录 | |
| public <T> Page<T> findPage(String hql, Page<T> page, Class<T> entityClass, Object[] params){ | |
| Query query = this.getSession().createQuery(hql); | |
| if(params!=null){ | |
| for (int i = 0; i < params.length; i++) { | |
| query.setParameter(i, params[i]); | |
| } | |
| } | |
| //查询一次,获取记录总数 | |
| int count = query.list().size(); | |
| page.setTotalRecord(count); | |
| //设置分页 | |
| query.setFirstResult((page.getPageNo()-1)*page.getPageSize()); //设置开始位置 | |
| query.setMaxResults(page.getPageSize()); //设置获取几条 | |
| page.setResults((List<T>)query.list()); | |
| return page; | |
| } | |
| //新增和修改,hibernate根据id是否为null自动判断 | |
| public <T> void saveOrUpdate(T entity) { | |
| this.getSession().saveOrUpdate(entity); | |
| } | |
| //集合保存,这时新增还是修改,就自动判断,调用时是否简洁。适合批量新增和修改时。(Mrecord控件) | |
| public <T> void saveOrUpdateAll(Collection<T> entitys){ | |
| for(T entity : entitys){ | |
| this.saveOrUpdate(entity);//为什么hibernate批量操作时,要用循环一条一条记录去更新? | |
| } | |
| } | |
| //按主键id删除 | |
| public <T> void deleteById(Class<T> entityClass, Serializable id) { | |
| this.getSession().delete(get(entityClass, id)); | |
| } | |
| //批量删除 | |
| public <T> void delete(Class<T> entityClass, Serializable[] ids) { | |
| for(Serializable s : ids){ | |
| deleteById(entityClass, s); | |
| } | |
| } | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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:p="http://www.springframework.org/schema/p" | |
| xmlns:context="http://www.springframework.org/schema/context" | |
| xmlns:tx="http://www.springframework.org/schema/tx" | |
| xmlns:aop="http://www.springframework.org/schema/aop" | |
| xsi:schemaLocation="http://www.springframework.org/schema/beans | |
| http://www.springframework.org/schema/beans/spring-beans.xsd | |
| http://www.springframework.org/schema/aop | |
| http://www.springframework.org/schema/aop/spring-aop.xsd | |
| http://www.springframework.org/schema/tx | |
| http://www.springframework.org/schema/tx/spring-tx.xsd | |
| http://www.springframework.org/schema/context | |
| http://www.springframework.org/schema/context/spring-context.xsd"> | |
| <!-- BaseDao --> | |
| <bean id="baseDao" class="cn.itcast.jk.dao.impl.BaseDaoImpl"> | |
| <property name="sessionFactory" ref="sessionFactory"></property> | |
| </bean> | |
| </beans> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <body> | |
| <h2>Hello World!</h2> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE web-app PUBLIC | |
| "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" | |
| "http://java.sun.com/dtd/web-app_2_3.dtd" > | |
| <web-app> | |
| <display-name>Archetype Created Web Application</display-name> | |
| </web-app> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment