任务
实现数据库的create/insert功能
相关
使用的库:culture-center
使用的表:dept_detail
项目入口controller: DeptController
———————————————————分——界——线——————————————————
我的解决方案
明确自己应该创建的java文件有哪些
main -->
- java -->
- Controller -->>
- ①DeptDetailController
- Service -->>
- ②IDeptDetailService
- impl -->>>
- ③DeptDetailServiceImpl
- DAO -->
- ④IDeptDAO
api -->
- model -->
- entity -->>>
- ⑤DeptDetail
- param -->>>
- ⑥NoahDeptDataSaveParam
①DeptDetailController(项目入口)
@Api(tags = "部门管理")
@RestController
@RequestMapping("/dept")
public class DeptController {
@Autowired
private IDeptDetailService deptDetailService;
@ApiOperation(value = "添加部门资料")
@RequestMapping(value = "/data/create", method = RequestMethod.POST)
@Transactional(rollbackFor = Exception.class)
public Long create(@Valid @RequestBody NoahDeptDataSaveParam param) {
Long result = deptDetailService.create(param);
return result;
}
}
②IDeptDetailService
public interface IDeptDetailService extends IService<DeptDetail> {
Long create(NoahDeptDataSaveParam param);
}
③DeptDetailServiceImpl
@Service
public class DeptDetailServiceImpl extends AbstractNoahServiceImpl<IDeptDetailDAO, DeptDetail> implements IDeptDetailService {
@Override
public Long create(NoahDeptDataSaveParam param) {
DeptDetail deptDetail = new DeptDetail();
deptDetail.setDeptId(param.getDeptId());
if(!CollectionUtils.isEmpty(param.getPictureUrls())){
deptDetail.setPictureUrls(StringUtil.list2String(param.getPictureUrls()));
}
boolean save = this.save(deptDetail);
return deptDetail.getId();
}
}
④IDeptDAO
package net.xinhuamm.noah.task.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.xinhuamm.noah.permission.model.entity.Dept;
import net.xinhuamm.noah.task.model.entity.DeptDetail;
import net.xinhuamm.noah.task.model.param.NoahDeptDataEditParam;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @program: noah-culture-center
* @description: 更新
* @author: chenmin
* @create: 2019-07-09 15:10
**/
@Repository
public interface IDeptDAO extends BaseMapper<DeptDetail> {
}
⑤DeptDetail
package net.xinhuamm.noah.task.model.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import net.xinhuamm.noah.common.entity.LogicDelEntity;
import java.sql.Date;
@TableName("dept_detail")
@Data
public class DeptDetail extends LogicDelEntity {
/**
*
*/
private Long deptId;
/**
*
*/
private Long memberCount;
/**
*
*/
private String abstracts;
/**
*
*/
private String pictureUrls;
}
⑥NoahDeptDataSaveParam
@Data
public class NoahDeptDataSaveParam {
/**
* 部门id
*/
@NotNull
@ApiModelProperty(value = "部门id")
private Long deptId;
/**
* 图片地址
*/
@ApiModelProperty(value = "图片地址")
private List<String> pictureUrls;
/**
* appId
*/
@ApiModelProperty(value = "appId")
private Long appId;
}
测试成功啦
总结
DeptDetailServiceImpl中的 boolean save = this.save(deptDetail);
此代码中的save虽然未被使用,但是在反工时测试数据是否被保存时很实用。