springboot后台服务搭建(三 整合mysql、spring-data-jpa)

总览:https://blog.csdn.net/qq_22037575/article/details/86687765

本文概要:springboot2.x 整合 mysql、spring-data-jpa

码云:https://gitee.com/RichterGit/csdn/tree/master/springboot-radmin/003/

目录

1.新建数据库与用户角色表

2.pom导入依赖

3.全局配置

4.业务分层

5.访问


1.新建数据库与用户角色表

  新建数据库 csdn_radmin

新建角色表 role 

drop table if exists role;

/*==============================================================*/
/* Table: role                                                  */
/*==============================================================*/
create table role
(
   id                   bigint not null,
   name                 varchar(50) not null comment '角色名',
   alias                varchar(50) not null comment '别名',
   primary key (id)
);

alter table role comment '角色';

插入三条数据 超级管理员、后台管理员、普通用户 

 

2.pom导入依赖

导入jdbc依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

 导入 mysql 依赖

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <scope>runtime</scope>
</dependency>

 导入 spring-data-jpa 依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

 

3.全局配置

配置 jdbc与 mysql

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/csdn_radmin?characterEncoding=utf8&useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=123456

配置 spring-data-jpa

spring.jpa.database=mysql
spring.jpa.show-sql=true

 

这里为了让全局配置文件的语句更有层次感,把 application.properties重命名为 application.yml 

 

 

4.业务分层

后台使用分层思想,我这里分别新建 domain包、repository包、service包

domain:用来存放实体

repository:用来存放与 spring-data-jpa相关的接口

service:用来存放实现业务功能的业务类

 

 

 

5.访问

全部评论

相关推荐

好像有点准
我推的MK:感觉这个表格呢好像有用又好像没用,真有offer了不管加班多么严重也得受着,没offer管他加班什么样也只能看看,反正轮不到我选
点赞 评论 收藏
分享
03-12 13:51
南昌大学 Java
点赞 评论 收藏
分享
04-15 23:42
中山大学 Java
ResourceUtilization:过几天楼主就会捧着一堆offer来问牛友们该怎么选辣
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务