现在创建个项目:

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

 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. JAVA实验报告及第七周总结

    JAVA第六周作业 实验报告五 第一题 1.设计一个类层次,定义一个抽象类--形状,其中包括有求形状的面积的抽象方法. 继承该抽象类定义三角型.矩形.圆. 分别创建一个三角形.矩形.圆存对象,将各类图 ...

  2. (模板)hdoj5977 Garden of Eden(点分治)

    题目链接:https://vjudge.net/problem/HDU-5977 题意:给一颗树,每个结点上有一个权值a[i],a[i]<=10,求有多少条路径满足这条路径上所有权值的结点都出现 ...

  3. [转帖]AMD第三代锐龙处理器首发评测:i9已无力招架

    AMD第三代锐龙处理器首发评测:i9已无力招架 Intel 从之前的 CCX 到了 CCD 增加了缓存 改善了 ccx 之间的延迟. https://baijiahao.baidu.com/s?id= ...

  4. python -- TypeError: 'module' object is not callable

    文件: 代码: import pprintmessge = 'It was a bringht cold day in April,and the clocks were striking thrir ...

  5. 解决Spring Boot集成Shiro,配置类使用Autowired无法注入Bean问题

    如题,最近使用spring boot集成shiro,在shiroFilter要使用数据库动态给URL赋权限的时候,发现 @Autowired 注入的bean都是null,无法注入mapper.搜了半天 ...

  6. 【转】js小数转百分比

    转自:js小数和百分数的转换 function toPercent(point){ var str=Number(point*100).toFixed(1); str+="%"; ...

  7. Bootstrap3基础教程 01 概述

    移动设备优先是 Bootstrap 3 的最显著的变化. 基础的页面: <!DOCTYPE html> <html> <head> <meta charset ...

  8. JS基础_for循环练习3

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. 【Git的基本操作三】基本操作命令

    基本操作 (1) 状态查看操作 git status 作用:查看工作区.暂存区状态 (2) 添加操作 git add [filename] 作用:将工作区文件的 添加/修改,添加到暂存区 (3) 提交 ...

  10. vue学习(2)-过滤器

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...