com.alibaba
druid
1.0.9
在application.properties中添加如下配置
jdbc 的相关信息
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/ssm?characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=123456
配置连接池信息
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
配置jpa的相关参数
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
这比我们在Spring中整合SpringDataJPA的配置文件要简单很多!
/**
-
@program: spring-boot-data-jpa-demo
-
@description: pojo
-
@author: 波波烤鸭
-
@create: 2019-05-20 11:15
*/
@Entity
@Table(name=“t_users”)
public class Users {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
@Column(name=“id”)
private Integer id;
@Column(name=“name”)
private String name;
@Column(name=“age”)
private Integer age;
@Column(name=“address”)
private String address;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Override
public String toString() {
return “Users [id=” + id + “, name=” + name + “, age=” + age + “, address=” + address + “]”;
}
}
创建Dao的接口,实现Repository接口
/**
-
@program: spring-boot-data-jpa-demo
-
@description: Dao接口
-
@author: 波波烤鸭
-
@create: 2019-05-20 11:17
*/
import com.dpb.spring_boot_da
【一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义】
ta_jpa_demo.pojo.Users;
import org.springframework.data.jpa.repository.JpaRepository;
/**
-
参数一 T :当前需要映射的实体
-
参数二 ID :当前映射的实体中的OID的类型
*/
public interface UsersRepository extends JpaRepository<Users,Integer> {
}
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringBootDataJpaDemoApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootDataJpaDemoApplication.class, args);
}
}
import com.dpb.spring_boot_data_jpa_demo.dao.UsersRepository;
import com.dpb.spring_boot_data_jpa_demo.pojo.Users;