老熟女激烈的高潮_日韩一级黄色录像_亚洲1区2区3区视频_精品少妇一区二区三区在线播放_国产欧美日产久久_午夜福利精品导航凹凸

重慶分公司,新征程啟航

為企業提供網站建設、域名注冊、服務器等服務

SpringBoot添加MySQL數據庫及JPA實例

最近在學習Spring Boot,繼續前面的學習,這一次我們加入MySQL數據庫和JPA。

成都創新互聯公司是專業的靖江網站建設公司,靖江接單;提供成都網站制作、網站建設、外貿網站建設,網頁設計,網站設計,建網站,PHP網站建設等專業做網站服務;采用PHP框架,可快速的進行靖江網站開發網頁制作和功能擴展;專業做搜索引擎喜愛的網站,專業的做網站團隊,希望更多企業前來合作!

配置:

pom.xml文件

 
   
  org.springframework.boot 
  spring-boot-starter-data-jpa 
   
   
   mysql 
   mysql-connector-java 
   

在Application.properties(在resource文件夾下新建,進行配置)文件中添加數據進行配置:

spring.datasource.url = jdbc:mysql://localhost:3306/spring_boot 
spring.datasource.username = root 
spring.datasource.password = root 
spring.datasource.driverClassName = com.mysql.jdbc.Driver 
 
 
# Specify the DBMS 
spring.jpa.database = MYSQL 
# Show or not log for each sql query 
spring.jpa.show-sql = true 
# Hibernate ddl auto (create, create-drop, update) 
spring.jpa.hibernate.ddl-auto = update 
# Naming strategy 
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy 
 
# stripped before adding them to the entity manager) 
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect 

User類

package com.seawater.bean; 
 
import javax.persistence.*; 
import javax.validation.constraints.NotNull; 
 
/** 
 * Created by zhouhs on 2016/12/30. 
 */ 
@Entity 
@Table(name = "user") 
public class User { 
 
 @Id 
 @GeneratedValue(strategy = GenerationType.AUTO) 
 private Long id; 
 private String name; 
 private int age; 
 
 public Long getId() { 
  return id; 
 } 
 
 public void setId(Long id) { 
  this.id = id; 
 } 
 
 public String getName() { 
  return name; 
 } 
 
 public void setName(String name) { 
  this.name = name; 
 } 
 
 public int getAge() { 
  return age; 
 } 
 
 public void setAge(int age) { 
  this.age = age; 
 } 
} 

UserController

package com.seawater.controller; 
import com.seawater.Dao.UserDao; 
import com.seawater.bean.User; 
import io.swagger.annotations.Api; 
import io.swagger.annotations.ApiImplicitParam; 
import io.swagger.annotations.ApiImplicitParams; 
import io.swagger.annotations.ApiOperation; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.RequestParam; 
import org.springframework.web.bind.annotation.RestController; 
 
import javax.annotation.Resource; 
 
/** 
 * Created by zhouhs on 2016/12/30. 
 */ 
@RestController 
@RequestMapping(value = "/user") 
@Api(description = "用戶") 
public class UserController { 
 
 @Resource 
 UserDao userDAO; 
 @ApiOperation(value = "添加用戶") 
 @ApiImplicitParams({ 
   @ApiImplicitParam(name = "name" , value = "name" , paramType = "query" , required = true ), 
   @ApiImplicitParam(name = "age" , value = "age" , paramType = "query" , required = true ) 
 }) 
 @RequestMapping(value = "/addUser" , method = RequestMethod.POST) 
 public String addUser(@RequestParam(value = "name") String name,@RequestParam(value = "age") int age){ 
 
  User user = new User(); 
  user.setName(name); 
  user.setAge(age); 
 
  userDAO.save(user); 
 
  return "add user success !"; 
 } 
 
 @ApiOperation(value = "查找用戶") 
 @ApiImplicitParam(name = "id" , value = "id" , paramType = "query" , required = true , dataType = "int") 
 @RequestMapping(value = "/findById" , method = RequestMethod.POST) 
 public String findById(@RequestParam(value = "id") Long id){ 
 
  User user = userDAO.findById(id); 
 
  if(user == null){ 
   return "error"; 
  }else{ 
   return "name:" + user.getName() + " , age:" + user.getAge(); 
  } 
 } 
 
 @ApiOperation(value = "查詢所有用戶") 
 @RequestMapping(value = "/findAll" , method = RequestMethod.POST) 
 public Iterable findAll(){ 
 
  Iterable userList = userDAO.findAll(); 
 
  return userList; 
 
 } 
 
 @ApiOperation(value = "刪除用戶") 
 @ApiImplicitParam(name = "id" , value = "id" , paramType = "query" , required = true , dataType = "int") 
 @RequestMapping(value = "/deleteById" , method = RequestMethod.POST) 
 public String deleteById(@RequestParam(value = "id") Long id){ 
 
  userDAO.delete(id); 
  return "delete success !"; 
 
 } 
} 

數據表(id定義為Integer):

Spring Boot 添加MySQL數據庫及JPA實例

UserDao:

package com.seawater.Dao; 
 
import com.seawater.bean.User; 
import org.springframework.data.repository.CrudRepository; 
 
/** 
 * Created by zhouhs on 2016/12/30. 
 */ 
public interface UserDao extends CrudRepository { 
 
 public User findById(Long id); 
 
} 

然后啟動項目:訪問http://localhost:8081/swagger-ui.html

結果:

Spring Boot 添加MySQL數據庫及JPA實例

方法我就不一一操作了。

源碼地址(項目中的源碼可能會更多哦,需要自己找到對應源碼):SpringBootLearning_jb51.rar

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持創新互聯。


文章名稱:SpringBoot添加MySQL數據庫及JPA實例
文章分享:http://www.xueling.net.cn/article/ppieod.html

其他資訊

在線咨詢
服務熱線
服務熱線:028-86922220
TOP
主站蜘蛛池模板: 中文字幕另类日韩欧美亚洲嫩草 | 亚洲国产天堂久久综合网 | 国产精品一区二区x88av | 国产女人囗交视频 | 91久久久一线二线三线品牌 | 日本特级黄 | 18禁止看的免费污网站 | 91日韩久久 | 在线中文字幕有码中文 | 国产乱码久久久久久 | 9免费视频 | 欧美日韩在线不卡 | 亚洲日本精品国产第一区 | 亚洲日本乱码一区两区在线观看 | 久久99精品一区二区三区 | 9999精品视频| 国产精品乱码一区二三区 | 国产精品色情一区二区三区 | 朝鲜女人大白屁股ass | 粉嫩大学生无套内射无码卡视频 | 亚州精品av久久久久久久影院 | 亚洲另类春色校园小说 | 欧美日韩一区二区在线播放 | 亚洲二区三区在线 | 中文字幕在线观看日韩 | 精品国产综合久久 | 黑人狂躁日本妞一区二区三区 | 啊灬啊灬啊灬快灬高潮少妇a片 | 国产主播户外勾搭人xx | 亚洲人成色777777老人头 | 亚洲香蕉在线视频 | 欧美狠狠爱 | 久久麻传媒亚洲av国产 | 欧美一级xxx | 久久综合给合久久97色 | 最新日本一道免费一区二区 | 性欧美video高清 | 女女女女bbbb毛片免费视频 | 疯狂做受XXXX国产 | 中文字幕视频一区二区三区久 | 初尝黑人巨砲波多野结衣 |