DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • The SPACE Framework for Developer Productivity
  • Getting Started With the YugabyteDB Managed REST API
  • Top 10 Pillars of Zero Trust Networks
  • How To Approach Java, Databases, and SQL [Video]

Trending

  • The SPACE Framework for Developer Productivity
  • Getting Started With the YugabyteDB Managed REST API
  • Top 10 Pillars of Zero Trust Networks
  • How To Approach Java, Databases, and SQL [Video]
  1. DZone
  2. Coding
  3. Frameworks
  4. Angular Datatables with different wrappers in Java Spring, along with the DataTablesInput and DataTablesOutput

Angular Datatables with different wrappers in Java Spring, along with the DataTablesInput and DataTablesOutput

Use Angular Datatables with different wrappers in Java's Spring framework, along with the DataTablesInput and DataTablesOutput methods when using custom queries.

Bosco Ferrao user avatar by
Bosco Ferrao
·
Updated Jan. 17, 20 · Tutorial
Like (5)
Save
Tweet
Share
19.40K Views

Join the DZone community and get the full member experience.

Join For Free

For the Angular 5 client-side, check out the below repository:

https://l-lin.github.io/angular-datatables/#/basic/server-side-angular-way

Server-Side Development With Spring

In the Spring controller, write a wrapper called NewWrapper and use NewWrapperService:

@RequestMapping(value = "/get", method = RequestMethod.POST)
  public DataTablesOutput<NewWrapper> listPOST(@Valid @RequestBody DataTablesInput input) {
  return newWrapperService.findAll(input);
}

In the Spring service, wrap it in the way shown below. Change the DataTablesInput values, giving proper overrides of JSON input data and the DataTablesOutput values, using ModelMapper or your own mapper, finally overriding OldObjectPaginate. Write your own custom query for repository currentRepo.findAll.

@Transactional
public DataTablesOutput<NewWrapper> findAll(DataTablesInput input) {
  DataTablesInput input1 = new DataTablesInput();
  input1.setDraw(input.getDraw());
  input1.setOrder(input.getOrder());
  input1.setStart(input.getStart());
  input1.setLength(input.getLength());
  input1.setSearch(input.getSearch());
  List<Column> columns = input.getColumns();
  for(Column column:columns) {
    if (column.getData().equals("levelType")) {
    column.setData("id.levelType");
    }
    else if (column.getData().equals("levelCode")) {
    column.setData("id.levelCode");
    }
  }
  input1.setColumns(columns);
  DataTablesOutput<OldObjectPaginate> dataTableOutput = currentRepo.findAll(input1);
  DataTablesOutput<NewWrapper> dataTableResult = new DataTablesOutput<NewWrapper>();
  dataTableResult.setDraw(dataTableOutput.getDraw());
  dataTableResult.setRecordsFiltered(dataTableOutput.getRecordsFiltered());
  dataTableResult.setRecordsTotal(dataTableOutput.getRecordsTotal());
  /*TypeMap<OldObjectPaginate, NewWrapper> typeMap = modelMapper.getTypeMap(OldObjectPaginate.class, NewWrapper.class);
  if(typeMap==null) {
  modelMapper.addMappings(new PropertyMap<OldObjectPaginate, NewWrapper>() {
    @Override
    protected void configure() {
    map().setLevelCode(source.getId().getLevelCode());
    map().setLevelType(source.getId().getLevelType());
    }
  });
  }*/
  List<NewWrapper> newWrapperList = new ArrayList<>();
  for(OldObjectPaginate data: dataTableOutput.getData()) {
    NewWrapper newWrapper = new NewWrapper();
    newWrapper.setLevelCode(data.getId().getLevelCode());
    newWrapper.setLevelType(data.getId().getLevelType());
    newWrapperList.add(newWrapper);
  }
  //dataTableResult.setData(modelMapper.map(dataTableOutput.getData(), new TypeToken<List<NewWrapper>>() {}.getType()));
  dataTableResult.setData(newWrapperList);
  return dataTableResult;
}
Spring Framework AngularJS Java (programming language)

Opinions expressed by DZone contributors are their own.

Trending

  • The SPACE Framework for Developer Productivity
  • Getting Started With the YugabyteDB Managed REST API
  • Top 10 Pillars of Zero Trust Networks
  • How To Approach Java, Databases, and SQL [Video]

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: