文章目录
前言
本次要完成的任务是工作经历信息的录入,项目结构图如下:
一、编写实体类
在bean目录下新建Work实体类,内容如下:
@ApiModel(value = "工作信息实体类",description = "描述用户的工作信息")
@Data
public class Work {
@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 company;
@ApiModelProperty(value = "工作名称")
private String job;
@ApiModelProperty(value = "描述")
private String description;
@ApiModelProperty(value = "下一条工作信息")
private String nextWork;
}
二、持久层开发
在dao目录下新建WorkDao类,内容如下:
@Repository("wrokDao")
@Mapper
public interface WorkDao {
int insertIntoWork(Work work);
}
在mapper下新建WorkMapper映射文件,内容如下:
<mapper namespace="com.personal.homepage.dao.WorkDao">
<insert id="insertIntoWork" parameterType="com.personal.homepage.bean.Work">
insert into homepage_work(userid,start,end,company,job,description) values (#{userid},
#{start},#{end},#{company},#{job},#{description})
</insert>
</mapper>
三、 服务层开发
在service目录下新建WorkService类,内容如下:
public interface WorkService {
public Result insert(Work work);
}
在service目录下新建WorkServiceImpl类,内容如下:
@Service("workService")
public class WorkServiceImpl implements WorkService{
@Autowired
WorkDao workDao;
@Override
public Result insert(Work work) {
if (workDao.insertIntoWork(work) == 1){
return new Result(1,"插入成功");
}else {
return new Result(0,"插入失败");
}
}
}
四、控制层开发
在controller目录下新建WorkController类,内容如下:
@RestController
@Api(tags = "工作信息接口")
public class WorkController {
@Autowired
WorkService workService;
@ApiResponses({
@ApiResponse(code = 1, message = "新增成功"),
@ApiResponse(code = 0, message = "新增失败")
})
@ApiOperation(value = "插入数据", notes = "插入用户的教育信息")
@PostMapping("/insertWork")
public Result insert(@ApiParam("工作信息实体类") @RequestBody Work work){
return workService.insert(work);
}
}
五、测试
插入一条信息经过测试,正常执行