增加 代码生成与MybatisPlus测试案例 cstest

This commit is contained in:
疯狂的狮子li 2020-02-14 13:36:52 +08:00
parent 7c8d062d58
commit 83c427c1bb
9 changed files with 648 additions and 0 deletions

View File

@ -0,0 +1,53 @@
import request from '@/utils/request'
// 查询测试列表
export function listCstest(query) {
return request({
url: '/cstest/cstest/list',
method: 'get',
params: query
})
}
// 查询测试详细
export function getCstest(id) {
return request({
url: '/cstest/cstest/' + id,
method: 'get'
})
}
// 新增测试
export function addCstest(data) {
return request({
url: '/cstest/cstest',
method: 'post',
data: data
})
}
// 修改测试
export function updateCstest(data) {
return request({
url: '/cstest/cstest',
method: 'put',
data: data
})
}
// 删除测试
export function delCstest(id) {
return request({
url: '/cstest/cstest/' + id,
method: 'delete'
})
}
// 导出测试
export function exportCstest(query) {
return request({
url: '/cstest/cstest/export',
method: 'get',
params: query
})
}

View File

@ -0,0 +1,299 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
<el-form-item label="key键" prop="testKey">
<el-input
v-model="queryParams.testKey"
placeholder="请输入key键"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="值" prop="value">
<el-input
v-model="queryParams.value"
placeholder="请输入值"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="创建时间" prop="createTime">
<el-date-picker clearable size="small" style="width: 200px"
v-model="queryParams.createTime"
type="date"
value-format="yyyy-MM-dd"
placeholder="选择创建时间">
</el-date-picker>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['cstest:cstest:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['cstest:cstest:edit']"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['cstest:cstest:remove']"
>删除</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
icon="el-icon-download"
size="mini"
@click="handleExport"
v-hasPermi="['cstest:cstest:export']"
>导出</el-button>
</el-col>
</el-row>
<el-table v-loading="loading" :data="cstestList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="主键" align="center" prop="id" />
<el-table-column label="key键" align="center" prop="testKey" />
<el-table-column label="值" align="center" prop="value" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['cstest:cstest:edit']"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['cstest:cstest:remove']"
>删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改测试对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px">
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="key键" prop="testKey">
<el-input v-model="form.testKey" placeholder="请输入key键" />
</el-form-item>
<el-form-item label="值" prop="value">
<el-input v-model="form.value" placeholder="请输入值" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { listCstest, getCstest, delCstest, addCstest, updateCstest, exportCstest } from "@/api/cstest/cstest";
export default {
data() {
return {
//
loading: true,
//
ids: [],
//
single: true,
//
multiple: true,
//
total: 0,
//
cstestList: [],
//
title: "",
//
open: false,
//
queryParams: {
pageNum: 1,
pageSize: 10,
testKey: undefined,
value: undefined,
createTime: undefined,
},
//
form: {},
//
rules: {
testKey: [
{ required: true, message: "key键不能为空", trigger: "blur" }
], value: [
{ required: true, message: "值不能为空", trigger: "blur" }
], version: [
{ required: true, message: "版本不能为空", trigger: "blur" }
], createTime: [
{ required: true, message: "创建时间不能为空", trigger: "blur" }
], deleted: [
{ required: true, message: "删除状态不能为空", trigger: "blur" }
] }
};
},
created() {
this.getList();
},
methods: {
/** 查询测试列表 */
getList() {
this.loading = true;
listCstest(this.queryParams).then(response => {
this.cstestList = response.rows;
this.total = response.total;
this.loading = false;
});
},
//
cancel() {
this.open = false;
this.reset();
},
//
reset() {
this.form = {
id: undefined,
testKey: undefined,
value: undefined,
version: undefined,
createTime: undefined,
deleted: undefined
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
//
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id)
this.single = selection.length!=1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加测试";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const id = row.id || this.ids
getCstest(id).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改测试";
});
},
/** 提交按钮 */
submitForm: function() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.id != undefined) {
updateCstest(this.form).then(response => {
if (response.code === 200) {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
} else {
this.msgError(response.msg);
}
});
} else {
addCstest(this.form).then(response => {
if (response.code === 200) {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
} else {
this.msgError(response.msg);
}
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const ids = row.id || this.ids;
this.$confirm('是否确认删除测试编号为"' + ids + '"的数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return delCstest(ids);
}).then(() => {
this.getList();
this.msgSuccess("删除成功");
}).catch(function() {});
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams;
this.$confirm('是否确认导出所有测试数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return exportCstest(queryParams);
}).then(response => {
this.download(response.msg);
}).catch(function() {});
}
}
};
</script>

