Spring Boot Framework Fresco Play Solutions

Spring Boot is a Java-Based Framework for building Microservices. The Course Id is 55960. It is not difficult to clear the final Assignment. But of the members difficult to feel to clear the hands-on Questions. These Answers are very helpful who are stuck to clear those questions. 

1. Sorting list of Candidates

1.E mployee.java

package com.example.demo.employee;
public class Employee implements Comparable < Employee > {

    private String name;
    private int age;
    private int exp;
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public int getExp() {
        return exp;
    }
    public void setExp(int exp) {
        this.exp = exp;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Employee(String name, int age, int exp) {
        super();
        this.name = name;
        this.age = age;
        this.exp = exp;
    }
    public Employee() {}

    @Override
    public int compareTo(Employee emp) {
        //replace your comparator here
        return (this.getAge() - emp.getAge());
    }



    2.E mployeeController



    package com.example.demo.employee;
    import java.util.Collections;
    import java.util.List;

    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    import java.util.ArrayList;
    @RestController
    public class EmployeeController {
        @Autowired
        private EmployeeService emp;
        //Put your code here
        @RequestMapping("/")
        public List < Employee > getEmpList() {
            //Put your code here
            List < Employee > e = emp.getEmployees();
            Collections.sort(e);
            return e;
        }

    }


    3.E mployeeService.java


    package com.example.demo.employee;

    import java.util.Arrays;

    import org.springframework.stereotype.Service;
    import java.util.List;
    import java.util.ArrayList;

    @Service
    public class EmployeeService {

        public List < Employee > getEmployees() {
            final List < Employee > demo = new ArrayList < > ();
            demo.add(new Employee("Sandhya", 20, 0));
            demo.add(new Employee("Kemp", 24, 2));
            demo.add(new Employee("Anil", 22, 3));
            demo.add(new Employee("Kumar", 30, 6));
            demo.add(new Employee("Tim", 32, 7));


            return demo;
        }
    }

}

2. Accessing Values from the application. properties.file

            fresco-course = Spring Boot

3) Print contents of the list along the sublist

ContentController.java

package com.example.demo.content;

import java.util.List;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

@RestController
public class ContentController {
//Put your code here.
@Autowired
private ContentService cs;

@RequestMapping("/")
public List < Category > getContentList() {
    List < Category > c = cs.getAllContent();
    return c;
}

}

ContentService.java

package com.example.demo.content;

import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;

import org.springframework.stereotype.Service;

@Service
public class ContentService {

//put your code here.
public List < Category > categories = new ArrayList < > ();

public List < Category > getAllContent() {

    List < Course > courses = new ArrayList < > ();
    courses.add(new Course(1, "Coursename", 200, 200, 1001));
    courses.add(new Course(2, "Coursename", 200, 200, 1001));
    courses.add(new Course(3, "Coursename", 200, 200, 1001));

    List < Category > categories = new ArrayList < > ();

    categories.add(new Category(1001, "Cloud Computing", "network of remote servers hosted on the internet to store", courses));
    categories.add(new Category(1002, "Software", "network of remote servers hosted on the internet to store", courses));
    categories.add(new Category(1003, "Networking", "network of remote servers hosted on the internet to store", courses));

    return categories;
}

}

Categories: Fresco Play

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *