1.pom依赖

<?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>spring-data-jpa</artifactId>
<groupId>org.maple</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion> <artifactId>jpa-02</artifactId> <properties>
<spring.version>5.0.2.RELEASE</spring.version>
<hibernate.version>5.0.7.Final</hibernate.version>
<slf4j.version>1.6.6</slf4j.version>
<log4j.version>1.2.12</log4j.version>
<c3p0.version>0.9.1.2</c3p0.version>
<mysql.version>5.1.6</mysql.version>
</properties> <dependencies>
<!-- junit单元测试 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency> <!-- spring beg -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.8</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency> <!-- spring对orm框架的支持包-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency> <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> <!-- spring end --> <!-- hibernate beg -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.2.1.Final</version>
</dependency>
<!-- hibernate end --> <!-- c3p0 beg -->
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>${c3p0.version}</version>
</dependency>
<!-- c3p0 end --> <!-- log end -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency> <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency> <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!-- log end --> <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency> <!-- spring data jpa 的坐标-->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.9.0.RELEASE</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency> <!-- el beg 使用spring data jpa 必须引入 -->
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>2.2.4</version>
</dependency> <dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.el</artifactId>
<version>2.2.4</version>
</dependency>
<!-- el end --> <dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
</dependency>
</dependencies> </project>

2.spring配置文件

<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:task="http://www.springframework.org/schema/task"
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/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"> <!--spring 和 spring data jpa的配置--> <!-- 1.创建entityManagerFactory对象交给spring容器管理-->
<bean id="entityManagerFactoty" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<!--配置的扫描的包(实体类所在的包) -->
<property name="packagesToScan" value="org.maple.domain" />
<!-- jpa的实现厂家 -->
<property name="persistenceProvider">
<bean class="org.hibernate.jpa.HibernatePersistenceProvider"/>
</property> <!--jpa的供应商适配器 -->
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<!--配置是否自动创建数据库表 -->
<property name="generateDdl" value="false" />
<!--指定数据库类型 -->
<property name="database" value="MYSQL" />
<!--数据库方言:支持的特有语法 -->
<property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
<!--是否显示sql -->
<property name="showSql" value="true" />
</bean>
</property> <!--jpa的方言 :高级的特性 -->
<property name="jpaDialect" >
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
</property> </bean> <!--2.创建数据库连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="user" value="root"></property>
<property name="password" value="root"></property>
<property name="jdbcUrl" value="jdbc:mysql:///jpa" ></property>
<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
</bean> <!--3.整合spring dataJpa-->
<jpa:repositories base-package="org.maple.dao" transaction-manager-ref="transactionManager"
entity-manager-factory-ref="entityManagerFactoty" ></jpa:repositories> <!--4.配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactoty"></property>
</bean> <!-- 4.txAdvice-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="get*" read-only="true"/>
<tx:method name="find*" read-only="true"/>
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice> <!-- 5.aop-->
<aop:config>
<aop:pointcut id="pointcut" expression="execution(* org.maple.service.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut" />
</aop:config> <!--5.声明式事务 --> <!-- 6. 配置包扫描-->
<context:component-scan base-package="org.maple" ></context:component-scan>
</beans>

3.实体类

