Spring boot + Mybatis 數據庫更新update 利用api文檔調用

第一次正式進入公司實習

第一次正式進入公司 實習 。接觸到的並未在學校中學到的許多東西(軟件、框架等)在下面列出。

工作軟件:IDEA(之前使用的是eclipse)、Navicat(之前使用的是SQL Server Management)
框架:Spring Boot、Mybatis
軟件項目管理工具:Maven

第一個任務:

實現數據庫的update功能

帶我的師傅並不打算帶着我做一次,也許他認爲項目太簡單,而且摸索的過程有利於我的發展吧!

但是對一個計算機專業但是從未接觸過Spring框架的準大四生來說,很難完成,而且限定了2天時間完成(其實第一天下午15:00才佈置任務)。

目標如下:

陣地介紹-編輯資料  @陳0敏 2019-7-9  
服務隊介紹-編輯資料 @陳0敏  2019-7-9 
熟悉項目結構及開發規範 @陳0敏 2019-7-9 
熟悉項目具體實施,且必須在規定時間內完成 @陳0敏 2019-7-9 

參考文檔如下:
mybatis-plus文檔
Spring-Boot文檔
Spring MVC文檔
swagger(文檔)
IDEA常用快捷鍵
java開發手冊

相關

使用的庫:culture-center

使用的表:dept_detail

項目入口controller: DeptController

———————————————————分——界——線——————————————————

我的解決方案

明確自己應該創建的java文件有哪些

main -->

- java -->
	- Controller -->>
		- ①DeptDetailController
	- Dao -->>
		- ②IDeptDAO
	- Service -->>
		- ③IDeptDetailService
		- impl -->>>
			- ④DeptDetailServiceImpl

api -->

- model -->
	- entity -->>>
		- ⑤DeptDetial
	- param -->>>
		- ⑥NoahDeptCreateParam
		- ⑦NoahDeptUpdateParam

①DeptDetailController(項目入口)

package net.xinhuamm.noah.task.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.xinhuamm.noah.task.model.param.NoahDeptUpdateParam;
import net.xinhuamm.noah.task.service.IDeptDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @program: noah-task-unit
 * @author: chenmin
 * @create: 2019-07-09 15:10
 * @desc: 服務隊編輯詳情
 **/
@Api(tags = "服務隊管理")
@RestController
@RequestMapping("/dept")
public class DeptDetailController {

        @Autowired
        private IDeptDetailService iDept_detailService;

        @ApiOperation(value = "編輯服務隊資料")
        @RequestMapping(value = "/data/edit", method = RequestMethod.POST)
        @Transactional(rollbackFor = Exception.class)
        public Boolean edit(@Valid @RequestBody NoahDeptUpdateParam param) {
                Assert.notNull(param.getPictureUrls(), "部門圖片url不能爲空");
                Assert.notNull(param.getAbstracts(), "部門簡介不能爲空");
                Boolean result = iDept_detailService.updateById(param);
                return result;
        }
}

②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 java.util.List;

/**
 * @program: noah-culture-center
 * @description: 更新
 * @author: chenmin
 * @create: 2019-07-09 15:10
 **/
public interface IDeptDAO extends BaseMapper<DeptDetail> {
}

③IDeptDetailService

package net.xinhuamm.noah.task.service;

import com.baomidou.mybatisplus.extension.service.IService;
import net.xinhuamm.noah.task.model.entity.DeptDetail;
import net.xinhuamm.noah.task.model.param.NoahDeptCreateParam;
import net.xinhuamm.noah.task.model.param.NoahDeptUpdateParam;
import org.springframework.stereotype.Service;

/**
 * @program: noah-task-unit
 * @author: chenmin
 * @create: 2019-07-09 15:10
 * @desc:
 **/
@Service
public interface IDeptDetailService extends IService<DeptDetail> {
    Long create(NoahDeptCreateParam param);

    Boolean updateById(NoahDeptUpdateParam param);

}

④DeptDetailServiceImpl

package net.xinhuamm.noah.task.service.impl;

import net.xinhuamm.noah.common.abstracts.AbstractNoahServiceImpl;
import net.xinhuamm.noah.common.util.DozerUtil;
import net.xinhuamm.noah.task.dao.IDeptDAO;
import net.xinhuamm.noah.task.model.entity.DeptDetail;
import net.xinhuamm.noah.task.model.param.NoahDeptCreateParam;
import net.xinhuamm.noah.task.model.param.NoahDeptUpdateParam;
import net.xinhuamm.noah.task.service.IDeptDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.Date;
@Service("IDeptDetailService")
public class DeptDetailServiceImpl extends AbstractNoahServiceImpl<IDeptDAO, DeptDetail> implements IDeptDetailService {
    @Autowired
    private IDeptDetailService iDept_detailService;

    @Override
    public Long create(NoahDeptCreateParam param) {
        return null;
    }

    @Override
    public Boolean updateById(NoahDeptUpdateParam param) {
        DeptDetail dept_detailById = getById(param.getDeptId());
        Assert.notNull(dept_detailById, "活動不存在");
        DeptDetail dept_detail1 = convert(param);
        boolean result = saveOrUpdate(dept_detail1);
        return result;
    }

    private DeptDetail convert(NoahDeptUpdateParam param) {
        DeptDetail dept_detail = DozerUtil.mapper(param, DeptDetail.class);
        dept_detail.setModifyTime(new Date());
        return dept_detail;
    }

}

⑤DeptDetial

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 id;
    /**
     *
     */
    private Long creator;
    /**
     *
     */
    private Long modifier;
    /**
     *
     */
    private Long appId;
    /**
     *
     */
    private Long deptId;
    /**
     *
     */
    private Long memberCount;
    /**
     *
     */
    private Date createTime;
    /**
     *
     */
    private Date modifyTime;
    /**
     *
     */
    private Integer deleted;
    /**
     *
     */
    private String abstracts;
    /**
     *
     */
    private String pictureUrls;
}

⑥NoahDeptCreateParam

package net.xinhuamm.noah.task.model.param;

import lombok.Data;

import java.sql.Date;

/**
 * @program: noah-culture-center
 * @description: 創建服務隊信息
 * @author: chenmin
 * @create: 2019-07-10 11:10
 **/
@Data
public class NoahDeptCreateParam {
    /**
     *
     */
    private Long deptId;
    /**
     *
     */
    private Long memberCount;
    /**
     *
     */
    private String abstracts;
    /**
     *
     */
    private String pictureUrls;
}

⑦NoahDeptUpdateParam

package net.xinhuamm.noah.task.model.param;

import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.NotNull;

public class NoahDeptUpdateParam extends NoahDeptCreateParam {
    @NotNull(message = "部門id不能爲空")
    @ApiModelProperty(value = "deptId")
    private Long deptId;
}

測試成功啦

在這裏插入圖片描述

總結

第一個項目就逾期了,233。
其中碰到了很多不會的地方,也不能總是去麻煩別人,只能靠自己查看api文檔(百度幾乎不到答案),希望以後越來越好!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章