使用IDEA 搭建一个 SpringBoot + Hibernate + Gradle 项目
现在创建个项目:


勾上 自已 需要东西。(这里作为演示)



maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
关闭项目,重新打开。

等待,依赖下载完成。

在 templates 文件夹 中 加入 一个 index.html 的文件


到这里,还要配置一下 数据库连接(刚刚加了 jpa),我这里作为演示使用的是 Mariadb数据库

增加,依赖...

implementation('org.springframework.boot:spring-boot-starter-actuator')
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
implementation('org.springframework.boot:spring-boot-starter-web')
testImplementation('org.springframework.boot:spring-boot-starter-test')
implementation('org.springframework.boot:spring-boot-starter-thymeleaf')//视图引擎
compile group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '2.3.0'

# 配置 Tomcat 端口号
server.port=8881
# 数据库驱动
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
# 连接数据库
spring.datasource.url=jdbc:mariadb://localhost:3306/test
# 用户名
spring.datasource.username=oukele
# 密码
spring.datasource.password=oukele # 要标注它是那个一个数据库,如果不标注它,它会使用MySQL的,因为我们是创建MySQL数据
spring.jpa.database-platform=org.hibernate.dialect.MariaDB102Dialect
在 templates 文件夹 中 新建一个 index.html 页面

然后,启动。。

启动,成功


OK啦。
现在,我们去访问数据库,拿到数据吧。
项目结构:

entity包中的User 类
package com.oukele.springboot.springboot_demo2.entity; import javax.persistence.*; @Entity
@Table(name = "user")//数据库的表名
public class User { @Id
@GeneratedValue(strategy = GenerationType.IDENTITY)//自动增长主键
private int id; @Column(name = "username")//数据库的字段名,数据库 不区分大小写 这个 要注意
private String name; private String password; public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
}
}
dao 包中的 UserMapper 接口
package com.oukele.springboot.springboot_demo2.dao; import com.oukele.springboot.springboot_demo2.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; public interface UserMapper extends JpaRepository<User,Integer> { }
service包中的 UserService 接口
package com.oukele.springboot.springboot_demo2.service;
import com.oukele.springboot.springboot_demo2.entity.User;
import java.util.List;
public interface UserService {
List<User> listAll();
}
serviceImp 包中的 UserServiceImp 类
package com.oukele.springboot.springboot_demo2.serviceImp; import com.oukele.springboot.springboot_demo2.dao.UserMapper;
import com.oukele.springboot.springboot_demo2.entity.User;
import com.oukele.springboot.springboot_demo2.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import java.util.List; @Service
public class UserServiceImp implements UserService { @Autowired
private UserMapper userMapper; @Override
public List<User> listAll() {
return userMapper.findAll();
}
}
controller 包 中 的 UserController 类
package com.oukele.springboot.springboot_demo2.controller; import com.oukele.springboot.springboot_demo2.entity.User;
import com.oukele.springboot.springboot_demo2.serviceImp.UserServiceImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import java.util.List; @RestController
public class UserController { @Autowired
private UserServiceImp userServiceImp; @RequestMapping(path = "list",method = RequestMethod.GET)
public List<User> getList(){
return userServiceImp.listAll();
} }
重新启动,运行结果:

