现在创建个项目:

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

 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 项目的更多相关文章

  1. 使用IDEA 搭建一个SpringBoot + Hibernate + Gradle

    ---恢复内容开始--- 打开IDEA创建一个新项目: 第一步: 第二步: 第三步: 最后一步: 如果下载的时候时间太久.可以找到build.gradle文件,添加以下代码.如下图 maven{ ur ...

  2. 手把手搭建一个完整的javaweb项目

    手把手搭建一个完整的javaweb项目 本案例使用Servlet+jsp制作,用MyEclipse和Mysql数据库进行搭建,详细介绍了搭建过程及知识点. 下载地址:http://download.c ...

  3. 小记如何有顺序的搭建一个Spring的web项目

    如何有顺序的搭建一个Spring的web项目 一.新建一个简单的maven,war工程 eclipse下如有报错,右键 Deployment 单击 Generate 生成web.xml后可解决报错 二 ...

  4. 快速搭建一个基于react的项目

    最近在学习react,快速搭建一个基于react的项目 1.创建一个放项目文件夹,用编辑器打开 2.打开集成终端输入命令: npm install -g create-react-app 3. cre ...

  5. react全家桶从0搭建一个完整的react项目(react-router4、redux、redux-saga)

    react全家桶从0到1(最新) 本文从零开始,逐步讲解如何用react全家桶搭建一个完整的react项目.文中针对react.webpack.babel.react-route.redux.redu ...

  6. 5分钟快速搭建一个springboot的项目

      现在开发中90%的人都在使用springboot进行开发,你有没有这样的苦恼,如果让你新建一个springboot开发环境的项目,总是很苦恼,需要花费很长时间去调试.今天来分享下如何快速搭建. 一 ...

  7. 用Eclipse 搭建一个Maven Spring SpringMVC 项目

    1: 先创建一个maven web  项目: 可以参照之前的文章:  用Maven 创建一个 简单的 JavaWeb 项目 创建好之后的目录是这样的; 2: 先配置maven  修改pom.xml & ...

  8. springboot入门(一)--快速搭建一个springboot框架

    原文出处 前言在开始之前先简单介绍一下springboot,springboot作为一个微框架,它本身并不提供Spring框架的核心特性以及扩展功能,只是用于快速.敏捷地开发新一代基于Spring框架 ...

  9. 带你搭建一个简单的mybatis项目:IDEA+spring+springMVC+mybatis+Mysql

    最近小编有点闲,突发奇想想重温一下mybatis,然后在脑海中搜索了一下,纳尼,居然不太会用了,想到这里都是泪啊!!现在我所呆的的公司使用的是springboot+hebinate,编程都是使用的JP ...

随机推荐

  1. Sentence Screen Fitting

    Given a rows x cols screen and a sentence represented by a list of words, find how many times the gi ...

  2. 【Python】【基础知识】【内置常量】

    Python的内置常量有: False.True.None.NotImplemented.Ellipsis.__debug__ 由 site 模块添加的常量:quit.exit.copyright.c ...

  3. 解决Win7上的连接access数据库的问题

    最近做了一个win桌面程序,没有用sql 数据库,而是用access数据库,因为access比sql用起来方便多了,最主要是不要安装sql server,直接放在程序里面,然后创建连接字符就可以了,s ...

  4. 内网和wifi同时存在

    1.注意都要用管理员身份运行 2.将以下代码编写为.bat文件,然后以管理员身份运行此文件 route delete 0.0.0.0 route delete 10.10.0.0 route dele ...

  5. 【一个蒟蒻的挣扎】最小生成树—Kruskal算法

    济南集训第五天的东西,这篇可能有点讲不明白提前抱歉(我把笔记忘到别的地方了 最小生成树 概念:一个有 n 个结点的连通图的生成树是原图的极小连通子图,且包含原图中的所有 n 个结点,并且有保持图连通的 ...

  6. php 连接sqlserver

    本地环境windows 10+phpstudy2016+ SQL Server 2008 R2 x86+php7.0查看自己sql server 多少位可以在新建查询里输入 select @@VERS ...

  7. 小白简单快速搭建lnmp环境(centos7)

    本来想着自己搭建lnmp,由于php包下载不下来因此这次本人使用的lnmp一键包搭建的环境(很遗憾还没有php7.3.5)很详细并且方便快捷网址https://lnmp.org/install.htm ...

  8. MySQ-表关系-外键-修改表结构-复制表-03

    目录 前言 不合理的表结构(案例) 带来的问题 如何解决问题? 如何确定表关系? 表关系 一对多 多对多 一对一 应用场景 判断表关系最简单的语法 三种关系常见案例 如何建立表关系? 外键 forei ...

  9. LeetCode 203——移除链表(JAVA)

    删除链表中等于给定值 val 的所有节点. 示例: 输入: 1->2->6->3->4->5->6, val = 6 输出: 1->2->3->4 ...

  10. python设计购物车

    设计购物车 一需求: 1.启动程序后,输入用户名密码后,如果是第一次登录,让用户输入工资,然后打印商品列表 2.允许用户根据商品编号购买商品 3.用户选择商品后,检测余额是否够,够就直接扣款,不够就提 ...