postman 在测试save(Entity entity)的时候如何保存一个实体类
1. 首先 选择正确的头信息
2. 输入对应格式的数据[补充一点.数据库主键 自增 json数据库无需包含主键]
3. 如果程序没有问题 ok,
4. 具体操作看下图[图的右下角为贴图.从左往右看--> ]..代码在下面
代码采用的springboot + MVC + jpa
代码块:
@RestController
@RequestMapping("/person")
public class PersonController {
@PostMapping("/save")
public String save(@RequestBody Person person) {
personService.save(person);
return "200";
}
}
//service接口
public interface PersonService {
//添加
void save(Person person);
}
//service impl
@Service
public class PersonServiceImpl implements PersonService {
@Autowired
private PersonRepository personRepository;
@Override
public void save(Person person) {
personRepository.save(person);
}
}
//dao
@SuppressWarnings("unused")
public interface PersonRepository extends BaseDao<Person, Long> {
}
// entity
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity //1
public class Person implements Serializable {
private static final long serialVersionUID = 5918727834473026681L;
@Id //2
@GeneratedValue //3
private Long id;
private String name;
private Integer age;
private String address;
}