Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Id
- //@GeneratedValue(strategy= GenerationType.IDENTITY)
- private ObjectId id;
- @NotNull
- @Length(min=4)
- @Field("name")
- private String name;
- @NotNull
- @Length(min=5)
- @Field("teamName")
- private String teamName;
- @NotNull
- @Field("salary")
- @Max(52125)
- private Long salary;
- public Users()
- {
- }
- public Users(ObjectId id, String name, String teamName, Long salary) {
- this.id = id;
- this.name = name;
- this.teamName = teamName;
- this.salary = salary;
- }
- public ObjectId getId() {
- return id;
- }
- public void setId(ObjectId id) {
- this.id = id;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getTeamName() {
- return teamName;
- }
- public void setTeamName(String teamName) {
- this.teamName = teamName;
- }
- public Long getSalary() {
- return salary;
- }
- public void setSalary(Long salary) {
- this.salary = salary;
- }
- private UserRepository userRepository;
- private MongoTemplate mongoTemplate =
- new MongoTemplate(new MongoClient("localhost"),"db");
- public UsersResource(UserRepository userRepository) {
- this.userRepository = userRepository;
- }
- @PostMapping("/createuser")
- public HttpStatus createUser(@RequestBody Users user) {
- userRepository.save(user);
- return HttpStatus.CREATED;
- }
- @GetMapping("/getallusers")
- public List<Users> getAll() {
- return userRepository.findAll();
- }
- @PostMapping("/deleteuser")
- public void deleteUser(@RequestParam (value = "userid")Integer id) {
- userRepository.delete(id);
- }
Add Comment
Please, Sign In to add comment