有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Postman在查询rest端点后返回错误消息

收到错误信息后,我已经尽我所能排除了故障,但它不起作用。我一直收到一条错误信息,可能是什么问题

这是控制器:

package com.Controller;

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 com.Model.*;
import com.Service.UserAccountService;


@RestController
public class UserController {

    @Autowired
    UserAccountService userService;

    @RequestMapping(path = "/users/")
    public List<UserAccount> getUsers()
    {
        return userService.getUsers();
    }
}

这是服务接口和ServiceImpl:

package com.Service;

import java.util.List;

import com.Exceptions.UserNotFoundException;
import com.Model.UserAccount;


public interface UserAccountService {

    UserAccount save(UserAccount user) throws Exception;

    List<UserAccount> getUsers();

    UserAccount update(UserAccount user, int id) throws Exception;

    //UserAccount delete(UserAccount user) throws Exception;

    UserAccount userAccountByKey(int id) throws UserNotFoundException;
   }

以下是服务实现的代码:

package com.ServiceImpl;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.Exceptions.UserNotFoundException;
import com.Model.UserAccount;
import com.Repository.UserRepo;
import com.Service.UserAccountService;

@Service
public class UserAccountServiceImplementation implements UserAccountService {

@Autowired  
private UserRepo repo;


@Override
public List<UserAccount> getUsers() {
    // TODO Auto-generated method stub
    List<UserAccount> users = new ArrayList<>();
    repo.findAll().forEach(users::add);
    return users;
}

以下是模型的代码:

package com.Model;

import java.util.Date;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
//import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

@Entity
public class UserAccount {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int id;
    @NotNull
    private String userName;
    private String email;
    @Temporal(TemporalType.DATE)
    private Date dateCreated;
    @OneToMany(mappedBy = "userAccount", fetch = FetchType.EAGER)
    private Set <Transaction> transactions = new HashSet<>();


    public UserAccount(int id) {
        super();
        this.id = id;
    }


    public UserAccount(String userName, String email, Date dateCreated) {
        super();
        this.userName = userName;
        this.email = email;
        this.dateCreated = dateCreated;
    }


    public UserAccount(int id, String userName, String email, Date dateCreated) {
        super();
        this.id = id;
        this.userName = userName;
        this.email = email;
        this.dateCreated = dateCreated;
    }


    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public Date getDateCreated() {
        return dateCreated;
    }
    public void setDateCreated(Date dateCreated) {
        this.dateCreated = dateCreated;
    }
    public Set<Transaction> getTransactions() {
        return transactions;
    }
    public void setTransactions(Set<Transaction> transactions) {
        this.transactions = transactions;
    }


    @Override
    public int hashCode() {
        return Objects.hash(id,userName,email,dateCreated);

    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        UserAccount other = (UserAccount) obj;
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder ("UserAccount{");
        sb.append("id=").append(id);
        sb.append(",username='").append(userName).append('\'');
        sb.append(",email='").append(email).append('\'');
        sb.append(",date='").append(dateCreated).append('\'');
        sb.append('}');
        return sb.toString();
    }
}

这是我的申请表。物业数据:

  spring.h2.console.enabled=true
  spring.datasource.platform=h2
  spring.datasource.driverClassName=org.h2.Driver
  spring.datasource.url=jdbc:h2:mem:mojec
  spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
  spring.jpa.hibernate.ddl-auto=update
  spring.datasource.data=classpath:data.sql

这让我担心


共 (0) 个答案