package org.maple.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors; import javax.persistence.*; /**
* @author mapleins
* @Date 2019-01-10 20:31
* @Desc
**/
@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
@Accessors(chain = true)
@Entity
@Table(name = "cst_customer")
public class Customer { /**
* @Id:声明主键的配置
* @GeneratedValue:配置主键的生成策略
* strategy
* GenerationType.IDENTITY :自增,mysql
* * 底层数据库必须支持自动增长(底层数据库支持的自动增长方式,对id自增)
* GenerationType.SEQUENCE : 序列,oracle
* * 底层数据库必须支持序列
* GenerationType.TABLE : jpa提供的一种机制,通过一张数据库表的形式帮助我们完成主键自增
* GenerationType.AUTO : 由程序自动的帮助我们选择主键生成策略
* @Column:配置属性和字段的映射关系
* name:数据库表中字段的名称
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "cust_id")
private Long custId; //客户的主键 @Column(name = "cust_name")
private String custName;//客户名称 @Column(name="cust_source")
private String custSource;//客户来源 @Column(name="cust_level")
private String custLevel;//客户级别 @Column(name="cust_industry")
private String custIndustry;//客户所属行业 @Column(name="cust_phone")
private String custPhone;//客户的联系方式 @Column(name="cust_address")
private String custAddress;//客户地址
}

4.dao接口

package org.maple.dao;

import org.maple.domain.Customer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; /**
* @author mapleins
* @Date 2019-01-10 21:20
* @Desc
**/
/**
* 符合SpringDataJpa的dao层接口规范
* JpaRepository<操作的实体类类型,实体类中主键属性的类型>
* * 封装了基本CRUD操作
* JpaSpecificationExecutor<操作的实体类类型>
* * 封装了复杂查询(分页)
*/
public interface CustomerDao extends JpaRepository<Customer,Long>, JpaSpecificationExecutor<Customer> { }

5.测试(CRUD)

package org.maple.test;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.maple.dao.CustomerDao;
import org.maple.domain.Customer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional; import java.util.List; /**
* @author mapleins
* @Date 2019-01-10 21:22
* @Desc
**/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class CustomerDaoTest { @Autowired
private CustomerDao dao; /**
* 查询一个 findOne 根据主键查询
* em.find() :立即加载
*/
@Test
public void findOne(){
Customer one = dao.findOne(3l);
System.out.println(one);
} /**
* 根据id从数据库查询
* @Transactional : 保证getOne正常运行
* getOne:
* em.getReference :延迟加载
* * 返回的是一个客户的动态代理对象
* * 什么时候用,什么时候查询
*/
@Test
@Transactional
public void testGetOne() {
Customer customer = dao.getOne(3l);
System.out.println(customer);
} /**
* save : 保存或者更新
* 根据传递的对象是否存在主键id,
* 如果没有id主键属性:保存
* 存在id主键属性,根据id查询数据,更新数据
*/
@Test
public void testSave() {
Customer customer = new Customer();
customer.setCustName("hasaki");
customer.setCustIndustry("峡谷之巅");
dao.save(customer);
} @Test
public void testUpdate() {
Customer customer = new Customer();
customer.setCustId(5l);
customer.setCustName("hasaki");
customer.setCustIndustry("废铜烂铁");
dao.save(customer);
} /**
* 测试删除
*/
@Test
public void testDelete(){
dao.delete(2l);
} /**
* 查询所有
*/
@Test
public void testFindAll() {
List<Customer> list = dao.findAll();
for(Customer customer : list) {
System.out.println(customer);
}
} /**
* 统计查询
*/
/**
* 测试统计查询:查询客户的总数量
* count:统计总条数
*/
@Test
public void testCount() {
long count = dao.count();//查询全部的客户数量
System.out.println(count);
} /**
* 测试:判断id为4的客户是否存在
* 1. 可以查询以下id为4的客户
* 如果值为空,返回false,如果不为空,返回true
*/
@Test
public void testExists() {
boolean exists = dao.exists(4l);
System.out.println("id为4的客户 是否存在:"+exists);
} }

6.JPQL(配置在接口方法上,使用@Query)

package org.maple.dao;

import org.maple.domain.Customer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; /**
* @author mapleins
* @Date 2019-01-10 21:40
* @Desc 使用Jpql
**/
public interface CustomerDao2 extends JpaRepository<Customer,Long>, JpaSpecificationExecutor<Customer> { /**
* 根据名字查询
*/
@Query("from Customer where custName = ?")
Customer findJpql(String custName); /**
* 根据客户名称和客户id查询客户
* 参数位置需要一致
* 或者
* @Query("from Customer where custName = ?2 and custId = ?1")
* Customer findJpql2(Long id,String custName);
*/
@Query("from Customer where custName = ? and custId = ?")
Customer findJpql2(String custName,Long id); /**
* 使用jpql完成更新操作
* 案例 : 根据id更新,客户的名称
* 更新4号客户的名称,将名称改为“黑马程序员”
*
* sql :update cst_customer set cust_name = ? where cust_id = ?
* jpql : update Customer set custName = ? where custId = ?
*
* @Query : 代表的是进行查询
* * 声明此方法是用来进行更新操作
* @Modifying
* * 当前执行的是一个更新操作
*
*/
@Query("update Customer set custName = ?2 where custId = ?1")
@Modifying
void updateCustomer(Long custId,String custName);
}
package org.maple.test;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.maple.dao.CustomerDao2;
import org.maple.domain.Customer;
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; /**
* @author mapleins
* @Date 2019-01-10 21:42
* @Desc
**/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class CustomerDao2Test { @Autowired
private CustomerDao2 dao; @Test
public void findJpql(){
Customer hasaki = dao.findJpql("hasaki");
System.out.println(hasaki);
} @Test
public void findJpq2(){
Customer hasaki = dao.findJpql2("hasaki",5l);
System.out.println(hasaki);
} /**
* 测试jpql的更新操作
* * springDataJpa中使用jpql完成 更新/删除操作
* * 需要手动添加事务的支持
* * 默认会执行结束之后,回滚事务
* @Rollback : 设置是否自动回滚
* false | true
*/
@Test
@Transactional //添加事务的支持
@Rollback(value = false)
public void testUpdateCustomer() {
dao.updateCustomer(4l,"coward");
}
}

7.SQL语句查询

package org.maple.dao;

import org.maple.domain.Customer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query; import java.util.List; /**
* @author mapleins
* @Date 2019-01-10 21:54
* @Desc 使用Sql
**/
public interface CustomerDao3 extends JpaRepository<Customer,Long>, JpaSpecificationExecutor<Customer> { @Query(value = "select * from cst_customer",nativeQuery = true)
List<Object[]> findSql(); @Query(value = "select * from cst_customer where cust_name like ?1",nativeQuery = true)
List<Object[]> findSql2(String name);
}
package org.maple.test;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.maple.dao.CustomerDao2;
import org.maple.dao.CustomerDao3;
import org.maple.domain.Customer;
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 java.util.Arrays;
import java.util.List; /**
* @author mapleins
* @Date 2019-01-10 21:42
* @Desc
**/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class CustomerDao3Test { @Autowired
private CustomerDao3 dao; @Test
public void findSql(){
List<Object[]> list = dao.findSql();
for (Object[] obj : list) {
System.out.println(Arrays.toString(obj));
}
} @Test
public void findSql2(){
List<Object[]> list = dao.findSql2("%a%");
for (Object[] obj : list) {
System.out.println(Arrays.toString(obj));
}
} }

8.方法名称规则

*我们只需要按照SpringDataJpa提供的方法名称规则定义方法,不需要再配置jpql语句,完成查询
  findBy开头: 代表查询
  对象中属性名称(首字母大写)
  *含义:根据属性名称进行查询

package org.maple.dao;

import org.maple.domain.Customer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import java.util.List; /**
* @author mapleins
* @Date 2019-01-10 22:03
* @Desc
**/
public interface CustomerDao4 extends JpaRepository<Customer,Long>, JpaSpecificationExecutor<Customer> { List<Customer> findCustomerByCustNameLike(String name); Customer findCustomerByCustNameAndCustIndustry(String name,String industry);
}
package org.maple.test;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.maple.dao.CustomerDao;
import org.maple.dao.CustomerDao4;
import org.maple.domain.Customer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional; import java.util.List; /**
* @author mapleins
* @Date 2019-01-10 21:22
* @Desc
**/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class CustomerDao4Test { @Autowired
private CustomerDao4 dao; @Test
public void findLike(){
List<Customer> customers = dao.findCustomerByCustNameLike("%a%");
for (Customer customer : customers) {
System.out.println(customer);
}
} @Test
public void findNameAndIndustry(){
Customer customer = dao.findCustomerByCustNameAndCustIndustry("hasaki","废铜烂铁");
System.out.println(customer);
} }

9.Spec Sort PageRequest

package org.maple.test;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.maple.dao.CustomerDao;
import org.maple.domain.Customer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional; import javax.persistence.criteria.*;
import java.util.List; /**
* @author mapleins
* @Date 2019-01-10 21:22
* @Desc
**/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class CustomerDaoTest { @Autowired
private CustomerDao dao; /**
* 查询单个参数
*/
@Test
public void testSpec(){
Specification<Customer> spec = new Specification<Customer>() {
/**
* 自定义查询条件
* 1.实现Specification接口(提供泛型:查询的对象类型)
* 2.实现toPredicate方法(构造查询条件)
* 3.需要借助方法参数中的两个参数(
* root:获取需要查询的对象属性
* CriteriaBuilder:构造查询条件的,内部封装了很多的查询条件(模糊匹配,精准匹配)
* )
* 案例:根据客户名称查询,查询客户名为hasaki的客户
* 查询条件
* 1.查询方式
* cb对象
* 2.比较的属性名称
* root对象
*
*/
@Override
public Predicate toPredicate(Root<Customer> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
//1.获取比较的属性
Path<Object> custName = root.get("custName");
//2.构造查询条件
/**
* 1.需要比较的属性 path对象
* 2.需要比较的取值
*/
Predicate predicate = cb.equal(custName, "hasaki");
return predicate;
}
};
Customer customer = dao.findOne(spec);
System.out.println(customer);
} /**
* 多条件查询
* 根据名字hasaki 和行业查询 废铜烂铁
*/
@Test
public void testSpec2(){
Specification<Customer> spec = new Specification<Customer>() {
@Override
public Predicate toPredicate(Root<Customer> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
Path<Object> custName = root.get("custName");
Path<Object> custIndustry = root.get("custIndustry");
Predicate p1 = cb.equal(custName, "hasaki");
Predicate p2 = cb.equal(custIndustry, "废铜烂铁");
//and 与
//or 或
Predicate predicate = cb.and(p1, p2);
return predicate;
}
};
Customer customer = dao.findOne(spec);
System.out.println(customer);
} /**
* 模糊查询返回列表
* 查询名字包含r的
* gt lt je le like :得到path ,根据path 指定比较的参数类型,再比较
*/
@Test
public void testSpec3(){
Specification<Customer> spec = new Specification<Customer>() {
@Override
public Predicate toPredicate(Root<Customer> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
Path<Object> custName = root.get("custName");
//path对象指定的参数类型
Predicate predicate = cb.like(custName.as(String.class), "%r%");
return predicate;
}
};
List<Customer> list = dao.findAll(spec);
System.out.println(list);
} /**
* 排序
*/
@Test
public void testSpec4(){
Specification<Customer> spec = new Specification<Customer>() {
@Override
public Predicate toPredicate(Root<Customer> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
Path<Object> custName = root.get("custName");
//path对象指定的参数类型
Predicate predicate = cb.like(custName.as(String.class), "%r%");
return predicate;
}
};
//1.升序或降序 2.属性名
Sort sort = new Sort(Sort.Direction.DESC,"custId");
List<Customer> list = dao.findAll(spec,sort);
System.out.println(list);
} /**
* 分页
*/
@Test
public void testSpec5(){
Specification<Customer> spec = null ;
//分页 从0开始,每页2条
PageRequest pageRequest = new PageRequest(0, 1);
Page<Customer> page = dao.findAll(spec, pageRequest);
System.out.println(page.getContent());//数据集合列表
System.out.println(page.getTotalElements());//总条数
System.out.println(page.getTotalPages());//总页数 } }

<Spring Data JPA>二 Spring Data Jpa的更多相关文章

  1. Spring Boot系列二 Spring @Async异步线程池用法总结

    1. TaskExecutor Spring异步线程池的接口类,其实质是java.util.concurrent.Executor Spring 已经实现的异常线程池: 1. SimpleAsyncT ...

  2. Spring boot 入门二:Spring Boot配置文件详解

    一.自定义属性 当我们创建一个springboot项目的时候,系统默认会为我们在src/main/java/resources目录下创建一个application.properties.同时也支持ym ...

  3. spring boot 学习(二)spring boot 框架整合 thymeleaf

    spring boot 框架整合 thymeleaf spring boot 的官方文档中建议开发者使用模板引擎,避免使用 JSP.因为若一定要使用 JSP 将无法使用. 注意:本文主要参考学习了大神 ...

  4. Spring学习(十二)-----Spring @PostConstruct和@PreDestroy实例

    实现 初始化方法和销毁方法3种方式: 实现标识接口 InitializingBean,DisposableBean(不推荐使用,耦合性太高) 设置bean属性 Init-method destroy- ...

  5. Spring学习(十二)-----Spring Bean init-method 和 destroy-method实例

    实现 初始化方法和销毁方法3种方式: 实现标识接口 InitializingBean,DisposableBean(不推荐使用,耦合性太高) 设置bean属性 Init-method destroy- ...

  6. spring学习笔记二:spring使用构造方法注入(set方式注入)

    项目目录树: 1.spring的依赖包配置 * SPRING_HOME/dist/spring.jar * SPRING_HOME/lib/log4j/log4j-1.2.14.jar * SPRIN ...

  7. Spring Boot系列(二) Spring Boot 之 REST

    Rest (Representational Stat Transer) 是一种软件架构风格. 基础理论 架构特性 性能 可伸缩 简化的统一接口 按需修改 组件通信透明 可移植 可靠性 架构约束 C/ ...

  8. spring boot(五):spring data jpa的使用

    在上篇文章springboot(二):web综合开发中简单介绍了一下spring data jpa的基础性使用,这篇文章将更加全面的介绍spring data jpa 常见用法以及注意事项 使用spr ...

  9. 整合Spring Data JPA与Spring MVC: 分页和排序

    之前我们学习了如何使用Jpa访问关系型数据库.比较完整Spring MVC和JPA教程请见Spring Data JPA实战入门,Spring MVC实战入门. 通过Jpa大大简化了我们对数据库的开发 ...

随机推荐

  1. 51nod 1092【区间dp】

    思路: 简单的区间dp,从小区间到大区间,随便写. 还有一种是那啥,n-LCS...具体不说了,赶时间)))= =. #include <stdio.h> #include <str ...

  2. Spring + MyBaits java.lang.reflect.InvocationTargetException 启动日志报错

    调试发现 实例化 class org.apache.ibatis.logging.slf4j.Slf4jImpl时发生异常,所以 slf4j jar 问题解决: http://www.cnblogs. ...

  3. Fiddler抓取HTTPS设置

    做App测试,用Fiddler进行抓包,以下操作记录如何用手机进行设置使其可以捕捉HTTPS协议. 一.电脑端设置 1.手机和电脑保持统一局域网内 2.配置fiddler允许监听到https 打开Fi ...

  4. 自适应的两端对齐:text-align:justify

    <!DOCTYPE HTML> <html> <head> <title>文本两端对齐 by hongchenok</title> < ...

  5. ACM_扫雷(dfs)

    扫雷 Time Limit: 2000/1000ms (Java/Others) Problem Description: 扫雷这个游戏想必各位都是会玩的吧.简单说一下规则,n行m列的格子地图上有分布 ...

  6. 用python编写的excel拆分小工具

    from datetime import date,datetime from openpyxl import Workbook from openpyxl import load_workbook ...

  7. 机器学习概念之特征选择(Feature selection)之VectorSlicer算法介绍

    不多说,直接上干货! VectorSlicer 算法介绍: VectorSlicer是一个转换器,输入特征向量,输出原始特征向量子集.VectorSlicer接收带有特定索引的向量列,通过对这些索引的 ...

  8. 华容道 noip2013 70分搜索

    题目描述 [问题描述] 小 B 最近迷上了华容道,可是他总是要花很长的时间才能完成一次.于是,他想到用编程来完成华容道:给定一种局面, 华容道是否根本就无法完成,如果能完成, 最少需要多少时间. 小 ...

  9. 前端之HTML样式

    <!doctype html> h5的文档声明 <html> 网页的根标签(根元素 html)--所有的代码都放置在此内 <head> <meta chars ...

  10. macOS 的 JDK 安装问题 (Homebrew)

    Homebrew 介绍 Homebrew 是 macOS 下的一个非常好用的包管理工具, caskroom 则是基于 Homebrew 构建的一个强大的应用程序管理器. 具体用法可以餐参考 像 Mac ...