在之前的测试中,我看到虽然它能够毫无问题地删除,但现在它不能工作。
这是我的实体类:
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name="subcomments")
public class SubComment {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public long id;
@Column(name="uid")
public String uid;
@Column (name="name")
public String name;
@Column (name="above_uid")
public String above_uid;
@Column (name="url")
public String url;
@Column(name="coin")
public String coin;
@Column (name="comment")
public String comment;
@Column (name="top_date")
public int top_date;
@Column (name="top_time")
public int top_time;
}
这是我的JPA存储库:
public interface SubCommentRepo extends JpaRepository<SubComment , Long>{
// All CRUD database methods
@Query( value="Select * from subcomments where uid=:uid and above_uid=:above_uid and coin=:coin and comment=:comment and top_date=:top_date and top_time=:top_time" , nativeQuery=true )
public SubComment info(String uid, String above_uid, String coin, String comment,int top_date, int top_time);
}
存储库中的INFO方法用于检查数据库中是否存在当前数据。
这是我的REST控制器:
@RestController
@RequestMapping(path="/api/v1/user")
public class ServiceController {
@Autowired
SubCommentRepo subRepo ;
// Delete Sub Comment***
@DeleteMapping(path="/comment/sub/delete")
public ResponseEntity<String> delete( @RequestBody SubComment smt ) {
if ( subRepo.info(smt.uid, smt.above_uid, smt.coin, smt.comment, smt.top_date, smt.top_time)!= null ) {
subRepo.delete(smt);
return ResponseEntity.status( HttpStatus.OK ).body ( "Deleted" );
} else {
return ResponseEntity.status( HttpStatus.BAD_REQUEST ).body( "Not available already" );
}
}
}
我正在使用MySQL作为数据库。
我是第一次试穿春靴。:)
1条答案
按热度按时间myss37ts1#
使用
deleteById
方法而不是delete
方法。