@TableField(value = "gbe_id")
private String gbe_id;
当我使用mybatis-plus 语句查询时,开启了驼峰配置,但是我的字段不想用驼峰命名,我有什么办法,可以在我查询的时候不为空
gbe_id为数据库字段
针对该问题,可以使用Mybatis-plus提供的@TableField注解来指定表中的字段名,在查询时使用下划线命名而不是驼峰命名即可。具体实现步骤如下:
@Data
@TableName(value = "table_name")
public class MyEntity {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@TableField(value = "gbe_id")
private String gbeId;
// 其他属性
}
@Service
public class MyService {
@Autowired
private MyMapper myMapper;
public List<MyEntity> findByGbeId(String gbeId) {
QueryWrapper<MyEntity> qw = new QueryWrapper<>();
qw.eq("gbe_id", gbeId);
return myMapper.selectList(qw);
}
}
这样查询语句中使用的字段名即为"gbe_id",保证了查询结果的正确性。
另外,如果需要动态生成随机的ID,可以使用提供的随机ID工具类:
public class IdUtils {
public static String getId(){
return UUID.randomUUID().toString().replaceAll("-","");
}
}
调用getId()方法即可生成一个随机ID,可以用于插入新数据时的ID字段值。