我想将请求中的二进制 16 字符串转换为 UUID。我尝试了很多方法,但没有取得任何进展。 重点是我选择一个 MySQL 数据库来获取这个二进制文件。
如果有人对将 binary16 转换为 UUID 有经验或见解,或者对我可以尝试的替代方法有任何建议,我将非常感谢您的帮助。我愿意接受任何可以帮助我克服这一障碍并成功将 binary16 数据转换为 UUID 格式的指导或建议。
@NoArgsConstructor
@ToString
@Entity
@Table(name = "attendant")
public class AttendantModel implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Getter
private UUID attendantID;
@Column(nullable = false, length = 100)
@Getter @Setter
private String name;
@Column
@Getter @Setter
private UUID productID1;
@Column
@Getter @Setter
private UUID productID2;
@Column
@Getter @Setter
private UUID instructionID;
}
@RestController
@RequestMapping("/api/attendant")
public class AttendantController {
final AttendantService attendantService;
public AttendantController(AttendantService attendantService) {
this.attendantService = attendantService;
}
@Autowired
private AttendantRepository attendantRepository;
@PostMapping
public ResponseEntity<Object> saveInstructions(@RequestBody @Valid AttendantDto attendantDto) {
var attendantModel = new AttendantModel();
BeanUtils.copyProperties(attendantDto, attendantModel);
return ResponseEntity.status(HttpStatus.CREATED).body(attendantService.save(attendantModel));
}
}
public class AttendantDto {
@NotBlank
@Size(max = 100)
@Getter @Setter
private String name;
@Getter @Setter
private UUID productID1;
@Getter @Setter
private UUID productID2;
@Getter @Setter
private UUID instructionID;
}
我的 JSON 请求是:
{
"name": "Júlia - vendedora",
"productID1": "5a61a32a5ab045dbb5a2bf25425da963"
}
我尝试在 DTO 或模型中将其作为字符串而不是 UUID 接收,但我无法弄清楚。
我的解决方案:不将UUID保存为varchar36,而不是将UUID保存为bynary16。
@JdbcTypeCode(SqlTypes.VARCHAR)