个人主页展示系统(SpringBoot)-no3-教育信息录入功能开发


前言

这次项目将在上一次的基础上个人主页展示系统(SpringBoot)-no2-用户信息录入功能开发继续完善,这次要完成的是教育信息录入功能。项目结构图如下:
在这里插入图片描述


一、编写实体类

在bean目录下新建Education实体类,内容如下:

@ApiModel(value = "教育信息实体类",description = "描述用户的教育信息")
@Data
public class Education {
    @ApiModelProperty(value = "教育信息id")
    private int id;
    @ApiModelProperty(value = "用户id")
    private int userid;
    @ApiModelProperty(value = "开始时间")
    private String start;
    @ApiModelProperty(value = "结束时间")
    private String end;
    @ApiModelProperty(value = "毕业学校")
    private String school;
    @ApiModelProperty(value = "专业")
    private String major;
    @ApiModelProperty(value = "描述")
    private String description;
    @ApiModelProperty(value = "下一条教育信息")
    private Education nextEducation;

}

二、持久层开发

在dao目录下新建EducationDao类,内容如下:

@Repository("educationDao")
@Mapper
public interface EducationDao {
    int insertIntoEducation(Education education);
}

在mapper下新建EducationMapper映射文件,内容如下:

<mapper namespace="com.personal.homepage.dao.EducationDao">
    <insert id="insertIntoEducation" parameterType="com.personal.homepage.bean.Education">
        insert into homepage_edu(userid,start,end,school,major,description)values (#{userid},#{start},#{end},#{school},
                                                                                   #{major},#{description})
    </insert>

</mapper>

namespace的值需要填写EducationDao类所在的完整路径。

三、服务层开发

在service目录下新建EducationService类,内容如下:

public interface EducationService {
    public Result insert(Education education);
}

其具体实现如下:

@Service("educationService")
public class EducationServiceImpl implements EducationService{
    @Autowired
    EducationDao educationDao;

    @Override
    public Result insert(Education education) {
        if (educationDao.insertIntoEducation(education)==1){
            return new Result(1,"插入成功");
        }else {
            return new Result(0,"插入失败");
        }
    }
}

四、控制层开发

在controller目录下新建EducationController类,内容如下:

@RestController
@Api(tags = "教育信息数据接口")
public class EducationController {
    @Autowired
    EducationService educationService;

    @ApiResponses({
            @ApiResponse(code = 1, message = "新增成功"),
            @ApiResponse(code = 0, message = "新增失败")
    })
    @ApiOperation(value = "插入数据", notes = "插入用户的教育信息")
    @PostMapping("/insertEducation")
    public Result insert(@ApiParam("教育信息实体类") @RequestBody Education education) {
        return educationService.insert(education);
    }
}

五、测试

上一次使用到了postman进行测试,这次使用的是Swagger自带的测试工具进行测试。进入Swagger首页,点击try it out ,如图所示:
在这里插入图片描述
填写测试数据,点击Execute执行
在这里插入图片描述
测试结果如下:
在这里插入图片描述
数据库记录也正确
在这里插入图片描述
经过测试教育信息录入功能正常执行。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

喂喂,要加油

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值