57
ruoyi/sql/test.sql Normal file
View File

@ -0,0 +1,57 @@
/*
Navicat Premium Data Transfer
Source Server : 192.168.0.222
Source Server Type : MySQL
Source Server Version : 80019
Source Host : 192.168.0.222:3306
Source Schema : ry-vue
Target Server Type : MySQL
Target Server Version : 80019
File Encoding : 65001
Date: 14/02/2020 13:29:11
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for chkj_test
-- ----------------------------
DROP TABLE IF EXISTS `chkj_test`;
CREATE TABLE `chkj_test` (
`id` int(0) NOT NULL AUTO_INCREMENT COMMENT '主键',
`test_key` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '' COMMENT 'key键',
`value` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '' COMMENT '',
`version` int(0) NULL DEFAULT 0 COMMENT '版本',
`create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
`deleted` tinyint(0) NULL DEFAULT 0 COMMENT '删除状态',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '测试表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of gen_table
-- ----------------------------
INSERT INTO `gen_table` VALUES (1, 'chkj_test', '测试表', 'CsTest', 'crud', 'com.ruoyi.project.cstest', 'cstest', 'cstest', '测试', 'Lion Li', '{}', 'admin', '2020-02-12 03:39:31', '', '2020-02-14 04:55:27', '测试代码生成器');
-- ----------------------------
-- Records of gen_table_column
-- ----------------------------
INSERT INTO `gen_table_column` VALUES (1, '1', 'id', '主键', 'int', 'Integer', 'id', '1', '1', NULL, '1', NULL, NULL, NULL, 'EQ', 'input', '', 1, 'admin', '2020-02-12 03:39:31', '', '2020-02-14 04:55:27');
INSERT INTO `gen_table_column` VALUES (2, '1', 'test_key', 'key键', 'varchar(255)', 'String', 'testKey', '0', '0', '1', '1', '1', '1', '1', 'LIKE', 'input', '', 2, 'admin', '2020-02-12 03:39:31', '', '2020-02-14 04:55:27');
INSERT INTO `gen_table_column` VALUES (3, '1', 'value', '', 'varchar(255)', 'String', 'value', '0', '0', '1', '1', '1', '1', '1', 'LIKE', 'input', '', 3, 'admin', '2020-02-12 03:39:31', '', '2020-02-14 04:55:27');
INSERT INTO `gen_table_column` VALUES (4, '1', 'version', '版本', 'int', 'Integer', 'version', '0', '0', '1', NULL, NULL, NULL, NULL, 'EQ', 'input', '', 4, 'admin', '2020-02-12 03:39:31', '', '2020-02-14 04:55:27');
INSERT INTO `gen_table_column` VALUES (5, '1', 'create_time', '创建时间', 'datetime', 'Date', 'createTime', '0', '0', '1', NULL, NULL, '1', '1', 'EQ', 'datetime', '', 5, 'admin', '2020-02-12 03:39:31', '', '2020-02-14 04:55:27');
INSERT INTO `gen_table_column` VALUES (6, '1', 'deleted', '删除状态', 'tinyint', 'Integer', 'deleted', '0', '0', '1', NULL, NULL, NULL, NULL, 'EQ', 'input', '', 6, 'admin', '2020-02-12 03:39:31', '', '2020-02-14 04:55:27');
INSERT INTO `sys_menu`(`menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `is_frame`, `menu_type`, `visible`, `perms`, `icon`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (2000, '测试用例', 0, 5, '', NULL, 1, 'M', '0', NULL, 'bug', 'admin', '2020-02-12 03:57:28', '', NULL, '');
INSERT INTO `sys_menu`(`menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `is_frame`, `menu_type`, `visible`, `perms`, `icon`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (2007, '测试', 2000, 1, 'cstest', 'cstest/cstest/index', 1, 'C', '0', 'cstest:cstest:list', '#', 'admin', '2018-03-01 00:00:00', 'ry', '2018-03-01 00:00:00', '测试菜单');
INSERT INTO `sys_menu`(`menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `is_frame`, `menu_type`, `visible`, `perms`, `icon`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (2008, '测试查询', 2007, 1, '#', '', 1, 'F', '0', 'cstest:cstest:query', '#', 'admin', '2018-03-01 00:00:00', 'ry', '2018-03-01 00:00:00', '');
INSERT INTO `sys_menu`(`menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `is_frame`, `menu_type`, `visible`, `perms`, `icon`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (2009, '测试新增', 2007, 2, '#', '', 1, 'F', '0', 'cstest:cstest:add', '#', 'admin', '2018-03-01 00:00:00', 'ry', '2018-03-01 00:00:00', '');
INSERT INTO `sys_menu`(`menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `is_frame`, `menu_type`, `visible`, `perms`, `icon`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (2010, '测试修改', 2007, 3, '#', '', 1, 'F', '0', 'cstest:cstest:edit', '#', 'admin', '2018-03-01 00:00:00', 'ry', '2018-03-01 00:00:00', '');
INSERT INTO `sys_menu`(`menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `is_frame`, `menu_type`, `visible`, `perms`, `icon`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (2011, '测试删除', 2007, 4, '#', '', 1, 'F', '0', 'cstest:cstest:remove', '#', 'admin', '2018-03-01 00:00:00', 'ry', '2018-03-01 00:00:00', '');
INSERT INTO `sys_menu`(`menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `is_frame`, `menu_type`, `visible`, `perms`, `icon`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (2012, '测试导出', 2007, 5, '#', '', 1, 'F', '0', 'cstest:cstest:export', '#', 'admin', '2018-03-01 00:00:00', 'ry', '2018-03-01 00:00:00', '');
SET FOREIGN_KEY_CHECKS = 1;

View File

@ -0,0 +1,114 @@
package com.ruoyi.project.cstest.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import java.util.List;
import java.util.Arrays;
import com.ruoyi.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.cstest.domain.CsTest;
import com.ruoyi.project.cstest.service.ICsTestService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;
/**
* 测试Controller
*
* @author Lion Li
* @date 2020-02-14
*/
@AllArgsConstructor
@RestController
@RequestMapping("/cstest/cstest" )
public class CsTestController extends BaseController {
private final ICsTestService iCsTestService;
/**
* 查询测试列表
*/
@PreAuthorize("@ss.hasPermi('cstest:cstest:list')" )
@GetMapping("/list" )
public TableDataInfo list(CsTest csTest) {
startPage();
LambdaQueryWrapper<CsTest> lqw = new LambdaQueryWrapper<CsTest>();
if (StringUtils.isNotBlank(csTest.getTestKey())){
lqw.like(CsTest::getTestKey ,csTest.getTestKey());
}
if (StringUtils.isNotBlank(csTest.getValue())){
lqw.like(CsTest::getValue ,csTest.getValue());
}
if (csTest.getCreateTime() != null){
lqw.eq(CsTest::getCreateTime ,csTest.getCreateTime());
}
List<CsTest> list = iCsTestService.list(lqw);
return getDataTable(list);
}
/**
* 导出测试列表
*/
@PreAuthorize("@ss.hasPermi('cstest:cstest:export')" )
@Log(title = "测试" , businessType = BusinessType.EXPORT)
@GetMapping("/export" )
public AjaxResult export(CsTest csTest) {
LambdaQueryWrapper<CsTest> lqw = new LambdaQueryWrapper<CsTest>(csTest);
List<CsTest> list = iCsTestService.list(lqw);
ExcelUtil<CsTest> util = new ExcelUtil<CsTest>(CsTest. class);
return util.exportExcel(list, "cstest" );
}
/**
* 获取测试详细信息
*/
@PreAuthorize("@ss.hasPermi('cstest:cstest:query')" )
@GetMapping(value = "/{id}" )
public AjaxResult getInfo(@PathVariable("id" ) Integer id) {
return AjaxResult.success(iCsTestService.getById(id));
}
/**
* 新增测试
*/
@PreAuthorize("@ss.hasPermi('cstest:cstest:add')" )
@Log(title = "测试" , businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody CsTest csTest) {
return toAjax(iCsTestService.save(csTest) ? 1 : 0);
}
/**
* 修改测试
*/
@PreAuthorize("@ss.hasPermi('cstest:cstest:edit')" )
@Log(title = "测试" , businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody CsTest csTest) {
return toAjax(iCsTestService.updateById(csTest) ? 1 : 0);
}
/**
* 删除测试
*/
@PreAuthorize("@ss.hasPermi('cstest:cstest:remove')" )
@Log(title = "测试" , businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}" )
public AjaxResult remove(@PathVariable Integer[] ids) {
return toAjax(iCsTestService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
}
}

View File

@ -0,0 +1,62 @@
package com.ruoyi.project.cstest.domain;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
import com.ruoyi.framework.aspectj.lang.annotation.Excel;
import java.io.Serializable;
import java.util.Date;
/**
* 测试对象 chkj_test
*
* @author Lion Li
* @date 2020-02-14
*/
@Data
@ToString
@EqualsAndHashCode
@NoArgsConstructor
@Accessors(chain = true)
@TableName("chkj_test")
public class CsTest implements Serializable {
private static final long serialVersionUID=1L;
/** 主键 */
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
/** key键 */
@Excel(name = "key键")
private String testKey;
/** 值 */
@Excel(name = "值")
private String value;
/** 版本 */
@Version
private Integer version;
/** 创建时间 */
@Excel(name = "创建时间" , width = 30, dateFormat = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/** 删除状态 */
@TableLogic
private Integer deleted;
}

View File

@ -0,0 +1,14 @@
package com.ruoyi.project.cstest.mapper;
import com.ruoyi.project.cstest.domain.CsTest;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* 测试Mapper接口
*
* @author Lion Li
* @date 2020-02-14
*/
public interface CsTestMapper extends BaseMapper<CsTest> {
}

View File

@ -0,0 +1,14 @@
package com.ruoyi.project.cstest.service;
import com.ruoyi.project.cstest.domain.CsTest;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* 测试Service接口
*
* @author Lion Li
* @date 2020-02-14
*/
public interface ICsTestService extends IService<CsTest> {
}

View File

@ -0,0 +1,18 @@
package com.ruoyi.project.cstest.service.impl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.project.cstest.mapper.CsTestMapper;
import com.ruoyi.project.cstest.domain.CsTest;
import com.ruoyi.project.cstest.service.ICsTestService;
/**
* 测试Service业务层处理
*
* @author Lion Li
* @date 2020-02-14
*/
@Service
public class CsTestServiceImpl extends ServiceImpl<CsTestMapper, CsTest> implements ICsTestService {
}

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.project.cstest.mapper.CsTestMapper">
<resultMap type="CsTest" id="CsTestResult">
<result property="id" column="id" />
<result property="testKey" column="test_key" />
<result property="value" column="value" />
<result property="version" column="version" />
<result property="createTime" column="create_time" />
<result property="deleted" column="deleted" />
</resultMap>
</mapper>