- 后台添加接口(端口号:8989,项目路径“/”),如下所示:
package io.renren.modules.sl.controller;
import io.renren.common.annotation.SysLog;
import io.renren.common.utils.Constant;
import io.renren.common.utils.R;
import io.renren.modules.sl.entity.ContractInfo;
import io.renren.modules.sl.service.ContractInfoService;
import io.renren.modules.sys.controller.AbstractController;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("sl/contractInfo")
public class ContractInfoController extends AbstractController {
@Autowired
private ContractInfoService contractInfoService;
@SysLog(type= Constant.LogType_Create, value="新增合同信息")
@ApiOperation("新增合同信息")
@PostMapping("/save")
public R save(@RequestBody ContractInfo contractInfo){
contractInfoService.saveContractInfo(contractInfo);
return R.ok();
}
}
- 编写实体类:ContractInfo
package io.renren.modules.sl.entity;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;
import io.renren.modules.sl.form.AttachmentForm;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("sl_contract_info")
public class ContractInfo implements Serializable {
private static final long serialVersionUID=1L;
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@TableField("sale_unit")
private String saleUnit;
@TableField("prem_name")
private String premName;
@TableField("build_name")
private String buildName;
@TableField("unit_name")
private String unitName;
@TableField("house_no")
private String houseNo;
@TableField("built_up_area")
private Float builtUpArea;
@TableField("inside_area")
private Float insideArea;
@TableField("shared_area")
private Float sharedArea;
@TableField("house_total_price")
private BigDecimal houseTotalPrice;
@TableField("fwjs")
private Integer fwjs;
@TableField("szcs")
private Integer szcs;
@TableField("jzjg")
private String jzjg;
@TableField("house_position")
private String housePosition;
@TableField("buy_person")
private String buyPerson;
@TableField("certificate_no")
private String certificateNo;
@TableField(exist=false)
private List<AttachmentForm> htAttentment;
}
- 打开postman访问路径处填写:http://localhost:8989/sl/contractInfo/save,请求方式选post,选择body-.raw,并添加json格式的参数
- 执行send方法,提示401,此时需要在请求路径的Headers中添加token,获取token的方式:
浏览器登录系统,F12打开开发者调试工具,随意访问一个连接,找到token,添加到postman中 - postman中添加token
6.添加完成后再次访问,提示 7.此时需要在postman中添加Content-Type 属性为:application/json 8.此时再次访问接口,提示404,经反复查看,原因是Controller中spring注解问题,返回值要求返回json传但是controller上的注解为@Controller 这种注解是不能够放回json传的,需要将@Controller注解改为@RestController即可成功调用接口
|