整合springboot 项目遇到不少的问题,感觉有点吃力,发出来求助一下大神
- 版本环境
ide:Idea2018.1.2
jdk:jdk1.8
spring boot:1.5.2RELEASE - pom文件
<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.0modelVersion>
<groupId>com.66limitgroupId>
<artifactId>moodelartifactId>
<packaging>pompackaging>
<version>1.0-SNAPSHOTversion>
<modules>
<module>resgitermodule>
<module>reptilemodule>
modules>
<parent>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-parentartifactId>
<version>1.5.2.RELEASEversion>
parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-dependenciesartifactId>
<version>Camden.SR6version>
<type>pomtype>
<scope>importscope>
dependency>
dependencies>
dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-starter-eureka-serverartifactId>
dependency>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-starter-eurekaartifactId>
dependency>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-starter-ribbonartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starterartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-testartifactId>
<scope>testscope>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-tomcatartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-devtoolsartifactId>
<optional>trueoptional>
dependency>
<dependency>
<groupId>junitgroupId>
<artifactId>junitartifactId>
<scope>testscope>
dependency>
<dependency>
<groupId>mysqlgroupId>
<artifactId>mysql-connector-javaartifactId>
dependency>
<dependency>
<groupId>org.mybatis.spring.bootgroupId>
<artifactId>mybatis-spring-boot-starterartifactId>
<version>1.1.1version>
dependency>
<dependency>
<groupId>com.github.pagehelpergroupId>
<artifactId>pagehelper-spring-boot-starterartifactId>
<version>1.2.3version>
dependency>
<dependency>
<groupId>tk.mybatisgroupId>
<artifactId>mapper-spring-boot-starterartifactId>
<version>RELEASEversion>
dependency>
<dependency>
<groupId>com.alibabagroupId>
<artifactId>druidartifactId>
<version>1.0.18version>
dependency>
<dependency>
<groupId>com.alibabagroupId>
<artifactId>fastjsonartifactId>
<version>1.2.8version>
dependency>
<dependency>
<groupId>org.projectlombokgroupId>
<artifactId>lombokartifactId>
<version>1.16.10version>
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 getPersionList(){
return persionService.getPersionList();
}
@RequestMapping("getPageInfo")
//@ResponseBody
public PageInfo getPageInfo(int pageNum,int pageSize){
PageInfo 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 getPersionList(){
return persionService.getPersionList();
}
@RequestMapping("getPageInfo")
@ResponseBody
public PageInfo getPageInfo(int pageNum,int pageSize){
PageInfo 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;
}
}