我正在努力解决这个问题。我每次在repository.save(CustomerDetails)中添加主类时都会收到错误消息。当我点击错误时,我要求添加一个依赖项,但它并没有告诉我要添加的依赖项。
我怎么知道?
这是我的班级:
package com.example.Customer.Application;
import com.example.Customer.CustomerRepository.CustomerDetailRepository;
import com.example.Customer.Model.CustomerDetails;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.util.ArrayList;
import java.util.List;
@SpringBootApplication
public class AccountApplication {
public static void main(String[] args) {
}
private void name(CustomerDetailRepository repository) {
List<CustomerDetails> cd = new ArrayList<>();
cd.add(new CustomerDetails(1, "Foo", "Bar"));
cd.add(new CustomerDetails(2, "Foo1", "Bar1"));
CustomerDetails cdd = new CustomerDetails(1, "a", "b");
{
}
repository.save(CustomerDetails); this is where the error is.
}
}
这是我的主要课程:
package com.example.Customer.Model;
import com.example.Customer.CustomerApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import javax.annotation.Generated;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
@Entity
public class CustomerDetails {
private Long id;
private String name;
private String address;
public CustomerDetails() {
}
public CustomerDetails(long id, String name, String address) {
this.id = id;
this.name = name;
this.address = address;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
这是我的控制器代码
package com.example.Customer.Controller;
import com.example.Customer.Model.CustomerDetails;
import com.sun.org.apache.bcel.internal.generic.RETURN;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Generated;
import java.util.ArrayList;
import java.util.List;
@RestController
public class Customerapplication {
@RequestMapping(method = RequestMethod.GET, path = "/findcustomer")
public CustomerDetails createnewcustomerrecord() {
return new CustomerDetails(1, "Sarah", "88 strong road");
}
}
有任何帮助吗?你知道我可以添加什么依赖来修复这个bug吗?