SpringBoot +Jpa+ Hibernate+Mysql工程
1 使用工具workspace-sts 3.9.5.RELEASE
(1)新建一个SpringBoot 项目,选择加载项目需要的的组件。DevTools,JPA,Web,Mysql. Finish. 工程命名,项目创建成功。
(2)src/mian/java文件下放java文件,创建包,规范化命名。
config:程序入口 @SpringBootApplication
@EntityScan(basePackages="com.entity")
@EnableJpaRepositories("com.dao")
@ComponentScan(basePackages = { "com.controller","com.server"}),
public class App {
public static void main(String[] args) {
// TODO Auto-generated method stub
SpringApplication.run(App.class,args);
}
}
dao:Jpa接口引入。@Repository用于标注数据访问组件,即DAO组件;
@Service("Test3Service")
public class Test3ServiceImpl implements Test3Service {
//自动注入
@Autowired
Test3Repository test3Repository;
@Override
entity:实体层,对应数据库表
@Entity
@Table(name = "Test3")
public class Test3 implements Serializable{
public Test3() {
}
implements Serializable 实现序列化,跨平台的时候解决一些问题。
server:测试表增删改查的接口,实现接口。处理业务逻辑方式
controller:控制器,@RestController
@RestController
public class Test3Controller {
//自动注入
@Autowired
Test3Service test3Service; //添加TestOne数据
@PostMapping(value="/test3s")//@RequestBody 接收参数,参数是一个对象
public ResponseEntity<Test3> saveTestOne(@RequestBody Test3 test3) { System.out.println(test3.getLastName()); test3Service.save(test3);
return new ResponseEntity<Test3>(test3, HttpStatus.OK); } //查询TestOne数据
@GetMapping("/test3s")
public List<Test3> getTestOne(){
return test3Service.findAll(); } //删除TestOne数据
@DeleteMapping("/test3s/{id}")
public void delete(@PathVariable("id") Long id) { test3Service.deleteOne(id);
} //修改TestOne数据
@PutMapping(value = "/test3s/{id}") // @RequestBody 接收参数,参数是一个对象
public ResponseEntity<Test3> updateTestOne (@RequestBody Test3 test3) { System.out.println(test3.getLastName()); test3Service.update(test3); return new ResponseEntity<Test3>(test3, HttpStatus.OK);
}
}
SpringBoot +Jpa+ Hibernate+Mysql工程的更多相关文章
- SpringBoot + JPA 连接MySQL完整实例(一)
开发工具 1.Eclipse 2.Maven 3.Spring Boot 首先,Eclipse中配置好maven,具体请百度 工程结构: 实现步骤: 1.Eclipse中新建一个maven proje ...
- SpringBoot + Jpa(Hibernate) 架构基本配置
1.基于springboot-1.4.0.RELEASE版本测试 2.springBoot + Hibernate + Druid + Mysql + servlet(jsp) 一.maven的pom ...
- 008Spring & JPA & Hibernate & MySQL
01下载免安装版MySQL 02安装MySQL a)将MySQL压缩包解压到合适的位置,以C:\programmer\Tools\mysql-5.7.20-winx64路径为例: b)新建系统变量,变 ...
- Spring 4 mvc+shiro+thymeleaf+JPA(Hibernate)+MySql eclipse项目模板
本模板基本配制为:spring 4.3.8+thymeleaf 3.0.3 +hibernate 5.5.5 + mysql 5.7 IDE:eclipse 运行环境为:Tomcat 8.0.28 项 ...
- SpringBoot系列之——整合JPA、mysql
一.JPA 1. 概念:JPA顾名思义就是Java Persistence API的意思,是JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中. 2. ...
- springboot 集成 jpa/hibernate
pom.xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...
- SpringBoot+Jpa+MySql学习
上一篇介绍了springboot简单整合mybatis的教程.这一篇是介绍springboot简单整合jpa的教程. 由于jpa的功能强大,后续会继续写关于jpa的介绍已经使用,本文只是简单介绍一下它 ...
- springboot配置hibernate jpa多数据源
这里我用的springboot项目,配置文件yml文件配置,gradle配置jar包依赖. 找了一天资料,终于整好了多数据源,步骤如下: application.yml: spring: dataso ...
- SpringBoot之使用jpa/hibernate
Springboot版本是2.1.3.RELEASE 1.依赖 List-1.1 <dependency> <groupId>org.springframework.boot& ...
随机推荐
- 解决使用angular2路由后,页面刷新后报404错误。
点击路由链接跳转页面是正常的,但是当刷新页面时就出现了404错误. 解决方法如下: 在app.module.ts中添加import: import {HashLocationStrategy,Loca ...
- java.io.IOException: Could not delete path 'D:\mycode\reactnative\SecondTest\android\app\build\generated\source\r \release\android\support\v7
问题解决 直观上看是没有删除某个文件,产生的IOException异常,实际上是因为上次编译导致的缓存没有清空导致的. 进入到android目录下运行下面代码清除上次打包时的缓存: ./gradlew ...
- C/C++ 宏技巧
1. C 也可以模板化 #define DEFINE_ARRAY_TYPE(array_type_, element_type_) \ static inline int array_type_ ## ...
- 2017-2018 ACM-ICPC, NEERC A题Automatic Door 挺棘手的模拟
题目链接:http://codeforces.com/contest/883/problem/A 题意大致就是有一个门,有n个人有规律的来,时刻分别是a,2a,3a.....na.有m个人无规律的来, ...
- Linux下常用工具
GUI篇 计算器gnome-calculator pdf阅读envince 虚拟机virtualbox vnc tigervnc-server and client 网络连接network-manag ...
- 整理面试问题iOS
1.如何添加手势操作. 我们以在view上来举例 //创建一个view UIView *tapView=[UIView new]; tapView.frame=CGRectMake(, , kWidt ...
- Ubuntu16.04中pip无法更新升级,采用源码方式安装
1.从pip官网下载最新版 https://pypi.org/project/pip/#files 2.ubuntu中创建文件位置,我的放在一下路径,之后进行解压 3.解压后进入pip的文件夹,在执行 ...
- 基于Jmeter的 性能测试
目标:对南通大学计算机学院网站开展性能测试:(url:http://cs.ntu.edu.cn/) 首先下载jmeter的zip压缩包,解压后进入bin目录,由于我使用的系统是win10,所以要双击执 ...
- hsdfz -- 6.16 -- day1
恩这回不写游记了 按照老师要求记录今天的心里路程:这题似乎可做期望得分150->日部分分似乎不是很显然->a题似乎是结论题,大力猜一波结论->过不了样例,先看b题->b题动态树 ...
- c#泛型TryParse类型转换
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...