搭建Springboot框架,并添加JPA和Gradle组件
来源:互联网 发布:ubuntu超级用户权限 编辑:程序博客网 时间:2024/06/03 17:11
开发工具:Intellij IDEA
所需开发环境:JDK Gradle
一、新建springboot项目
1.New Project
2. spring initializr
3. 填写项目组织
group : 项目属于哪个组,这个组往往和项目所在的组织或公司存在关联
artifact : 当前项目在组中唯一的ID
Type : jar包管理所使用的工具
Lauguage : 开发语言
packageing : 打包方式
Java Version : JDK 的版本号
version :项目当前的版本号
4.选择所需要添加的组件
5. 选择项目的保存位置
二、目标代码组织
1. 配置数据库
resource目录下的application.properties
spring.jpa.hibernate.ddl-auto=create-dropspring.datasource.url=jdbc:mysql://localhost:3306/testspring.datasource.username=rootspring.datasource.password=cueb
2. 修改build.gradle文件
将34行的providedRuntime修改为compile,否者项目无法正常启动
providedRuntime :在运行时提供Tomcat Jar包
compile :在编译时提供Tomcat jar包
buildscript {ext {springBootVersion = '1.5.7.RELEASE'}repositories {mavenCentral()}dependencies {classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")}}apply plugin: 'java'apply plugin: 'eclipse-wtp'apply plugin: 'org.springframework.boot'apply plugin: 'war'group = 'com.example'version = '0.0.1-SNAPSHOT'sourceCompatibility = 1.8repositories {mavenCentral()}configurations {providedRuntime}dependencies {compile('org.springframework.boot:spring-boot-starter-data-jpa')compile('org.springframework.boot:spring-boot-starter-web')runtime('mysql:mysql-connector-java')compile('org.springframework.boot:spring-boot-starter-tomcat')testCompile('org.springframework.boot:spring-boot-starter-test')}
3. 新建controller
package com.example.demo.control;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class TestController { @RequestMapping(value = "") public String test(){ return "hello cueb"; }}
4. 新建model
package com.example.demo.model;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.GenerationType;import javax.persistence.Id;@Entitypublic class User { @Id @GeneratedValue(strategy= GenerationType.AUTO) int id; public int getId() { return id; } public void setId(int id) { this.id = id; } private String name; public String getName() { return name; } public void setName(String name) { this.name = name; }}
三、部署运行
1. debug 启动
2. 数据库user表新建成功
阅读全文
0 0
- 搭建Springboot框架,并添加JPA和Gradle组件
- 新建gradle项目 并添加springboot框架支持
- springboot+jpa 基础框架搭建
- SpringBoot搭建,10分钟教你完成框架SpringBoot+hibernate+jpa
- SpringBoot和Jpa相关
- springboot框架组件
- idea使用gradle搭建SpringBoot
- SpringBoot连接SQLite数据库(基于Spring-Data-Jpa和Gradle配置)
- jpa框架的搭建
- 学习搭建springboot框架
- springboot 框架搭建
- java 搭建基于springboot的ssh(spring + springmvc + hibernate)的gradle项目(添加多Module篇)
- SpringBoot JPA使用QueryDsl之gradle文件配置
- eclipse+gradle+springBoot搭建开发环境
- 初探SpringBoot,简单搭建一个SpringBoot框架
- struts2.0+JPA框架搭建
- SpringMVC+JPA+Mysql框架搭建
- springMVC+jpa+maven框架搭建
- HDPCD-Java-复习笔记(10)-lab
- 如何免费上传4G以上大文件至百度云盘
- 二分法查找
- python 手记6 〖笨方法学python习题21〗
- Tp5 Validate
- 搭建Springboot框架,并添加JPA和Gradle组件
- 面试_人事问题
- windows环境eclipse操作hadoop常见错误:Permission denied: user=haibozhang, access=WRITE, inode='...'
- c++演示表达式的运算过程
- git的基本工作流程(git add; git commit; git rm; git mv; .gitignore文件)
- C 基本语法
- (M)DFS:116. Populating Next Right Pointers in Each Node
- 151. Reverse Words in a String
- Android进阶——源码分析之图片加载框架Glide