spring-boot入门整合jpa基于maven


先附上项目代码结构

spring-boot入门整合jpa基于maven_第1张图片




pom文件配置:

  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  4.0.0
  project_spring
  project_spring
  war
  0.0.1-SNAPSHOT
  project_spring Maven Webapp
  http://maven.apache.org
 
org.springframework.boot
spring-boot-starter-parent
1.3.0.M1





UTF-8
1.8





org.springframework.boot
spring-boot-starter-data-jpa




mysql
mysql-connector-java
5.1.21


com.google.guava
guava
18.0






org.springframework.boot
spring-boot-starter-web




org.springframework.boot
spring-boot-starter-test
test







org.springframework.boot
spring-boot-maven-plugin



配置文件application.properties

spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost/springboot?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&autoReconnect=true&failOverReadOnly=false
spring.datasource.username=root
spring.datasource.password=
#1
spring.jpa.hibernate.ddl-auto=update
#2
spring.jpa.show-sql=true
spring.jackson.serialization.indent_output=true


添加spring boot 的启动类:Application

package com.htf;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import com.htf.dao.PersonRepository;
import com.htf.support.CustomRepositoryFactoryBean;


@SpringBootApplication
@EnableJpaRepositories(repositoryFactoryBeanClass = CustomRepositoryFactoryBean.class)
public class Application {
@Autowired
PersonRepository personRepository;

public static void main(String[] args) {
  SpringApplication.run(Application.class, args);
}
}

实体类:

spring-boot入门整合jpa基于maven_第2张图片

访问http://localhost:8080/q1?address=合肥

spring-boot入门整合jpa基于maven_第3张图片


剩余的不一一概述。。项目源码地址>>>>>

http://download.csdn.net/detail/a295277302/9862857

mysql脚本

insert into person(name,age,address) values('汪云飞',32,'合肥');
insert into person(name,age,address) values('xx',31,'北京');
insert into person(name,age,address) values('yy',30,'上海');
insert into person(name,age,address) values('zz',29,'南京');
insert into person(name,age,address) values('aa',28,'武汉');
insert into person(name,age,address) values('bb',27,'合肥');

你可能感兴趣的:(SPRING)