# 从Java创建接口
上面章节的实现是通过可视化的方式来实现接口,对于比较复杂的场景,有些情况下需要使用原生 Java 代码来实现。更多细节请参考API开发规范 (opens new window)。
还是以前面实现的合同实体为例,假如实体类创建了Contract.java,我们可以通过 Java 创建接口。
package com.app.controller;
import fly.rest.data.annotation.Crud;
import fly.rest.data.crud.operation.CrudAll;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.app.entity.Contract;
@RestController
@RequestMapping("/contract")
@Tag(name = "Contract", description = "合同接口")
@Crud(entityClass = Contract.class)
public class ContractController implements CrudAll<Contract>{
// TODO: 这里实现扩展接口
}
通过实现 implements CrudAll<Contract> 接口,可以实现接口的增删改查,接口的地址为/contract。同时可以覆盖或者追加其他接口方法。