Mysql 如何更正sql语句以给出正确的结果

Mysql 如何更正sql语句以给出正确的结果,mysql,spring-boot,Mysql,Spring Boot,我正在端口3306上运行一个本地MySQL服务器,模式为“sys”,表为“users” 现在我有了一个小的spring启动应用程序来查询该表中的所有条目。 该表的模型为: package com.example.databaseneu.model; import javax.persistence.Entity; import javax.persistence.Id; @Entity public class Users { @Id // @Column(name = "id") pri

我正在端口3306上运行一个本地MySQL服务器,模式为“sys”,表为“users”

现在我有了一个小的spring启动应用程序来查询该表中的所有条目。 该表的模型为:

package com.example.databaseneu.model;

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class Users {

@Id
// @Column(name = "id")
private int id;
// @Column(name = "name")
private String name;
// @Column(name = "salary")
private int salary;
// @Column(name = "team_name")
private String team_name;

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public int getSalary() {
    return salary;
}

public void setSalary(int salary) {
    this.salary = salary;
}

public String getTeam_name() {
    return team_name;
}

public void setTeam_name(String team_name) {
    this.team_name = team_name;
}}
连接正常,但当我看到白标签错误页面时,查询似乎没有给出正确的结果。 查询以从表中获取所有元素(由存储库自动生成)

所以我不确定我是把实体定义错了还是其他什么东西放在一起了 @Column标记不起作用

---编辑---

package com.example.databaseneu.controller;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.stereotype.Controller;
导入org.springframework.web.bind.annotation.GetMapping;
导入org.springframework.web.bind.annotation.RequestMapping;
导入org.springframework.web.bind.annotation.RequestParam;
导入org.springframework.web.bind.annotation.ResponseBody;
导入com.example.databaseneu.model.Users;
导入com.example.databaseneu.repository.UserRepository;
@Controller//这意味着该类是一个控制器
@RequestMapping(path=“/demo”)//这意味着URL以/demo开头(在应用程序路径之后)
公共类主控制器{
@自动连线
私有用户存储库用户存储库;
@GetMapping(路径=“/add”)
public@ResponseBody String addNewUser(@RequestParam String name,@RequestParam int salary,
@RequestParam字符串(团队名称){
用户n=新用户();
n、 集合名(名称);
n、 固定工资;
n、 SETTAM_名称(团队名称);
userRepository.save(n);
返回“已保存”;
}
@GetMapping(path=“/all”)
公共Iterable getAllUsers(){
返回userRepository.findAll();
}}

因此,我导航到localhost:8080/demo/all

除了一件事之外,您已经编写了所有正确的代码。用
@ResponseBody
注释标记返回类型——类似于
addNewUser
方法

@GetMapping(path = "/all")
public @ResponseBody Iterable<Users> getAllUsers() {
    return userRepository.findAll();
}}
@GetMapping(path=“/all”)
public@ResponseBody Iterable getAllUsers(){
返回userRepository.findAll();
}}

希望这能奏效。如果您仍然面临问题,请在此处发布。

除了一件事之外,您已经写出了所有正确的内容。用
@ResponseBody
注释标记返回类型——类似于
addNewUser
方法

@GetMapping(path = "/all")
public @ResponseBody Iterable<Users> getAllUsers() {
    return userRepository.findAll();
}}
@GetMapping(path=“/all”)
public@ResponseBody Iterable getAllUsers(){
返回userRepository.findAll();
}}

希望这能奏效。如果您仍然面临问题,请将其发布在此处。

您是否可以将正在执行
存储库.findAll()的代码发布在此处。
?还有处理程序映射,即代码的
@RequestMapping/@GetMapping
部分。您可能需要访问该处理程序才能查看JSON响应。希望编辑足够您可以在执行
存储库的位置发布代码。findAll()
?还有处理程序映射,即代码的
@RequestMapping/@GetMapping
部分。您可能需要访问该处理程序才能查看JSON响应。希望编辑足够了
@GetMapping(path = "/all")
public @ResponseBody Iterable<Users> getAllUsers() {
    return userRepository.findAll();
}}