跳到主要内容

MyBatis 集成

返回文档导航


JSONMap 可与 MyBatis 配合处理数据库中的 JSON 字段。

示例

// Mapper
@Mapper
public interface ProductMapper {
@Select("SELECT * FROM product WHERE id = #{id}")
Product selectById(Long id);
}

// Service
@Service
public class ProductService {

public Product getById(Long id) {
Product product = productMapper.selectById(id);

// JSON 字段自动转换
if (product.getExtInfo() != null) {
JSONMap ext = new JSONMap(product.getExtInfo());
product.setBrand(ext.getStr("brand"));
product.setModel(ext.getStr("model"));
}

return product;
}
}

上一节:SpringMVC集成 | 返回文档导航 | 下一节:AI辅助开发 →