大大们,这个一个返回字符串,一个返回RespPageBean对象,字符串的可以成功返回,但是这个对象不行,这个对象从数据库查询到是有值的!!
测试请求的结果
这个是返回RespPageBean对象的,500错误,但是后台没报错,一切正常
这个是将RespPageBean对象toString返回的结果
这两个有一个不同点就是Connection 一个是close,一个是keep-alive
这个RespPageBean使用了MybatisPlus自带的分页.
数据库是没有问题的,我把别人的代码搞过来,用自己的数据库是可以成功的..
#Controller
package com.xiang.server.controller;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mysql.cj.xdevapi.JsonArray;
import com.xiang.server.pojo.Employee;
import com.xiang.server.pojo.RespBean;
import com.xiang.server.pojo.RespPageBean;
import com.xiang.server.service.IEmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.spring.web.json.Json;
import java.time.LocalDate;
import java.util.Date;
@Api(tags = "EmployeeController")
@RestController
@RequestMapping("/employee/basic")
public class EmployeeController {
@Autowired
private IEmployeeService employeeService;
@ApiOperation(value = "获取所有员工(分页)")
@GetMapping("/")
public RespPageBean getEmployeeByPage(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "10") Integer size,
Employee employee, LocalDate[] beginDateScope){
RespPageBean employeeByPage = employeeService.getEmployeeByPage(currentPage, size, employee, beginDateScope);
System.out.println("测试输出"+employeeByPage);
return employeeByPage;
}
@ApiOperation(value = "获取所有员工(分页)")
@GetMapping("/cccc")
public String getEmployeeByPage2(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "10") Integer size,
Employee employee, LocalDate[] beginDateScope){
RespPageBean employeeByPage = employeeService.getEmployeeByPage(currentPage, size, employee, beginDateScope);
return employeeByPage.toString();
}
}
#Service
package com.xiang.server.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiang.server.mapper.EmployeeMapper;
import com.xiang.server.pojo.Employee;
import com.xiang.server.pojo.RespPageBean;
import com.xiang.server.service.IEmployeeService;
import org.apache.tomcat.jni.Local;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements IEmployeeService {
@Autowired
private EmployeeMapper employeeMapper;
@Override
public RespPageBean getEmployeeByPage(Integer currentPage, Integer size, Employee employee, LocalDate[] beginDateScope) {
Page<Employee> page = new Page<>(currentPage, size);
IPage<Employee> employeeIPage = employeeMapper.getEmployeeByPage(page, employee, beginDateScope);
RespPageBean respPageBean = new RespPageBean(employeeIPage.getTotal(), employeeIPage.getRecords());
return respPag
}
}
#Mapper
package com.xiang.server.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiang.server.pojo.Employee;
import org.apache.ibatis.annotations.Param;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
public interface EmployeeMapper extends BaseMapper<Employee> {
IPage<Employee> getEmployeeByPage(Page<Employee> page,@Param("employee") Employee emp,@Param("beginDateScope") LocalDate[] beginDateScope);
}
#RespPageBean
package com.xiang.server.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RespPageBean {
private Long total;
private List<?> data;
}
#Employee
package com.xiang.server.pojo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.time.LocalDate;
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("t_employee")
@ApiModel(value="Employee对象", description="Employee对象")
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "员工编号")
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@ApiModelProperty(value = "员工姓名")
private String name;
@ApiModelProperty(value = "性别")
private String gender;
@ApiModelProperty(value = "出生日期")
@JsonFormat(pattern = "yyyy-MM-dd",timezone = "Asia/Shanghai")
private LocalDate birthday;
@ApiModelProperty(value = "身份证号")
private String idCard;
@ApiModelProperty(value = "婚姻状况")
private String wedlock;
@ApiModelProperty(value = "民族")
private Integer nationId;
@ApiModelProperty(value = "籍贯")
private String nativePlace;
@ApiModelProperty(value = "政治面貌")
private Integer politicId;
@ApiModelProperty(value = "邮箱")
private String email;
@ApiModelProperty(value = "电话号码")
private String phone;
@ApiModelProperty(value = "联系地址")
private String address;
@ApiModelProperty(value = "所属部门")
private Integer departmentId;
@ApiModelProperty(value = "职称ID")
private Integer jobLevelId;
@ApiModelProperty(value = "职位ID")
private Integer posId;
@ApiModelProperty(value = "聘用形式")
private String engageForm;
@ApiModelProperty(value = "最高学历")
private String tiptopDegree;
@ApiModelProperty(value = "所属专业")
private String specialty;
@ApiModelProperty(value = "毕业院校")
private String school;
@ApiModelProperty(value = "入职日期")
@JsonFormat(pattern = "yyyy-MM-dd",timezone = "Asia/Shanghai")
private LocalDate beginDate;
@ApiModelProperty(value = "在职状态")
private String workState;
@ApiModelProperty(value = "工号")
private String workID;
@ApiModelProperty(value = "合同期限")
private Double contractTerm;
@ApiModelProperty(value = "转正日期")
@JsonFormat(pattern = "yyyy-mm-dd",timezone = "Asia/Shanghai")
private LocalDate conversionTime;
@ApiModelProperty(value = "离职日期")
@JsonFormat(pattern = "yyyy-MM-dd",timezone = "Asia/Shanghai")
private LocalDate notWorkDate;
@ApiModelProperty(value = "合同起始日期")
@JsonFormat(pattern = "yyyy-MM-dd",timezone = "Asia/Shanghai")
private LocalDate beginContract;
@ApiModelProperty(value = "合同终止日期")
@JsonFormat(pattern = "yyyy-MM-dd",timezone = "Asia/Shanghai")
private LocalDate endContract;
@ApiModelProperty(value = "工龄")
private Integer workAge;
@ApiModelProperty(value = "工资账套ID")
private Integer salaryId;
@ApiModelProperty(value = "民族")
@TableField(exist = false)
private Nation nation;
@ApiModelProperty(value = "政治面貌")
@TableField(exist = false)
private PoliticsStatus politicsStatus;
@ApiModelProperty(value = "部门")
@TableField(exist = false)
private Department department;
@ApiModelProperty(value = "职称")
@TableField(exist = false)
private Joblevel joblevel;
@ApiModelProperty(value = "职位")
@TableField(exist = false)
private Position position;
}