当前位置: 首页 > news >正文

领动营销网站建设/优化营商环境心得体会1000字

领动营销网站建设,优化营商环境心得体会1000字,乐清网站建设服务,辽阳市住房城乡建设委官方网站上一篇介绍了springboot简单整合mybatis的教程。这一篇是介绍springboot简单整合jpa的教程。由于jpa的功能强大,后续会继续写关于jpa的介绍已经使用,本文只是简单介绍一下它与springboot的整合。jpa不需要像mybatis一样创建表,首先给大家看一…

上一篇介绍了springboot简单整合mybatis的教程。这一篇是介绍springboot简单整合jpa的教程。

由于jpa的功能强大,后续会继续写关于jpa的介绍已经使用,本文只是简单介绍一下它与springboot的整合。

jpa不需要像mybatis一样创建表,首先给大家看一下application.properties文件代码,其中包含了jpa的配置和数据库配置,尤其注意一下spring.jpa.hibernate.ddl-auto属性,代码如下:

##端口号

server.port=8888

##数据库配置

##数据库地址

spring.datasource.url=jdbc:mysql://localhost:3306/test?characterEncoding=utf8&useSSL=false

##数据库用户名

spring.datasource.username=root

##数据库密码

spring.datasource.password=root

##数据库驱动

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

##validate 加载hibernate时,验证创建数据库表结构

##create 每次加载hibernate,重新创建数据库表结构,这就是导致数据库表数据丢失的原因。

##create-drop 加载hibernate时创建,退出是删除表结构

##update 加载hibernate自动更新数据库结构

##validate 启动时验证表的结构,不会创建表

##none 启动时不做任何操作

spring.jpa.hibernate.ddl-auto=create

##控制台打印sql

spring.jpa.show-sql=true

启动类application

package com.dalaoyang;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication

public class SpringbootJpaApplication {

public static void main(String[] args) {

SpringApplication.run(SpringbootJpaApplication.class, args);

}

}

pom文件大致和整合mybatis一样,只是把其中的mybatis改成了jpa,代码如下:

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

com.dalaoyang

springboot_jpa

0.0.1-SNAPSHOT

jar

springboot_jpa

springboot_jpa

org.springframework.boot

spring-boot-starter-parent

1.5.9.RELEASE

UTF-8

UTF-8

1.8

org.springframework.boot

spring-boot-starter-data-jpa

org.springframework.boot

spring-boot-starter-web

org.springframework.boot

spring-boot-devtools

runtime

mysql

mysql-connector-java

runtime

org.springframework.boot

spring-boot-starter-test

test

org.springframework.boot

spring-boot-maven-plugin

实体类city,其中@Table中的name对应数据库中表的名称

package com.dalaoyang.entity;

import javax.persistence.*;

/**

* @author dalaoyang

* @Description

* @project springboot_learn

* @package com.dalaoyang.Entity

* @email 397600342@qq.com

* @date 2018/4/7

*/

@Entity

@Table(name="city")

public class City {

@Id

@GeneratedValue(strategy=GenerationType.AUTO)

private int cityId;

private String cityName;

private String cityIntroduce;

public City(int cityId, String cityName, String cityIntroduce) {

this.cityId = cityId;

this.cityName = cityName;

this.cityIntroduce = cityIntroduce;

}

public City(String cityName, String cityIntroduce) {

this.cityName = cityName;

this.cityIntroduce = cityIntroduce;

}

public City() {

}

public int getCityId() {

return cityId;

}

public void setCityId(int cityId) {

this.cityId = cityId;

}

public String getCityName() {

return cityName;

}

public void setCityName(String cityName) {

this.cityName = cityName;

}

public String getCityIntroduce() {

return cityIntroduce;

}

public void setCityIntroduce(String cityIntroduce) {

this.cityIntroduce = cityIntroduce;

}

}

然后就是jpa的重要地方,CityRepository,继承了JpaRepository,

由于本文只是简单介绍了jpa的简单功能,所以JpaRepository中内置的方法已经足够使用。

代码如下:

package com.dalaoyang.repository;

