Spring Boot:搭建一个简单的用户系统(一) - 环境搭建

Spring Boot:搭建一个简单的用户系统

    • 一.用户系统需要哪些接口
    • 二.数据库安装
    • 三.SpringBoot数据库配置
    • 三.redis安装
    • 四.数据库建表
    • 五.注意点

一.用户系统需要哪些接口

Spring Boot:搭建一个简单的用户系统(一) - 环境搭建_第1张图片
我们接口角度看,一个用户系统需要如上图所示的接口,接下来就开始准备工作;

二.数据库安装

本文用的数据库为mysql,具体安装过程就不写了,附一篇博文:https://www.runoob.com/mysql/mysql-install.html
mysql可视化工具推荐navicat for mysql;

三.SpringBoot数据库配置

  1. pom.xml配置
        
		
			org.springframework.boot
			spring-boot-starter-data-jpa
		
		
			mysql
			mysql-connector-java
		
  1. application.properties
#数据库配置
spring.datasource.url=jdbc:mysql://localhost:3306/数据库名
spring.datasource.username=用户名
spring.datasource.password=密码
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.jpa.properties.hibernate.hbm2ddl.auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.show-sql=true

三.redis安装

除了数据库,还用到了redis,安装过程也不写了,附一篇博文自己看:
https://www.runoob.com/redis/redis-install.html
redis可视化工具推荐:rdm;

  1. pom.xml配置
        
		
			org.springframework.boot
			spring-boot-starter-data-redis
			
				
					org.springframework.boot
					spring-boot-starter
				
			
		
        
            org.apache.commons
            commons-pool2
        
  1. application.properties
#Redis数据库索引(默认为0)
spring.redis.database=0
# Redis服务器地址
spring.redis.host=127.0.0.1
# Redis服务器连接端口
spring.redis.port=6379
# Redis服务器连接密码(默认为空)
spring.redis.password=
# 连接池最大连接数(使用负值表示没有限制) 默认 8
spring.redis.lettuce.pool.max-active=8
# 连接池最大阻塞等待时间(使用负值表示没有限制) 默认 -1
spring.redis.lettuce.pool.max-wait=-1
# 连接池中的最大空闲连接 默认 8
spring.redis.lettuce.pool.max-idle=8
# 连接池中的最小空闲连接 默认 0
spring.redis.lettuce.pool.min-idle=0

四.数据库建表

Spring Boot:搭建一个简单的用户系统(一) - 环境搭建_第2张图片
大部分应该不需要说明,着重说几个字段
(1)openid:微信的用户id,但是多平台不一致,不建议使用;
(2)unionid:微信的唯一id,多平台统一,建议绑定微信用这个id,否则后期就会出现账号不统一的问题,在小程序注册的账号和App绑定的账号不是一个账号;

五.注意点

  1. 有时候maven项目拉取失败,怎么叫失败呢,点击下图maven->Dependencies,如果有红色✘,则没有拉去成功,需要查看下你的maven源,如何查看呢;
    Spring Boot:搭建一个简单的用户系统(一) - 环境搭建_第3张图片
    Spring Boot:搭建一个简单的用户系统(一) - 环境搭建_第4张图片
    settings.xml就是maven项目拉取的源地址;

		  
      		alimaven  
      		aliyun maven  
      		http://maven.aliyun.com/nexus/content/groups/public/  
      		central          
    	
  

建议国内的改为aliyun的镜像,速度快不少,而且会减少失败的频率;

工欲善其事必先利其器,把mysql,redis和可视化工具搭建好后,就可以开始接口开发了。

你可能感兴趣的:(java)