您现在的位置是:主页 > news > 网站的线下推广怎么做/网络营销策略理论有哪些

网站的线下推广怎么做/网络营销策略理论有哪些

admin2025/5/15 12:11:33news

简介网站的线下推广怎么做,网络营销策略理论有哪些,郴州市第四人民医院,现在的网站开发方式什么是Hibernate?是 Gavin King 开发的一套对于持久层操作的自动的 ORM 框架。什么是JPA?由 Sun 公司提供了一对对于持久层操作的标准(接口文档)什么是Hibernate JPA?是在 Hibernate3.2 版本那种提供了对于 JPA 的标准的实现。提供了一套按照 JPA 标准来…

网站的线下推广怎么做,网络营销策略理论有哪些,郴州市第四人民医院,现在的网站开发方式什么是Hibernate?是 Gavin King 开发的一套对于持久层操作的自动的 ORM 框架。什么是JPA?由 Sun 公司提供了一对对于持久层操作的标准(接口文档)什么是Hibernate JPA?是在 Hibernate3.2 版本那种提供了对于 JPA 的标准的实现。提供了一套按照 JPA 标准来…

什么是Hibernate?
是 Gavin King 开发的一套对于持久层操作的自动的 ORM 框架。

什么是JPA?
由 Sun 公司提供了一对对于持久层操作的标准(接口+文档)

什么是Hibernate JPA?
是在 Hibernate3.2 版本那种提供了对于 JPA 的标准的实现。提供了一套按照 JPA 标准来实现持久层开发的 API

什么是Spring Data?
是spring的一个子项目,用来简化数据库访问,支持nosql和关系数据库存储,其主要目标是使数据库的访问变得方便快捷

什么是Spring Data JPA?
Spring Data JPA构建并增强了JPA,简化数据访问层,智能spring存储库接口

什么是Spring Data Redis
提供了redis配置

整合springData

配置文件applicationContext.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.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"><!-- 配置读取properties文件的工具类 --><context:property-placeholder location="classpath:jdbc.properties"/><!-- 配置c3p0数据库连接池 --><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"><property name="jdbcUrl" value="${jdbc.url}"></property><property name="driverClass" value="${jdbc.driver.class}"></property><property name="user" value="${jdbc.username}"></property><property name="password" value="${jdbc.password}"></property></bean><!-- 配置hibernate的sessionfactory --><bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"><property name="dataSource" ref="dataSource"></property><!-- 配置与hibernate相关的内容,如显示sql语句,开启正向工程 --><property name="hibernateProperties"><props><!-- 显示当前执行的sql语句 --><prop key="hibernate.show_sql">true</prop><!-- 开启正向工程 --><prop key="hibernate.hbm2ddl.auto">update</prop></props></property><!-- 扫描实体所在的包 --><property name="packagesToScan"><list><value>com.bjsxt.pojo</value></list></property></bean><!-- 配置hibernatetemplate对象 --><bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate"><property name="sessionFactory" ref="sessionFactory"></property></bean><!-- 配置hibernate的事务管理器 --><bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory"></property></bean><!-- 配置开启事务注解处理 --><tx:annotation-driven transaction-manager="transactionManager"/><!-- 配置springIOC的注解扫描 --><context:component-scan base-package="com.bjsxt"></context:component-scan>
</beans>

项目结构

cd8333d637c617217fa69990e14ad657.png

dao层实现类:

