【千锋教育java教程SpringBoot2全套,springboot快速入门到项目实战视频教程】
添加客户窗口可以输入客户信息,然后保存入库。
修改客户接口路径
http://localhost/customer
请求方式:POST
请求参数
| 参数名 | 参数说明 | 备注 |
|---|---|---|
| CustomerVo | 客户视图对象 |
响应数据
| 参数名 | 参数说明 | 备注 |
|---|---|---|
| ResultObj | 统一封装数据对象 |
【CustomerMapper持久层接口】
/*
* 添加客户
* */
void addCustomer(CustomerVo customerVo);

【CustomerMapper.xml 映射文件】
<insert id="addCustomer" parameterType="com.dingjiaxiong.vo.CustomerVo">
insert into t_customer
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="identity != null">
identity,
if>
<if test="custname != null">
custname,
if>
<if test="sex != null">
sex,
if>
<if test="address != null">
address,
if>
<if test="phone != null">
phone,
if>
<if test="career != null">
career,
if>
<if test="createtime != null">
createtime,
if>
trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="identity != null">
#{identity},
if>
<if test="custname != null">
#{custname},
if>
<if test="sex != null">
#{sex},
if>
<if test="address != null">
#{address},
if>
<if test="phone != null">
#{phone},
if>
<if test="career != null">
#{career},
if>
<if test="createtime != null">
#{createtime},
if>
trim>
insert>
【CustomerService接口】
/*
* 添加客户
* */
void addCustomer(CustomerVo customerVo);

【CustomerServicelmpl 实现类】
@Override
public void addCustomer(CustomerVo customerVo) {
customerMapper.addCustomer(customerVo);
}

【CustomerController控制器】
/*
* 添加客户
* */
@PostMapping
public ResultObj addCustomer(@RequestBody CustomerVo customerVo) {
try {
customerVo.setCreatetime(new Date());
customerService.addCustomer(customerVo);
return ResultObj.ADD_SUCCESS;
} catch (Exception e) {
e.printStackTrace();
return ResultObj.ADD_ERROR;
}
}

OK,启动服务

测试接口

查看数据库

OK,添加成功。