如何插入和return uuid?

How to insert and return the uuid?

我的目标是插入 table

CREATE TABLE event_info (
  id INT NOT NULL AUTO_INCREMENT,
  uuid VARCHAR(255) NOT NULL,
  PRIMARY KEY (id),
  UNIQUE (uuid)
);
@Mapper
public class EventMapper {
  @Insert("INSERT INTO event_info (uuid) " +
          "VALUES (#{uuid})")
  @SelectKey(statement = "SELECT UUID() as uuid), resultType = String.class, keyProperty = "uuid", before = true)
  String insertReturnUuid();
}
String uuid = eventMapper.insertReturnUuid();

我的预期结果:uuid 不为空。

我的实际成绩

org.apache.ibatis.binding.BindingException: Mapper method 'com.a.mapper.EventsMapper.insertReturnUuid' has an unsupported return type: class java.lang.String

1.char(36) 比较好 2.you 不能。唯一的解决方案是执行 2 个单独的查询:

SELECT UUID() 插入 table1 (id, text) VALUES ($uuid, 'text') 其中 $uuid 是第一步检索到的值