SpringBoot整合SpringDataJPA,nginx语法检查源码分析

com.alibaba

druid

1.0.9

2.添加相关的配置


在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的配置文件要简单很多!

3.创建pojo


/**

  • @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 + “]”;

}

}

4.创建dao接口


创建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> {

}

5.创建启动器


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);

}

}

6.单元测试


import com.dpb.spring_boot_data_jpa_demo.dao.UsersRepository;

import com.dpb.spring_boot_data_jpa_demo.pojo.Users;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值