最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

温州市| 定日县| 鸡东县| 永寿县| 两当县| 武平县| 伊吾县| 大足县| 广宁县| 平和县| 建平县| 同江市| 呈贡县| 曲阳县| 荣成市| 类乌齐县| 康保县| 林周县| 延庆县| 绥中县| 越西县| 绥德县| 横峰县| 策勒县| 合肥市| 邢台县| 宁国市| 休宁县| 朝阳区| 日土县| 高阳县| 张北县| 海阳市| 广宁县| 乐昌市| 兴安县| 惠州市| 靖州| 科技| 泰宁县| 汽车|