Spring boot 项目遇到返回数据本应该是Json格式但是却返回了String类型的数据

整合springboot 项目遇到不少的问题,感觉有点吃力,发出来求助一下大神

  1. 版本环境
    ide:Idea2018.1.2
    jdk:jdk1.8
    spring boot:1.5.2RELEASE
  2. pom文件
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.66limit</groupId>
<artifactId>moodel</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>resgiter</module>
        <module>reptile</module>
    </modules>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
    </parent>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Camden.SR6</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <!--eureka注册中心-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
        <!--负载均衡-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-ribbon</artifactId>
        </dependency>
        <!--spring boot依赖-->
        <!--对自动配置、日志记录和YAML支持,核心starter-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
           <!-- <exclusions>
                &lt;!&ndash; 排除自带的logback依赖 &ndash;&gt;
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>-->
        </dependency>
        <!--对Spring test支持,包括:Junit,Hamcrest,Mockito-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!--对web支持,包括RESTful,使用tomcat作为默认容器-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--解决外部容器报错区问题-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
        <!--实现spring boot项目的热部署,该依赖只在idea环境中有效-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
        <!--实现spring boot项目的热部署,eclipse中使用下面配置-->
        <!--<build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <fork>true</fork>
                    </configuration>
                </plugin>
            </plugins>
        </build>-->
        <!--juit测试工具类-->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <!--mysql数据库-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <!--mybatis-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.1.1</version>
        </dependency>
        <!-- pagehelper分页插件 -->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.3</version>
        </dependency>
        <!-- 通用mapper -->
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper-spring-boot-starter</artifactId>
            <version>RELEASE</version>
        </dependency>
        <!-- 阿里巴巴druid数据库连接池 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.0.18</version>
        </dependency>
        <!-- 阿里巴巴fastjson -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.8</version>
        </dependency>
        <!--log4j-->
       <!-- <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j</artifactId>
            <version>1.3.8.RELEASE</version>
        </dependency>-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.10</version>
        </dependency>
    </dependencies>
</project>

3 . 本来应该是返回Json格式的数据但是返回的却是String 类型的数据
这里写图片描述
4 . 附上controller代码

package com.limit.controller;

import com.github.pagehelper.PageInfo;
import com.limit.Model.Persion;
import com.limit.service.PersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author fxl
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2018-05-0915:45
 */
//
//@Controller
@RestController
public class PersionController {

    @Autowired
    private PersionService persionService;

    @RequestMapping("getPersionList")

    public List<Persion> getPersionList(){
       return persionService.getPersionList();
    }

    @RequestMapping("getPageInfo")
    //@ResponseBody
    public PageInfo<Persion> getPageInfo(int pageNum,int pageSize){
        PageInfo<Persion> pageInfo= persionService.listPage(1,10);
        return pageInfo;
    }
}

这样也不行

package com.limit.controller;

import com.github.pagehelper.PageInfo;
import com.limit.Model.Persion;
import com.limit.service.PersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author fxl
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2018-05-0915:45
 */
//
@Controller
//@RestController
public class PersionController {

    @Autowired
    private PersionService persionService;

    @RequestMapping("getPersionList")

    public List<Persion> getPersionList(){
       return persionService.getPersionList();
    }

    @RequestMapping("getPageInfo")
    @ResponseBody
    public PageInfo<Persion> getPageInfo(int pageNum,int pageSize){
        PageInfo<Persion> pageInfo= persionService.listPage(1,10);
        return pageInfo;
    }
}

Model

package com.limit.Model;

import lombok.Data;
import lombok.Generated;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;

/**
 * @author fxl
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2018-05-0915:20
 */

@Table(name = "Persion")
@Data
public class Persion implements Serializable {

    private static final long serialVersionUID = 8157040516270067074L;
    @Id
    @GeneratedValue(generator = "JDBC")
    private String id;

    private String name;

    private String age;

    private String address;



}

5.在controller 从新键个类试下
Controller

package com.limit.controller;

import com.limit.Model.TestModel;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author fxl
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2018-05-1814:54
 */
@RestController
public class TestController {

    @RequestMapping("testJson")
    public TestModel testJson(){
        TestModel testModel = new TestModel();
        testModel.setNamge("张三");
        testModel.setAge("134");
        return testModel;
    }
}

Model

package com.limit.Model;

import lombok.Getter;
import lombok.Setter;

/**
 * @author fxl
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2018-05-1814:57
 */
public class TestModel {
    @Getter
    @Setter
    private String namge;

    @Getter
    @Setter
    private String age;

}

6.怀疑是用了lombok的问题

package com.limit.Model;

import lombok.Getter;
import lombok.Setter;

/**
 * @author fxl
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2018-05-1814:57
 */
public class TestModel {

    private String namge;

    private String age;

    public String getNamge() {
        return namge;
    }

    public String getAge() {
        return age;
    }

    public void setNamge(String namge) {
        this.namge = namge;
    }

    public void setAge(String age) {
        this.age = age;
    }
}

问题还是没有解决,启动了别的项目发现没有这种问题,一直都在看什么有用就往项目里边整合什么,发现遇到一点问题都很难解决,所以决定系统化的学习一下springboot项目,网上找了一点资源,回头的笔记都记录在帖子里吧

  • 0
    点赞
  • 2
    评论
  • 0
    收藏
  • 打赏
    打赏
  • 扫一扫,分享海报

©️2022 CSDN 皮肤主题:点我我会动 设计师:我叫白小胖 返回首页

打赏作者

fanxlxs

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值