【千锋教育java教程SpringBoot2全套,springboot快速入门到项目实战视频教程】
请求地址:http://localhost/customer
请求方式:GET
请求参数
| 参数名 | 参数说明 | 备注 |
|---|---|---|
| Customer | 客户视图对象 | 封装客户前台展示信息 |
响应数据
| 参数名 | 参数说明 | 备注 |
|---|---|---|
| DataGridView | 数据对象 | 前台展示数据对象 |
【1】封装layui数据表格的数据对象DataGridView
package com.dingjiaxiong.vo;/*** ClassName: DataGridView* date: 2022/10/14 21:09* 前台做数据展示* @author DingJiaxiong*/public class DataGridView {/** 封装数据表格的数据对象* */private Integer code = 0;private String msg = "";private Long count;private Object data;public DataGridView() {}public DataGridView(Object data) {super();this.data = data;}public DataGridView(Long count, Object data) {super();this.count = count;this.data = data;}public Integer getCode() {return code;}public void setCode(Integer code) {this.code = code;}public String getMsg() {return msg;}public void setMsg(String msg) {this.msg = msg;}public Long getCount() {return count;}public void setCount(Long count) {this.count = count;}public Object getData() {return data;}public void setData(Object data) {this.data = data;}
}
说实话,没看明白这代码的意义
【2】封装客户实体对象Customer
package com.dingjiaxiong.domain;import com.fasterxml.jackson.annotation.JsonFormat;import java.util.Date;/*** ClassName: Customer* date: 2022/10/14 21:12* 客户实体** @author DingJiaxiong*/public class Customer {//身份证private String identity;//客户名称private String custname;//性别private Integer sex;//地址private String address;//电话private String phone;//职业private String career;//创建时间@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")private Date createtime;public String getIdentity() {return identity;}public void setIdentity(String identity) {//this.identity = identity;this.identity = identity == null ? null : identity.trim();}public String getCustname() {return custname;}public void setCustname(String custname) {//this.custname = custname;this.custname = custname == null ? null : custname.trim();}public Integer getSex() {return sex;}public void setSex(Integer sex) {this.sex = sex;}public String getAddress() {return address;}public void setAddress(String address) {//this.address = address;this.address = address == null ? null : address.trim();}public String getPhone() {return phone;}public void setPhone(String phone) {// this.phone = phone;this.phone = phone == null ? null : phone.trim();}public String getCareer() {return career;}public void setCareer(String career) {// this.career = career;this.career = career == null ? null : career.trim();}public Date getCreatetime() {return createtime;}public void setCreatetime(Date createtime) {this.createtime = createtime;}@Overridepublic String toString() {return "Customer{" +"identity='" + identity + '\'' +", custname='" + custname + '\'' +", sex=" + sex +", address='" + address + '\'' +", phone='" + phone + '\'' +", career='" + career + '\'' +", createtime=" + createtime +'}';}}
【3】封装客户视图对象CustomerVo
package com.dingjiaxiong.vo;import com.dingjiaxiong.domain.Customer;/*** ClassName: CustomerVo* date: 2022/10/14 21:14* 客户的视图对象* @author DingJiaxiong*/public class CustomerVo extends Customer {/*** 分页参数*/private Integer page; //当前页private Integer limit; //每页展示多少条public Integer getPage() {return page;}public void setPage(Integer page) {this.page = page;}public Integer getLimit() {return limit;}public void setLimit(Integer limit) {this.limit = limit;}}
【5】CustomerMapper接⼝
package com.dingjiaxiong.mapper;import com.dingjiaxiong.domain.Customer;import java.util.List;/*** ClassName: CustomerMapper* date: 2022/10/14 21:17** @author DingJiaxiong*/@Mapper
public interface CustomerMapper {/** 查询* */List queryAllCustomer(Customer customer);}
【6】CustomerMapper.xml
identity, custname, sex, address, phone, career, createtime
【7】CustomerService接口
package com.dingjiaxiong.service;import com.dingjiaxiong.vo.CustomerVo;
import com.dingjiaxiong.vo.DataGridView;/*** ClassName: CustomerService* date: 2022/10/14 21:15** @author DingJiaxiong*/public interface CustomerService {/** 查询所有客户* */public DataGridView queryAllCustomer(CustomerVo customerVo);}
【8】CustomerServiceImpl 实现类
这里快速添加一个分页依赖
com.github.pagehelper pagehelper-spring-boot-starter 1.3.1
package com.dingjiaxiong.service.impl;import com.dingjiaxiong.domain.Customer;
import com.dingjiaxiong.mapper.CustomerMapper;
import com.dingjiaxiong.service.CustomerService;
import com.dingjiaxiong.vo.CustomerVo;
import com.dingjiaxiong.vo.DataGridView;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.List;/*** ClassName: CustomerServiceImpl* date: 2022/10/14 21:25** @author DingJiaxiong*/@Service
public class CustomerServiceImpl implements CustomerService {@Autowiredprivate CustomerMapper customerMapper;@Overridepublic DataGridView queryAllCustomer(CustomerVo customerVo) {Page
【9】编写控制器
package com.dingjiaxiong.controller;import com.dingjiaxiong.service.CustomerService;
import com.dingjiaxiong.vo.CustomerVo;
import com.dingjiaxiong.vo.DataGridView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;/*** ClassName: CustomerController* date: 2022/10/14 21:30** @author DingJiaxiong*/@RestController
@RequestMapping("/customer")
public class CustomerController {@Autowiredprivate CustomerService customerService;/** 查询客户信息* */@GetMappingpublic DataGridView loadAllCustomer(@RequestBody CustomerVo customerVo){return customerService.queryAllCustomer(customerVo);}}
给启动类加上扫描

启动服务器

报了一个循环依赖的错误
【解决】
在application.yml 中配置
main:allow-circular-references: true
OK。
再次启动

OK,启动成功。
测试一下接口:
