SpringBoot JPA实现增删改查
2021-03-29 21:26
标签:hiberna roo interface wired web class stp else vax pom.xml文件 可以拿走直接用 application.yml 注意这里需要先改一下后缀名 因为程序中碰到了bug 这里将sql语句打印出来了jpa:show-sql:true User.java UserDao.java 这里也可以使用jpa父接口自定好的方法 UserService.java UserServiceImpl.java UserController.java 项目运行地址 http://localhost:8080/findAll SpringBoot JPA实现增删改查 标签:hiberna roo interface wired web class stp else vax 原文地址:https://www.cnblogs.com/alongg/p/13598270.htmlserver:
port: 8080
spring:
datasource:
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=UTC
driver-class-name: com.mysql.jdbc.Driver
username: root
password: root
jpa:
hibernate:
ddl-auto: update
show-sql: true
package com.along.jpa_user.entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity(name = "t_user")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String name;
private int age;
public int getId() {
return id;
}
public void setId(int 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;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", name=‘" + name + ‘\‘‘ +
", age=" + age +
‘}‘;
}
}
package com.along.jpa_user.dao;
import com.along.jpa_user.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Repository
public interface UserDao extends JpaRepository
package com.along.jpa_user.service;
import com.along.jpa_user.entity.User;
import org.springframework.data.repository.query.Param;
import java.util.List;
public interface UserService {
List
package com.along.jpa_user.service.Impl;
import com.along.jpa_user.dao.UserDao;
import com.along.jpa_user.entity.User;
import com.along.jpa_user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class UserServiceImpl implements UserService {
@Autowired
UserDao userDao;
@Override
public List
package com.along.jpa_user.controller;
import com.along.jpa_user.entity.User;
import com.along.jpa_user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class UserController {
@Autowired
UserService userService;
@GetMapping("/findAll")
public List
下一篇:es6 数组操作
文章标题:SpringBoot JPA实现增删改查
文章链接:http://soscw.com/index.php/essay/69688.html