我有一个与客户打交道的Angular 2应用程序和一个弹簧休息后端.客户对象有一个客户类型,也是一个对象,我在客户表单上下拉工作,以便将对象存储为值,但我无法弄清楚如何选择正确的客户类型现有客户已加载到表单中.
<select class="form-control" required [(ngModel)]="customer.customerType" >
<option *ngFor="let ct of customerTypes" [ngValue]="ct">{{ct.customerType}}</option>
</select>
Run Code Online (Sandbox Code Playgroud)
在上面的代码段中,如果客户已有客户类型,则下拉列表将不会选择任何值.我记得使用ngOptions解决了angular1的相同问题:
<select ng-model="customer.customerType"
ng-options="customerType.customerType for customerType in customerTypes
track by customerType.customerType" >
</select>
Run Code Online (Sandbox Code Playgroud)
所以,我的问题是,如何复制Angular1在Angular 2中解决这个问题的方式
我有一个Spring数据存储库,其中包含以下方法:
public interface ImportAssetWrapperRepository extends PagingAndSortingRepository<ImportAssetWrapper, Long> {
ImportAssetWrapper findByAssetId(String assetId);
List<ImportAssetWrapper> findByAssetId(String assetId, PageRequest pageRequest);
Run Code Online (Sandbox Code Playgroud)
在调用这些方法的控制器中,findAssetById(String assetId)工作正常,表明查询的结构是正确的.
尝试findAll(可分页可分页)也可以正常工作,因此存储库的Pageable方面也可以正常工作(至少对于这个默认方法).
但是,当我尝试使用List findByAssetId(String assetId,PageRequest pageRequest)时,使用:
for(ImportAssetWrapper ia : repository.findByAssetId("asset-version-123456",pr)){
log.info("Processing new import asset: " + ia.getFilePath());
}
Run Code Online (Sandbox Code Playgroud)
我得到以下异常:
java.util.NoSuchElementException: null
at java.util.ArrayList$Itr.next(ArrayList.java:854) ~[na:1.8.0_45]
at java.util.Collections$UnmodifiableCollection$1.next(Collections.java:1042) ~[na:1.8.0_45]
at org.springframework.data.jpa.repository.query.CriteriaQueryParameterBinder.bind(CriteriaQueryParameterBinder.java:63) ~[spring-data-jpa-1.10.3.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.ParameterBinder.bind(ParameterBinder.java:100) ~[spring-data-jpa-1.10.3.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.ParameterBinder.bindAndPrepare(ParameterBinder.java:160) ~[spring-data-jpa-1.10.3.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.ParameterBinder.bindAndPrepare(ParameterBinder.java:151) ~[spring-data-jpa-1.10.3.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$QueryPreparer.invokeBinding(PartTreeJpaQuery.java:218) ~[spring-data-jpa-1.10.3.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$QueryPreparer.createQuery(PartTreeJpaQuery.java:142) ~[spring-data-jpa-1.10.3.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.doCreateQuery(PartTreeJpaQuery.java:78) ~[spring-data-jpa-1.10.3.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.createQuery(AbstractJpaQuery.java:188) ~[spring-data-jpa-1.10.3.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.JpaQueryExecution$CollectionExecution.doExecute(JpaQueryExecution.java:118) ~[spring-data-jpa-1.10.3.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:82) ~[spring-data-jpa-1.10.3.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:114) ~[spring-data-jpa-1.10.3.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:104) ~[spring-data-jpa-1.10.3.RELEASE.jar:na] …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个抽象类来执行所需的常见REST操作,但如果我正在尝试做的事情是可能的话,则无法解决.我已经尝试了很多方法,但是已经将下面的代码剥离了,直到它应该如何在我脑海中起作用
根据以下建议更新课程.现在的问题是具体类中的构造函数无效,因为CustomerRepository不能分配给JpaRepository,尽管它扩展了该接口.
AbstractRestController
public abstract class AbstractRestController<T> {
private final JpaRepository<T, Serializable> repository;
public AbstractRestController(JpaRepository<T, Serializable> repository) {
this.repository = repository;
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public ResponseEntity<JsonResponseBody<T>> getOne(@PathVariable Long id) {
T restObj = repository.findOne(id);
JsonResponseBody<T> response = new JsonResponseBody<>(ResponseStatus.SUCCESS, restObj);
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON_UTF8).body(response);
}
protected JpaRepository<T, Serializable> getRepository() {
return repository;
}
}
Run Code Online (Sandbox Code Playgroud)
CustomerController
@RestController
@RequestMapping(value = "/api/v1/customer")
public class CustomerController extends AbstractRestController<Customer> {
@Autowired
public CustomerController(CustomerRepository repository){
super(repository);
}
}
Run Code Online (Sandbox Code Playgroud)
CustomerRepository
public interface CustomerRepository extends JpaRepository<Customer, …Run Code Online (Sandbox Code Playgroud)