找不到类型为的返回值的转换器:class java.util.arraylist(spring boot)

des4xlb0  于 2021-06-21  发布在  Mysql
关注(0)|答案(4)|浏览(491)

我对springboot还不熟悉,正在研究数据库连接。所有相关的类都在这里,只有具有run方法的主类没有发布。
这是给我的错误,没有找到转换器的arraylist。
如果我做错了什么,请帮帮我。
//客户.java

package springbootfirstapp.domain;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Customer {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="id")
private int id;

private String name;
private String phone;

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 String getPhone() {
return phone;
}

public void setPhone(String phone) {
    this.phone = phone;
}

public Customer(int id, String name, String phone) {
    super();
    this.id = id;
    this.name = name;
    this.phone = phone;
}

public Customer() {
    super();
}
}

//客户控制器.java

package springbootfirstapp.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.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import springbootfirstapp.domain.Customer;
import springbootfirstapp.repo.CustomerRepo;

@RestController
@RequestMapping("/customer")
public class CustomerController {

@Autowired
CustomerRepo rp;

@RequestMapping("/findall")
@ResponseBody
public List<Customer> findall()
{
    return rp.findAll();
}
}

//客户报告.java

package springbootfirstapp.repo;
import org.springframework.data.jpa.repository.JpaRepository;
import springbootfirstapp.domain.Customer;
public interface CustomerRepo extends JpaRepository<Customer, Integer> {
}

//pom.xml文件

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>SpringBootFirstApp</groupId>
<artifactId>springbootfirstapp</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.5.RELEASE</version>
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEndoing>UTF-  8</project.reporting.outputEndoing>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>

</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
</project>

堆栈跟踪:

ajsxfq5m

ajsxfq5m1#

此类错误的一般准则是检查:
无参数构造函数
getter和setters
Jackson属地
由于前两个不是问题,请尝试添加以下两个依赖项,并让我们知道它是否工作。

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.4.3</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.4.3</version>
</dependency>
yduiuuwa

yduiuuwa2#

将此依赖项添加到 pom.xml ```

com.fasterxml.jackson.core
jackson-databind
2.8.1

mrzz3bfm

mrzz3bfm3#

如果我正确理解你的问题,你需要在pom中添加jackson mapper。你能试一下,看看你的转换器问题得到解决。

aelbi1ox

aelbi1ox4#

谢谢大家的帮助。。。这个问题可以通过添加jacksonMap器依赖项来解决

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.2</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.5.2</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.5.2</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.5.2</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
<version>2.5.2</version>
</dependency>

相关问题