使用JavaSpring引导有什么问题

使用JavaSpring引导有什么问题,java,spring-boot,jsp,jpa,Java,Spring Boot,Jsp,Jpa,我尝试使用JavaSpringBoot和Mysql搜索所有数据,但是当我运行代码时,我发现了这个错误 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'emp0_.get_company_name' in 'field list' 这是我的控制器代码 package com.example.rest.controller; import com.example.rest.Emp; impor

我尝试使用JavaSpringBoot和Mysql搜索所有数据,但是当我运行代码时,我发现了这个错误

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'emp0_.get_company_name' in 'field list'
这是我的控制器代码

package com.example.rest.controller;


import com.example.rest.Emp;
import com.example.rest.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@RestController
@RequestMapping("emp")
public class EmpController {
    @Autowired
    private EmpService empService;

    @GetMapping(produces = {MediaType.APPLICATION_JSON_VALUE})
    public ResponseEntity<List<Emp>> getAllEmps() {
        List<Emp> emps = empService.findAll();
        return new ResponseEntity<List<Emp>>(emps,HttpStatus.OK);
    }
}
这是我的Emp代码

package com.example.rest;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.io.Serializable;

@Entity
@Table(name = "company")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Emp implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue (strategy = GenerationType.IDENTITY)
    private Integer idx;
    private String company_id;
    private String getCompany_name;
}
所以,如果有人知道问题出在哪里,请告诉我,如果你没有用解决方案提醒我的话


谢谢大家!

在EmpServiceImpl类上使用@Service注释,在empservicerepository上使用@Repository注释

@服务
公共类EmpServiceImpl实现EmpService{
@自动连线
私有存储库;
@凌驾
公共列表findAll(){
List emps=new ArrayList();
empRepository.findAll().forEach((e->emps.add(e));
返回EMP;
}
}
@存储库
公共接口存储库扩展了JpaRepository{
}

需要在下面的类上添加注释:

@Service  
class EmpServiceImpl implements EmpService {

}

答案重复。正在工作,但我得到了com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:未知列“字段列表”中的“emp0”。get_company_name”此错误您知道为什么会出现此错误吗?getCompany_name表中不存在此列。您必须更改该表,并在company表中添加一列getCompany_name。对于开发环境,您可以在应用程序yml中设置jpa:hibernate:ddl auto:update,这样它就可以自动更新。请始终注意,每当在实体类中添加新字段(即新列)时,您都需要使用jpa ddl设置重新启动项目以进行更新,或者手动在数据库中添加列,以避免此类冲突。你可以参考-了解更多关于相同的内容。
package com.example.rest.service;

import com.example.rest.Emp;
import com.example.rest.repository.EmpRepository;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;
@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpRepository empRepository;

    @Override
    public List<Emp> findAll() {

        List<Emp> emps= new ArrayList<>();
        empRepository.findAll().forEach((e -> emps.add(e)));

        return emps;
    }
}
package com.example.rest;

import com.example.rest.repository.EmpRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@SpringBootApplication
@Configuration
public class Application {
    @Autowired
    EmpRepository empRepository;
    public static void main(String[] args) {
        SpringApplication.run(Application.class , args);
    }
}
package com.example.rest;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.io.Serializable;

@Entity
@Table(name = "company")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Emp implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue (strategy = GenerationType.IDENTITY)
    private Integer idx;
    private String company_id;
    private String getCompany_name;
}
@Service  
class EmpServiceImpl implements EmpService {

}