Postman使用实例
实体类Emp
package com.example.springboot_postman.pojo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.io.Serializable;
/**
* @Author moon
* @Date 2023/10/2 18:29
* @Description
*/
@Entity
@Table(name = "t_emp")
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties(value = { "hibernateLazyInitializer"})
public class Emp implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "emp_id")
private int id;
@Column(name = "emp_name")
private String name;
@Column(name = "age")
private int age;
@Column(name = "gender")
private String gender;
@Column(name = "email")
private String email;
}
JPA接口EmpDao
package com.example.springboot_postman.dao;
import com.example.springboot_postman.pojo.Emp;
import org.springframework.data.jpa.repository.JpaRepository;
/**
* @Author moon
* @Date 2023/10/2 18:43
* @Description
*/
public interface EmpDao extends JpaRepositoryEmp, Integer> {
}
1. 分页查询
EmpService:
public PageEmp> queryByPage(Integer page, Integer size) {
Pageable pageable = PageRequest.of(page, size,Sort.by(Sort.Direction.DESC, "id"));
return empDao.findAll(pageable);
}
EmpController
@RequestMapping("/getByPage")
public ResponseEntityPageEmp>> queryByPage(@RequestBody MapString, Integer> map) {
System.out.println(map.get("page") + map.get("size"));
return ResponseEntity.ok(this.EmpService.queryByPage(map.get("page"), map.get("size")));
}
2. 根据id查询
EmpService:
public Emp queryById(Integer id) {
Emp emp = new Emp();
emp.setId(id);
return empDao.getOne(emp.getId());
}
EmpController
@PostMapping
public ResponseEntityEmp> add(Emp Emp) {
return ResponseEntity.ok(this.EmpService.insert(Emp));
}
3. 增
EmpService
public Emp insert(Emp emp) {
empDao.save(emp);
return emp;
}
EmpController
@PostMapping
public ResponseEntityEmp> add(@RequestBody Emp Emp) {
System.out.println(Emp);
return ResponseEntity.ok(this.EmpService.insert(Emp));
}
4. 删
EmpService
public Boolean deleteById(Integer id) {
Emp emp = new Emp();
emp.setId(id);
empDao.deleteById(emp.getId());
return true;
}
EmpController
@DeleteMapping("{id}")
public ResponseEntityBoolean> deleteById(@PathVariable Integer id) {
return ResponseEntity.ok(this.EmpService.deleteById(id));
}
5. 改
EmpService
public Emp update(Emp emp) {
empDao.save(emp);
return emp;
}
EmpController
@PutMapping
public ResponseEntityEmp服务器托管网> edit(@RequestBody Emp Emp) {
return ResponseEntity.ok(this.EmpService.update(Emp));
}
其中分页管理也可以这样写
@GetMapping
public ResponseEntityPageEmp>> queryByPage(@RequestBody MapString, Integer> map) {
return ResponseEntity.ok(this.EmpService.queryByPage(map.get("page"), map.get("size")));
}
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
相关推荐: Go语言基准测试(benchmark)三部曲之一:基础篇
欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 关于基准测试(benchmark) Go的标准库内置的testing框架提供了基准测试(benchmark)功能,…