欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

springboot + jpa實(shí)現(xiàn)刪除數(shù)據(jù)的操作代碼

 更新時(shí)間:2024年05月29日 11:00:57   作者:Dr.Disrespect  
這篇文章主要介紹了springboot + jpa實(shí)現(xiàn)刪除數(shù)據(jù)的操作代碼,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧

Entity層

package coolwen.demo.model;
import lombok.*;
import javax.persistence.*;
@Table(name = "t_stu")
@NoArgsConstructor
@AllArgsConstructor
@Setter
@Getter
@ToString
@Entity
public class Student {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO,generator = "student_id")
    private int id;
    private String name;
    private String address;
    private int age;
}

dao層方法

package coolwen.demo.dao;
import coolwen.demo.model.Student;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Component;
@Component
public interface StudentDao extends JpaRepository<Student,Integer> {
//    Student findByNameAndAddress(String name,String address);
    void deleteById(int id);
//    Page<Student> findAllByAge(int age,Pageable pageable);
}

??????? controller層方法

    @GetMapping("delete")
    public String deleteuser(){
        return "user/DeleteUser";
    }
    @PostMapping("delete")
    @ResponseBody
    public String deleteuser(int id){
        System.out.println(id);
        serviceimp.deleteById(id);
        return "delete suc";
    };

??????? thymeleaf前端模板

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form method="post" action="/admin/user/delete">
    <input type="text" name="id">
<!--    <input type="text" name="address">-->
    <input type="submit" value="提交">
</form>
</body>
</html>

??????? service層接口

package coolwen.demo.service;
import coolwen.demo.model.Student;
public interface Serviceimp {
    Student findByNameAndAddress(String name,String address);
    void deleteById(int id);
}

service層實(shí)現(xiàn)類

package coolwen.demo.service;
import coolwen.demo.dao.StudentDao;
import coolwen.demo.model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class Serviceimpl implements Serviceimp {
    @Autowired
    StudentDao studentDao;
    @Override
    public Student findByNameAndAddress(String name, String address) {
        return studentDao.findByNameAndAddress(name,address);
    }
    @Override
    public void deleteById(int id) {
        studentDao.deleteById(id);
    }
}

到此這篇關(guān)于springboot + jpa實(shí)現(xiàn)刪除數(shù)據(jù)的文章就介紹到這了,更多相關(guān)springboot jpa刪除數(shù)據(jù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論