我正在開發一個應用程序,前端部分使用AngularJS,後端使用Spring。AngularJS Spring排序字段名稱
我主要有兩個實體類:
@Entity
public class Project implements Serializable {
private static final long serialVersionUID = 1L;
/**
* idProject
*/
@Id
@GeneratedValue(strategy=AUTO, generator="PROJECT_SEQ")
private Integer idProject;
/**
* name
*/
@Column(name="PROJECT_NAME")
private String name;
/**
* date
*/
@Column(name="PROJECT_DATE")
private Date date;
/**
* technology
*/
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="ID_TECHNOLOGY", nullable=true)
@ForeignKey(name = "FK_PROJECT_TECHNOLOGY")
private Technology technology;
和
@Entity
public class Technology implements Serializable {
/**
* idTechnology
*/
@Id
@Column(name="ID_TECHNOLOGY", length=2)
private Integer idTechnology;
/**
* ID = 0 ==> "TechA"
* ID = 1 ==> "TechB";
* ID = 2 ==> "TechC";
* ID = 3 ==> "TechD";
* ID = 4 ==> "TechE"
*/
@Column(name="TECHNOLOGY", length=30)
private String technology;
我想要做的是,爲AngularJS應用提供的項目名單。
對於我創建了一個控制器:
@Autowired
private ProjectAssembler projectAssembler;
@RequestMapping(method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public PagedResources<ProjectResource> findAll(
@PageableDefault Pageable page,
PagedResourcesAssembler<Project> assembler) {
//Request
Page<Project> projectPage = projectRepo.findAll(page);
PagedResources<ProjectResource> resources = assembler.toResource(projectPage, projectAssembler);
return resources;
}
正如你所看到的,我使用HATEOAS用於創建JSON資源列表,並提供瀏覽鏈接。除此之外,我正在使用推土機將Project類映射到ProjectAssembler中的ProjectResource類。
public class ProjectResource extends ResourceSupport {
private Integer idProject;
private String projectName;
private Date projectDate;
private String technologyName;
和彙編
@Component
public class ProjectResourceAssembler extends ResourceAssemblerSupport<Project, ProjectResource> {
@Autowired
private Mapper dozerBeanMapper;
public ProjectResourceAssembler() {
super(ProjectController.class, ProjectResource.class);
}
@Override
public ProjectResource toResource(Project entity) {
ProjectResource resource = createResourceWithId(entity.getIdProject(), entity);
return resource;
}
@Override
protected ProjectResource instantiateResource(Project entity) {
return dozerBeanMapper.map(entity, ProjectResource.class);
}
}
的目標是,我想在前端應用AngularJS不同領域的名稱,在後端。 例如,ProjectResources字段是前端中項目表列的列。
我的問題是當我想在angularjs應用中使用排序,我使用前端字段名稱,當我想要過濾時,所以當控制器接收到頁面屬性時,它不知道排序的字段。
我的問題是:你有任何建議,以幫助我使用排序?