最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

搭建Springboot框架并添加JPA和Gradle組件的方法

 更新時間:2018年07月26日 10:48:39   作者:姜興琪  
這篇文章主要介紹了搭建Springboot框架并添加JPA和Gradle組件的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

開發(fā)工具:Intellij IDEA

所需開發(fā)環(huán)境:JDK Gradle

一、新建springboot項目

1.New Project


2. spring initializr


3. 填寫項目組織

group : 項目屬于哪個組,這個組往往和項目所在的組織或公司存在關(guān)聯(lián)

artifact : 當(dāng)前項目在組中唯一的ID

Type : jar包管理所使用的工具

Lauguage : 開發(fā)語言

packageing : 打包方式

Java Version : JDK 的版本號

version :項目當(dāng)前的版本號

4.選擇所需要添加的組件



5. 選擇項目的保存位置


二、目標代碼組織


1. 配置數(shù)據(jù)庫

resource目錄下的application.properties

spring.jpa.hibernate.ddl-auto=create-drop
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.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.8
 
repositories {
	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;
 
@RestController
public 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;
 
@Entity
public 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. 數(shù)據(jù)庫user表新建成功


以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

舞阳县| 富平县| 义马市| 民权县| 永胜县| 仲巴县| 图们市| 屏东市| 怀集县| 西峡县| 汉沽区| 涟源市| 阿拉善盟| 镇江市| 香河县| 吉木萨尔县| 铁力市| 新津县| 旬阳县| 安义县| 晋州市| 沧州市| 南投县| 南陵县| 华亭县| 长宁县| 平原县| 铜梁县| 福清市| 普陀区| 嘉祥县| 郴州市| 云和县| 昔阳县| 洪洞县| 礼泉县| 秦皇岛市| 乳源| 霍邱县| 禹城市| 蕉岭县|