springboot + jpa實(shí)現(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層實(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)文章希望大家以后多多支持腳本之家!
- Spring?Boot?整合JPA?數(shù)據(jù)模型關(guān)聯(lián)使用操作(一對一、一對多、多對多)
- SpringDataJPA詳解增刪改查操作方法
- Spring?Data?JPA映射自定義實(shí)體類操作
- SpringDataJpa多表操作的實(shí)現(xiàn)
- Springboot使用Spring Data JPA實(shí)現(xiàn)數(shù)據(jù)庫操作
- SpringBoot集成JPA持久層框架,簡化數(shù)據(jù)庫操作
- springboot-jpa的實(shí)現(xiàn)操作
- springboot 之jpa高級查詢操作
- Springboot?JPA級聯(lián)操作的實(shí)現(xiàn)(一對一、一對多、多對多)
相關(guān)文章
SpringBoot + openFeign實(shí)現(xiàn)遠(yuǎn)程接口調(diào)用的過程
現(xiàn)在的微服務(wù)項(xiàng)目不少都使用的是springboot+spring cloud構(gòu)建的項(xiàng)目,微服務(wù)之間的調(diào)用都離不開feign來進(jìn)行遠(yuǎn)程調(diào)用,這篇文章主要介紹了SpringBoot + openFeign實(shí)現(xiàn)遠(yuǎn)程接口調(diào)用,需要的朋友可以參考下2022-11-11
Java并發(fā)應(yīng)用之任務(wù)執(zhí)行分析
這篇文章主要為大家詳細(xì)介紹了JavaJava并發(fā)應(yīng)用編程中任務(wù)執(zhí)行分析的相關(guān)知識,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下2023-07-07
java實(shí)現(xiàn)基于SGIP協(xié)議開發(fā)聯(lián)通短信的方法
這篇文章主要介紹了java實(shí)現(xiàn)基于SGIP協(xié)議開發(fā)聯(lián)通短信的方法,涉及java短信發(fā)送的相關(guān)實(shí)現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-07-07
Spring Security將用戶數(shù)據(jù)存儲到數(shù)據(jù)庫的方法
這篇文章主要介紹了Spring Security將用戶數(shù)據(jù)存儲到數(shù)據(jù)庫的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09
SpringMVC @RequestBody屬性名大寫字母注入失敗的解決
這篇文章主要介紹了SpringMVC @RequestBody屬性名大寫字母注入失敗的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-04-04
基于SpringBoot+Avue實(shí)現(xiàn)短信通知功能
Avue是基于vue和element-ui的快速開發(fā)框架 ,它的核心是數(shù)據(jù)驅(qū)動UI的思想,讓我們從繁瑣的crud開發(fā)中解脫出來,本文將給大家介紹一下使用SpringBoot+Avue實(shí)現(xiàn)短信通知功能,文中有詳細(xì)的代碼示例,需要的朋友可以參考下2023-09-09
SpringBoot中的Condition包下常用條件依賴注解案例介紹
這篇文章主要介紹了SpringBoot中的Condition包下常用條件依賴注解案例,文章基于Java的相關(guān)資料展開主題詳細(xì)內(nèi)容,需要的小伙伴可以參考一下2022-04-04

