- 浏览: 2399 次
- 来自: ...
文章分类
<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd "> <!-- 配置eclipselink entityManagerFactory --> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean" > <property name="persistenceUnitName" value="WebApplication2PU" /> <!-- property name="loadTimeWeaver" ref="loadTimeWeaver" / --> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter"> <property name="showSql" value="false" /> <property name="generateDdl" value="false" /> </bean> </property> <property name="jpaDialect"> <bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" /> </property> </bean> <!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> <!-- Needed so the @PersistenceUnit annotation is recognized --> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/> <!-- 采用@Transaction注解的方式使用事务 --> <tx:annotation-driven transaction-manager="transactionManager"/> <!-- tx:annotation-driven mode="aspectj" /> <context:load-time-weaver aspectj-weaving="on"/ --> <!-- Activates scanning of @Autowired --> <context:annotation-config/> <!-- Activates scanning of @Repository --> <context:component-scan base-package="com.stuke.DAO"/> <!-- need agent--> <!--context:load-time-weaver weaver-class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" / --> <bean class="com.stuke.DAO.Impl.AdminTJpaController" id="admintJpa" /> </beans><?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" 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_3_0.xsd"> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>*.htm</url-pattern> </servlet-mapping> <session-config> <session-timeout> 30 </session-timeout> </session-config> <welcome-file-list> <welcome-file>redirect.jsp</welcome-file> </welcome-file-list> </web-app>
!----------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<!-- Imports user-defined @Controller beans that process client requests -->
<beans:import resource="controllers.xml" />
</beans:beans>
!---------------------------------------------------------------------------------------------------------
<?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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- Scans within the base package of the application for @Components to configure as beans -->
<context:component-scan base-package="com.stuke.action" />
</beans>
!--------------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="AppPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.stuke.entity.WebConfig</class>
<class>com.stuke.entity.AdminT</class>
<class>com.stuke.entity.BigClass</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:microsoft:sqlserver://127.0.0.1;DatabaseName=dsbk"/>
<property name="javax.persistence.jdbc.password" value="************"/>
<property name="javax.persistence.jdbc.driver" value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
<property name="javax.persistence.jdbc.user" value="dsbk"/>
</properties>
</persistence-unit>
</persistence>
!-----------------------------------------------------------------------------------------------------------------------
package com.stuke.DAO.Impl;
import com.stuke.DAO.IAdminTDAO;
import com.stuke.DAO.Impl.exceptions.NonexistentEntityException;
import com.stuke.DAO.Impl.exceptions.PreexistingEntityException;
import com.stuke.entity.AdminT;
import java.io.Serializable;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.persistence.PersistenceContext;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
/**
*
* @author Administrator
*/
@Repository
@Transactional
public class AdminTJpaController implements Serializable,IAdminTDAO {
private static final long serialVersionUID = 1L;
@PersistenceContext
private EntityManager em;
public void create(AdminT adminT) throws PreexistingEntityException, Exception {
}
public void edit(AdminT adminT) throws NonexistentEntityException, Exception {
}
public void destroy(Integer id) throws NonexistentEntityException {
}
public List<AdminT> findAdminTEntities() {
return findAdminTEntities(true, -1, -1);
}
public List<AdminT> findAdminTEntities(int maxResults, int firstResult) {
return findAdminTEntities(false, maxResults, firstResult);
}
@SuppressWarnings("unchecked")
private List<AdminT> findAdminTEntities(boolean all, int maxResults, int firstResult) {
try {
CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
cq.select(cq.from(AdminT.class));
Query q = em.createQuery(cq);
if (!all) {
q.setMaxResults(maxResults);
q.setFirstResult(firstResult);
}
return q.getResultList();
} finally {
em.close();
}
}
@Override
public AdminT findAdminT(Integer id) {
Query q=em.createNativeQuery("select * from admin_t",AdminT.class);
/* System.out.println("111111111111");
System.out.println(""+em.isOpen()+":"+em.toString());
System.out.println(em.getEntityManagerFactory().getPersistenceUnitUtil().toString());
System.out.println(em.getProperties().toString());
System.out.println(q.getSingleResult().toString());
*/
return (AdminT)q.getSingleResult();
}
@SuppressWarnings("unchecked")
public int getAdminTCount() {
try {
CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
Root<AdminT> rt = cq.from(AdminT.class);
cq.select(em.getCriteriaBuilder().count(rt));
Query q = em.createQuery(cq);
return ((Long) q.getSingleResult()).intValue();
} finally {
em.close();
}
}
}
!------------------------------------------------------------------------------------------------
*/
package com.stuke.DAO;
import com.stuke.entity.AdminT;
import org.springframework.stereotype.Repository;
/**
*
* @author Administrator
*/
@Repository
public interface IAdminTDAO {
public AdminT findAdminT(Integer id);
}
!--------------------------------------------------------------------------------
package com.stuke.action;
import com.stuke.DAO.IAdminTDAO;
import com.stuke.entity.AdminT;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.portlet.ModelAndView;
/**
*
* @author Administrator
*/
@Controller
@RequestMapping(value="/liruiadmin")
public class AdminTAction {
@Autowired
@Qualifier("admintJpa")
private IAdminTDAO iatDAO;
/**
* 登陆
* @return ModelAndView
*/
//
@RequestMapping(value="login",method=RequestMethod.GET)
public ModelAndView login(AdminT a,Map<String,Object> model){
ModelAndView av=new ModelAndView();
model.put("message","dsd");
av.addAllObjects(model);
a=iatDAO.findAdminT(4);
model.put("admint", a);
return av;
}
@RequestMapping(value="login",method=RequestMethod.POST)
public String loginDo(AdminT a,HttpSession session){
//
session.setAttribute("admin",a.getAdminName());
return "redirect:main.htm";
}
}
相关推荐
在IT行业中,构建高效、可维护的Web应用是至关重要的,而"Maven+SpringMVC+SpringJPA+Hibernate"的组合就是一个常见的解决方案。这个组合提供了全面的开发工具和技术,帮助开发者快速构建基于Java的Web应用程序。...
SpringDataJPA能够与各种JPA供应商(如Hibernate、EclipseLink等)集成,减少了编写持久化层代码的工作量。 **JdbcTemplate**:JdbcTemplate是Spring提供的一个简单但强大的JDBC抽象层,它降低了直接使用JDBC的复杂...
在本项目中,"SpringMvc+Eclipselink+JPA+ActiveMQ+MySQL在线聊天" 实现了一个基于Web的即时通讯系统,模仿了微信的聊天功能。让我们逐一解析这个项目所涉及的关键技术: 1. **Spring MVC**: - Spring MVC是...
Spring框架提供了对JPA的支持,允许开发者选择不同的实现,如Hibernate或EclipseLink。JPA允许我们声明性地定义实体类和它们的关系,简化了数据访问层的代码。 整合这些技术,我们可以创建一个高效、模块化的应用...
JPA(Java Persistence API)是Java平台上的标准持久化API,它的出现是为了统一ORM框架,如Hibernate、EclipseLink等。JPA提供了一套规范,使得开发者可以更容易地在不同的ORM实现之间切换。通过JPA,你可以定义实体...
它定义了实体类、持久化字段、关系映射等概念,通过ORM工具如Hibernate或EclipseLink将这些Java对象映射到数据库表。JPA简化了数据库操作,使得开发更加面向对象,同时提供了事务管理和查询语言JPA Criteria API。 ...
JPA通过ORM(对象关系映射)工具,如Hibernate,EclipseLink等,将Java对象转换为数据库中的记录,反之亦然。这使得开发者无需编写大量的SQL代码,即可进行数据库操作。 在Spring MVC与JPA整合的过程中,主要涉及...
JPA实现通常包括Hibernate、EclipseLink等ORM(Object-Relational Mapping)框架。 "仅进行了简单的配置" 表明这个项目并没有包含复杂的业务逻辑或特定的数据库模型,而是提供了一个基本的环境,方便开发者添加自己...
6. **JPA支持**:Spring也支持Java Persistence API(JPA),这使得开发者可以根据需求选择更适合的ORM(对象关系映射)工具,如Hibernate、EclipseLink等。 7. **MVC与Service层**:在SpringMVC中,Controller通常...
bookapp-nextgen 这是一个小示例 REST 书店应用程序。 它使用非常前沿的技术,...JPA / EclipseLink Spring数据 弹簧框架 4 Spring Java 配置 ModelMapper(用于创建 DTO) SpringMVC 小服务程序 3.1 AngularJS
这使得 Spring 能够与 JPA 提供者(如 EclipseLink 或 Hibernate)进行无缝集成。 7. **Validation**: 为了验证用户输入,`hibernate-validator.jar` 或其他验证库(如 Apache Commons BeanUtils)可能需要。它们...
特别是在该项目中,我们将以Java语言Hibernate为例框架,在描述的项目中将提到其他一些东西,例如eclipseLink,DJango(来自python语言),还具有其他功能,例如MVC,NHibernate(C#)等。 使用的技术 Java 7 ...
PageHelper是一款针对MyBatis的优秀分页插件,它不仅支持MyBatis的分页功能,还支持JPA、Hibernate、EclipseLink等多种ORM框架。PageHelper的优点在于其强大的灵活性和易用性,能够帮助开发者快速实现分页功能,提高...