2025.9.17日软件工程学习日志
今日设计了hbase的后端插入数据代码
`// Java示例代码
public void insertAchievement(Achievement achievement) throws IOException {
try (Connection connection = ConnectionFactory.createConnection(config);
Table table = connection.getTable(TableName.valueOf("achievements"))) {
Put put = new Put(Bytes.toBytes(achievement.getResultId()));
// 添加基本信息到info列族
put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("name"), Bytes.toBytes(achievement.getName()));
put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("type"), Bytes.toBytes(achievement.getType()));
put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("keywords"), Bytes.toBytes(String.join(",", achievement.getKeywords())));
put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("completionTime"), Bytes.toBytes(achievement.getCompletionTime()));
put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("innovation"), Bytes.toBytes(achievement.getInnovation()));
put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("subjects"), Bytes.toBytes(String.join(",", achievement.getSubjects())));
put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("industry"), Bytes.toBytes(achievement.getIndustry()));
// 添加详细内容到detail列族
put.addColumn(Bytes.toBytes("detail"), Bytes.toBytes("overview"), Bytes.toBytes(achievement.getOverview()));
put.addColumn(Bytes.toBytes("detail"), Bytes.toBytes("detail"), Bytes.toBytes(achievement.getDetail()));
table.put(put);
}
}`

浙公网安备 33010602011771号