。这样就快速完成了一个 SpringBoot项目。
示例源码下载地址:https://github.com/oukele/SpringBoot-demo1
使用IDEA 搭建一个 SpringBoot + Hibernate + Gradle 项目的更多相关文章
- 使用IDEA 搭建一个SpringBoot + Hibernate + Gradle
---恢复内容开始--- 打开IDEA创建一个新项目: 第一步: 第二步: 第三步: 最后一步: 如果下载的时候时间太久.可以找到build.gradle文件,添加以下代码.如下图 maven{ ur ...
- 手把手搭建一个完整的javaweb项目
手把手搭建一个完整的javaweb项目 本案例使用Servlet+jsp制作,用MyEclipse和Mysql数据库进行搭建,详细介绍了搭建过程及知识点. 下载地址:http://download.c ...
- 小记如何有顺序的搭建一个Spring的web项目
如何有顺序的搭建一个Spring的web项目 一.新建一个简单的maven,war工程 eclipse下如有报错,右键 Deployment 单击 Generate 生成web.xml后可解决报错 二 ...
- 快速搭建一个基于react的项目
最近在学习react,快速搭建一个基于react的项目 1.创建一个放项目文件夹,用编辑器打开 2.打开集成终端输入命令: npm install -g create-react-app 3. cre ...
- react全家桶从0搭建一个完整的react项目(react-router4、redux、redux-saga)
react全家桶从0到1(最新) 本文从零开始,逐步讲解如何用react全家桶搭建一个完整的react项目.文中针对react.webpack.babel.react-route.redux.redu ...
- 5分钟快速搭建一个springboot的项目
现在开发中90%的人都在使用springboot进行开发,你有没有这样的苦恼,如果让你新建一个springboot开发环境的项目,总是很苦恼,需要花费很长时间去调试.今天来分享下如何快速搭建. 一 ...
- 用Eclipse 搭建一个Maven Spring SpringMVC 项目
1: 先创建一个maven web 项目: 可以参照之前的文章: 用Maven 创建一个 简单的 JavaWeb 项目 创建好之后的目录是这样的; 2: 先配置maven 修改pom.xml & ...
- springboot入门(一)--快速搭建一个springboot框架
原文出处 前言在开始之前先简单介绍一下springboot,springboot作为一个微框架,它本身并不提供Spring框架的核心特性以及扩展功能,只是用于快速.敏捷地开发新一代基于Spring框架 ...
- 带你搭建一个简单的mybatis项目:IDEA+spring+springMVC+mybatis+Mysql
最近小编有点闲,突发奇想想重温一下mybatis,然后在脑海中搜索了一下,纳尼,居然不太会用了,想到这里都是泪啊!!现在我所呆的的公司使用的是springboot+hebinate,编程都是使用的JP ...
随机推荐
- 手把手教你用vue-clic3搭建vue-element-admin项目
下载element-admin框架 点击该地址:https://github.com/PanJiaChen/vue-element-admin 用git clone https://github.co ...
- 修改Jupyter Notebook默认目录
Jupyter Notebook每次打开都需要先进到相应的文件夹再打开 很不方便 首先进入到Jupyter的安装目录,我的是 D:\Anaconda3\Scripts 然后,输入命令: jupyter ...
- [bzoj3043]IncDec Sequence_差分
IncDec Sequence 题目大意:给定一个长度为n的数列{a1,a2...an},每次可以选择一个区间[l,r],使这个区间内的数都加一或者都减一.问至少需要多少次操作才能使数列中的所有数都一 ...
- 阿里云服务器 lnmp安装流程
nginx安装:wget http://nginx.org/download/nginx-1.12.2.tar.gztar zxvf nginx-1.12.2.tar.gzcd nginx-1.12. ...
- Redis(1.8)Redis与mysql的数据库同步(缓存穿透与缓存雪崩)
[1]缓存穿透与缓存雪崩 [1.1]缓存和数据库间数据一致性问题 分布式环境下(单机就不用说了)非常容易出现缓存和数据库间的数据一致性问题,针对这一点的话,只能说,如果你的项目对缓存的要求是强一致性的 ...
- oracle——学习之路(oracle内置函数)
oracle与很多内置函数,主要分为单行函数与集合函数. 首先要提一下dual表,它oracle的一个表,没有什么实质的东西,不能删除它,否则会造成Oracle无法启动等问题,他有很大用处,可以利用它 ...
- Photon Server初识(一) ---C#链接MySql
环境: 1.MAC电脑,JetBrains Rider编辑器 2.本地MySql5.7 (开始安装8.1发现使用 NHibernate 映射链接不上) 一.新建工程 二.引入dll包(MySQL.Da ...
- dmesg、stat命令
一.dmesg:系统启动异场诊断. 语法: dmesg [选项] 参数: -C,-清除 清除环形缓冲区. -c,--read-clear ...
- Array Product CodeForces - 1042C (细节)
#include <iostream> #include <sstream> #include <algorithm> #include <cstdio> ...
- Office/Visio/Project 2019 专业版iso
一.Microsoft Office 2019专业增强版1.简体中文版Office Professional Plus 2019 (x86 and x64) – DVD (Chinese-Simpli ...