import com.dalaoyang.entity.City;

import org.springframework.data.jpa.repository.JpaRepository;

/**

* @author dalaoyang

* @Description

* @project springboot_learn

* @package com.dalaoyang.Repository

* @email 397600342@qq.com

* @date 2018/4/7

*/

public interface CityRepository extends JpaRepository {

}

最后是controller,里面和mybatis整合一样,方法上面写的就是对应的测试方法。

package com.dalaoyang.controller;

import com.dalaoyang.entity.City;

import com.dalaoyang.repository.CityRepository;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.RestController;

/**

* @author dalaoyang

* @Description

* @project springboot_learn

* @package com.dalaoyang.controller

* @email 397600342@qq.com

* @date 2018/4/7

*/

@RestController

public class CityController {

@Autowired

private CityRepository cityRepository;

//http://localhost:8888/saveCity?cityName=北京&cityIntroduce=中国首都

@GetMapping(value = "saveCity")

public String saveCity(String cityName,String cityIntroduce){

City city = new City(cityName,cityIntroduce);

cityRepository.save(city);

return "success";

}

//http://localhost:8888/deleteCity?cityId=2

@GetMapping(value = "deleteCity")

public String deleteCity(int cityId){

cityRepository.delete(cityId);

return "success";

}

//http://localhost:8888/updateCity?cityId=3&cityName=沈阳&cityIntroduce=辽宁省省会

@GetMapping(value = "updateCity")

public String updateCity(int cityId,String cityName,String cityIntroduce){

City city = new City(cityId,cityName,cityIntroduce);

cityRepository.save(city);

return "success";

}

//http://localhost:8888/getCityById?cityId=3

@GetMapping(value = "getCityById")

public City getCityById(int cityId){

City city = cityRepository.findOne(cityId);

return city;

}

}

到这里启动项目就可以简单测试一下整合的效果了。

源码下载 :大老杨码云

http://www.lbrq.cn/news/768403.html

相关文章:

  • 栾川网站建设/手机制作网站app
  • 商务网站建设定义/福州网站排名提升
  • 专业建设网站的企业/友情链接seo
  • 深圳建设网站需要多少钱/sem推广什么意思
  • 做淘宝客网站用什么程序好/夜狼seo
  • 妇科网站源码/品牌网络营销推广方案策划
  • 淘宝客怎么做网站管理/google官网入口手机版
  • 第一成品网站/成都最新热门事件
  • 网站建设布局利于优化/最新搜索引擎排名
  • 可以直接进入网站的代码/刷排名seo
  • 做企业网站不好混/广告做到百度第一页
  • 小码王编程网站/seo推广策略
  • 静态化动态新闻网站开发/网站打开速度优化
  • 网站建设 软件开发的公司排名/seo推广技术培训
  • 网站的会员系统怎么做/站长工具seo综合查询推广
  • 网站开发需要什么/成功的网络营销案例及分析
  • wordpress ssh/网站搜索排名优化软件
  • 网站的用户体验/百度网页版
  • 网站自己做自己的品牌好做/网上竞价
  • 兰州市建设局网站国贸大厦/淘宝代运营公司排名
  • 织梦网站为什么容易被注入/东莞网站推广营销网站设计
  • 速贝cms建站系统/google商店
  • 品牌设计有限公司/seo技术培训广东
  • 网站建站建设/今日头条官网首页
  • wordpress成长记录网站模版/seo咨询推广找推推蛙
  • 网站设计的技术方案/深圳seo优化电话
  • 宜宾建设机械网站/搜索引擎优化的主要工作有
  • 怎么建设代刷网站/设计公司网站设计
  • 做建筑设计的网站推荐/网络营销服务有哪些
  • 微信开发小程序开发网站建设/扬州seo优化
  • Linux学习-UI技术
  • [AI React Web] 包与依赖管理 | `axios`库 | `framer-motion`库
  • 15.卷积神经网络
  • C# 微软依赖注入 (Microsoft.Extensions.DependencyInjection) 详解
  • linux 开机进入initramfs无法开机
  • ETCD备份