【发布时间】:2020-04-09 18:22:57
【问题描述】:
要求:
使用 RestAPI 调用填充唯一的 cateID, categoryName ,但我得到了整个记录。
表格
代码说明:
存储库:
@Repository
public interface CategoryRepository extends JpaRepository<xCategory,Integer>
{
// @Query("SELECT DISTINCT a.catID,a.categoryName FROM ccCategory a order by categoryName asc")
@Query("SELECT DISTINCT a.catID, a.categoryName FROM xCategory a order by categoryName asc")
List<ccCategory> getCategoryName();
}
休息控制器:
@RestController
@CrossOrigin(origins = "http://localhost:4200", maxAge = 3600)
public class HomeResource {
private final Logger log = LoggerFactory.getLogger(HomeResource.class);
@Autowired
CategoryRepository categoryRepository;
@GetMapping("/getAllCategory")
public List<ccCategory> getAllCategory() {
// public List<String> getAllCategory() {
System.out.println("***** Call : API getAllCategory() ******");
List<ccCategory> cCategory = categoryRepository.findAll();
return cCategory;
}
角度代码:
<label class="control-label">Category: </label>
<select [(ngModel)]="listAllCategory" name="xxcategory" class="form-control" required>
<option *ngFor="let xxcategory of listAllCategory" [value]="xxcategory.catID">
{{xxcategory.categoryName}}
</option>
</select>
问题: 下拉填充所有表值,但我只想要唯一值,例如一次 catID , categoryName。
【问题讨论】:
-
API 填充唯一数据对吗?
-
开始获取唯一数据 .... 仅在存储库中更改
-
ABHI 你是对的,但我的数据没有以 JSON 格式填充....任何具体原因它以 [[1,"A"],[2,"V"]
-
您检查过 RestAPI App 中的任何错误吗?
标签: angularjs spring-boot spring-boot-actuator