springboot + jpa實現(xiàn)刪除數(shù)據(jù)的操作代碼
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層實現(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實現(xiàn)刪除數(shù)據(jù)的文章就介紹到這了,更多相關(guān)springboot jpa刪除數(shù)據(jù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Spring?Boot?整合JPA?數(shù)據(jù)模型關(guān)聯(lián)使用操作(一對一、一對多、多對多)
- SpringDataJPA詳解增刪改查操作方法
- Spring?Data?JPA映射自定義實體類操作
- SpringDataJpa多表操作的實現(xiàn)
- Springboot使用Spring Data JPA實現(xiàn)數(shù)據(jù)庫操作
- SpringBoot集成JPA持久層框架,簡化數(shù)據(jù)庫操作
- springboot-jpa的實現(xiàn)操作
- springboot 之jpa高級查詢操作
- Springboot JPA級聯(lián)操作的實現(xiàn)(一對一、一對多、多對多)
相關(guān)文章
Java class文件格式之方法_動力節(jié)點Java學(xué)院整理
這篇文章主要為大家詳細(xì)介紹了Java class文件格式之方法的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-06-06
在IDEA中使用debug工具去運行java程序的實現(xiàn)步驟
調(diào)試工具(debug工具)是一種用于幫助程序員識別和修復(fù)程序中的錯誤的工具,它們提供了一系列的功能,幫助程序員在代碼執(zhí)行的過程中跟蹤和檢測問題,本文將給大家介紹使用debug工具去運行java程序的實現(xiàn)步驟,需要的朋友可以參考下2024-04-04
SparkSQL中的JSON內(nèi)置函數(shù)全解析
你是否曾經(jīng)為處理JSON數(shù)據(jù)而頭疼?SparkSQL為我們提供了強(qiáng)大的內(nèi)置JSON函數(shù),讓JSON處理變得輕而易舉,本文將帶你深入了解這些函數(shù),感興趣的朋友一起看看吧2024-08-08
IntelliJ IDEA里找不到j(luò)avax.servlet的jar包的解決方法
這篇文章主要介紹了IntelliJ IDEA里找不到j(luò)avax.servlet的jar包的解決方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09