package com.bjsxt.dao.impl;import java.util.List;import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;import com.bjsxt.dao.UserDao;
import com.bjsxt.pojo.Users;
@Repository
public class UserDaoImpl extends HibernateDaoSupport implements UserDao {@Autowiredprivate HibernateTemplate hibernateTemplate;@Overridepublic void insertUsers(Users users) {// TODO Auto-generated method stubthis.hibernateTemplate.save(users);}@Overridepublic void updateUsers(Users users) {// TODO Auto-generated method stubthis.hibernateTemplate.update(users);}@Overridepublic void deleteUsers(Users users) {// TODO Auto-generated method stubthis.hibernateTemplate.delete(users);}@Overridepublic Users selectUsersById(Integer userid) {// TODO Auto-generated method stubreturn this.hibernateTemplate.get(Users.class, userid);}@Overridepublic List<Users> selectByName(String username) {Session session = this.hibernateTemplate.getSessionFactory().getCurrentSession();Query query = session.createQuery("from Users where username = :abc");Query queryTemp = query.setString("abc", username);return queryTemp.list();}@Overridepublic List<Users> selectByNameUseSQL(String username) {Session session = this.hibernateTemplate.getSessionFactory().getCurrentSession();Query query = session.createSQLQuery("select * from t_users where username = ?").addEntity(Users.class);return query.list();}}

test类

package com.bjsxt.test;import java.util.List;import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;import com.bjsxt.dao.UserDao;
import com.bjsxt.pojo.Users;@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class UserDaoTemplateTest {@Autowiredprivate UserDao userDao;/** 添加用户*/@Test@Transactional@Rollback(false)public void testInsertUsers() {Users users = new Users();users.setUserage(20);users.setUsername("zc");this.userDao.insertUsers(users);}//hql测试@Test@Transactional@Rollback(false)public void testselectByName() {List<Users> list = this.userDao.selectByName("zc");for (Users users : list) {System.out.println(users);}}//sql测试@Test@Transactionalpublic void testSelectByNameUseSQL() {List<Users> list = this.userDao.selectByNameUseSQL("zc");for (Users users : list) {System.out.println(users);}}}

整合JPA

配置文件:

<?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.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"><!-- 配置读取properties文件的工具类 --><context:property-placeholder location="classpath:jdbc.properties"/><!-- 配置c3p0数据库连接池 --><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"><property name="jdbcUrl" value="${jdbc.url}"></property><property name="driverClass" value="${jdbc.driver.class}"/><property name="user" value="${jdbc.username}"/><property name="password" value="${jdbc.password}"/></bean><!-- Spring整合JPA  配置EntityManagerFactory--><bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"><property name="dataSource" ref="dataSource"></property><property name="jpaVendorAdapter"><bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"><!-- hibernate相关的属性的注入 --><!-- 配置数据库类型 --><property name="database" value="MYSQL" /><!-- 正向工程 自动创建表 --><property name="generateDdl" value="true" /><!-- 显示执行的SQL --><property name="showSql" value="true" /></bean></property><!-- 扫描实体的包 --><property name="packagesToScan"><list><value>com.bjsxt.pojo</value></list></property></bean><!-- 配置Hibernate的事务管理器 --><bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"><property name="entityManagerFactory" ref="entityManagerFactory"/></bean><!-- 配置开启注解事务处理 --><tx:annotation-driven transaction-manager="transactionManager"/><!-- 配置springIOC的注解扫描 --><context:component-scan base-package="com.bjsxt"/><!-- Spring Data JPA 的配置 --><!-- base-package:扫描dao接口所在的包 --><jpa:repositories base-package="com.bjsxt.dao"/>
</beans>

dao层实现类:

package com.bjsxt.dao.impl;import java.util.List;import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;import com.bjsxt.dao.UsersDao;
import com.bjsxt.pojo.Users;
@Repository
public class UsersDaoImpl implements UsersDao {@PersistenceContext(name="entityManagerFactory")private EntityManager entityManager;@Overridepublic void insertUsers(Users users) {// TODO Auto-generated method stubthis.entityManager.persist(users);}@Overridepublic void updateUsers(Users users) {// TODO Auto-generated method stub}@Overridepublic void deleteUsers(Users users) {// TODO Auto-generated method stub}@Overridepublic Users selectUsersById(Integer userid) {// TODO Auto-generated method stubreturn this.entityManager.find(Users.class, userid);}@Overridepublic List<Users> selectUserByName(String username) {return this.entityManager.createQuery(" from Users where username = :zc").setParameter("zc", username).getResultList();}@Overridepublic List<Users> selectUserByNameUseSQL(String username) {// TODO Auto-generated method stubreturn null;}@Overridepublic List<Users> selectUserByNameUseCriteria(String username) {//CriteriaBuilder对象:创建一个CriteriaQuery,创建查询条件。CriteriaBuilder builder = this.entityManager.getCriteriaBuilder();//CriteriaQuery对象:执行查询的Criteria对象CriteriaQuery<Users> query = builder.createQuery(Users.class);//获取要查询的实体类的对象Root<Users> root = query.from(Users.class);//封装查询条件Predicate cate = builder.equal(root.get("username"), username);query.where(cate);//执行查询TypedQuery<Users> typeQuery = this.entityManager.createQuery(query);return typeQuery.getResultList();}}

其中有部分方法未实现

package com.bjsxt.test;import java.util.List;import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;import com.bjsxt.dao.UsersDao;
import com.bjsxt.pojo.Users;@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class TestJPA {@Autowiredprivate UsersDao usersDao;//添加@Test@Transactional@Rollback(false)public void testInsert() {Users users = new Users();users.setUserage(20);users.setUsername("zc");this.usersDao.insertUsers(users);}@Test@Transactionalpublic void testSelectUserByNameUseCriteria(){List<Users> list = this.usersDao.selectUserByNameUseCriteria("zc");for (Users users : list) {System.out.println(users);}}
}