Java Spring Rest API 404错误

时间:2018-04-29 10:50:53

标签: java spring rest api postman

我在Java Spring(Gradle)中创建了一个RestApi。当编译代码,并在Postman中尝试它时返回404.我不知道为什么,这非常烦人。

package arma.Arma.RestController;

import arma.Arma.Service.UserService;
import arma.Arma.doman.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping(value = "api/user")
public class UserRestController {

    @Autowired
    UserService userService;

    @RequestMapping(value = "/all", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public List<User> getAll() {
        return userService.getAll();
    }
}

UserService

package arma.Arma.Service;

import arma.Arma.Repository.UserRepository;
import arma.Arma.doman.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    @Autowired
    UserRepository userRepository;

    public List<User> getAll() {
        return userRepository.findAll();
    }
}

用户

package arma.Arma.doman;

import javax.persistence.*;

@Entity
@Table(name = "users")
public class User {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "user_id", nullable = false)
    private Long id;
    @Column(name = "username", nullable = false)
    private String username;
    @Column(name = "email", nullable = false)
    private String email;
    @Column(name = "password", nullable = false)
    private String password;
    @Column(name = "user_type", nullable = false)
    private UserType type;

    public Long getId() {
        return id;
    }

    public void setId(Long 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 String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

我读了很多解决方案,但没有一个能帮到你。此外,它是第一次出现,我在许多机器中配置了Tomcat,Java,MySql等,现在我真的很无奈。

0 个答案:

没有答案