0

My RestController :

@RestController
public class TeacherRestController {

private static final String TEACHER_MODEL = "teacher";

@Autowired
TeacherService teacherService;

@GetMapping("/rest/teachers/getAll")
public List<Teacher> getAllTeachers() {
    return teacherService.getAll();
}
}

Model Teacher :

@Entity
@ToString
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "teachers", schema = "public")
public class Teacher {
@Id
@Column(name="teacher_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int teacherId;
@Column(name = "teacher_name")
@NotNull
@Size(min = 4,max = 75,message = "Teacher name should be not less than 4 symbols and not more than 75 symbols!")
private String teacherName;
@Column(name = "position")
@NotNull
@Size(min = 3,max = 50,message = "Teacher position should be not less than 3 symbols and not more than 50 symbols!")
private String position;

My index.html :

enter image description here

And angular.js :

var app = angular.module("myApp", []);
app.controller('myCtrl', function ($scope, $http) {

$http.get('http://localhost:8081/rest/teachers/getAll')
    .then(function(response) {
        $scope.myWelcome = response.data;
    });
});

On index.html teachers doesn't show, but on this address http://localhost:8081/rest/teachers/getAll I have teachers in JSON.

enter image description here

1
  • I do not remember clearly how was in in AngularJS but my feeling is that you don't have the teacher object set on the $scope Commented Jan 25, 2021 at 16:22

1 Answer 1

1

It looks like the problem is in angularjs. Take a look here https://docs.angularjs.org/tutorial/step_02

When the data is loading from server you assign it to $scope.myWelcome = response.data;

Then you access your data in the template using teacher. which iss not defined on the $scope.

Try renaming myWelcome into teacher.

Sign up to request clarification or add additional context in comments.

1 Comment

And he should add ng for for his table data integration

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.