这篇文章主要介绍了springboot整合JPA过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
接下来具体看看是怎么弄的。
1、新建一个springboot项目,选择web、data jdbc、data jpa、mysql driver。
2、建立以下目录及结构:
pom.xml
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://.gong.springbootjpa.repository.UserRepository;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class UserController { @Autowired UserRepository userRepository; @GetMapping("/user/{id}") public User getUser(@PathVariable("id") Integer id){ User user = userRepository.getOne(id); return user; } @GetMapping("/user") public User insertUser(User user){ User save = userRepository.save(user); return save; }}7、启动服务器
插入一条数据:
查询一条数据:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。