目录
1 实现过程
这是一个功能增加练习,和新建子菜单练习一样,仿照“公告管理”菜单新建测试信息管理功能。
1.1 数据库
这次数据库操作涉及了系统其他表单的条目新增。
- 新建sys_testinfo表
- 在sys_menu表中加入菜单内容,包含主菜单和下属的查询、新增、编辑、删除功能,注意路径不要写错,否则会导致数据库全部加载不出
- 在sys_role_menu中将新增的菜单id添加给普通角色(2)
- 在新建的testinfo表中设计了“测试信息类型”条目(1常规 2临时),类型的选项需要自己定义,因此在系统字典表sys_dict_type中新增测试信息类型的定义条目
- 在sys_dict_data表中新增常规和临时条目,注意dict_type内容和上表保持一致
1.2 后端
- 在com.ruoyi.project.system下新建testinfo包,包含实体层,数据层,服务层,控制层
- 新建实体层Java Bean:Testinfo.java 声明变量和get set方法
- 新建数据层接口:TestinfoMapper.java声明数据层方法
- 新建服务层接口:ITestinfoService.java声明服务层方法(内容和mapper一样)
- 新建服务类:TestinfoServiceImpl.java声明服务层实现方法
- 新建控制类:TestinfoController,java声明控制层信息操作处理方法
- 在resources.mybatis.system下新建映射:TestinfoMapper.xml建立数据库表和变量的映射
1.3 前端
- 在resources.templates.system下新建目录testinfo
- 新建add.html
- 新建edit.html
- 新建testinfo.html
2 遇到的问题
运行一下先:
新增:
编辑:
添加图片文件试一下:
编辑后的菜单:
更新后的数据表:
没有问题,开心o( ̄▽ ̄)ブ
3 总结
这次按照我认为的顺序进行了编写,对各个方法的定义和作用有了更明确的理解,一个子菜单的后端结构比较清晰了,就是前端依然靠蒙和依葫芦画瓢,html/css/js太难了!还需要多多学习,这次编写过程中学习的帖子们:
MySQL之CONCAT()的用法
浅析MySQL中concat以及group_concat的使用
4 所有新增代码
按照编写顺序
4.1 后端
Testinfo.java
package com.ruoyi.project.system.testinfo.domain;
import javax.validation.constraints.*;
import javax.validation.constraints.Size;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.framework.web.domain.BaseEntity;
/**
* 测试信息实体类
*
* @author XYM_
*/
public class Testinfo extends BaseEntity
{
private static final long serialVersionUID = 1L;
/**测试信息id*/
private Long testinfoId;
/**测试信息标题*/
private String testinfoTitle;
/**测试信息类型(1常规 2临时)*/
private String testinfoType;
/**测试信息内容*/
private String testinfoContent;
/**测试信息状态(0正常 1停用)*/
private String status;
public Long getTestinfoId() {
return testinfoId; }
public void setTestinfoId(Long testinfoId) {
this.testinfoId = testinfoId; }
@NotBlank(message = "测试信息标题不能为空")
@Size(min = 0, max = 50, message = "标题不能超过50个字符")
public String getTestinfoTitle() {
return testinfoTitle; }
public void setTestinfoTitle(String testinfoTitle) {
this.testinfoTitle = testinfoTitle; }
public String getTestinfoType() {
return testinfoType; }
public void setTestinfoType(String testinfoType) {
this.testinfoType = testinfoType; }
public String getTestinfoContent() {
return testinfoContent; }
public void setTestinfoContent(String testinfoContent) {
this.testinfoContent = testinfoContent; }
public String getStatus() {
return status; }
public void setStatus(String status) {
this.status = status; }
@Override
public String toString()
{
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("testinfoId", getTestinfoId())
.append("testinfoTitle", getTestinfoTitle())
.append("testinfoType", getTestinfoType())
.append("testinfoContent", getTestinfoContent())
.append("status", getStatus())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("remark",getRemark())
.toString();
}
}
TestinfoMapper.java
package com.ruoyi.project.system.testinfo.mapper;
import com.ruoyi.project.system.testinfo.domain.Testinfo;
import java.util.List;
/**
* 测试信息 数据层
*
* @author XYM_
*/
public interface TestinfoMapper
{
/**
* 查询测试信息
*
* @param testinfoId
* @return 信息
*/
public Testinfo selectTestinfoById(Long testinfoId);
/**
* 查询信息列表
*
* @param testinfo
* @return 信息集合
*/
public List<Testinfo> selectTestinfoList(Testinfo testinfo);
/**
* 新增测试信息
*
* @param testinfo
* @return 结果
*/
public int insertTestinfo(Testinfo testinfo);
/**
* 修改测试信息
*
* @param testinfo
* @return 结果
*/
public int updateTestinfo(Testinfo testinfo);
/**
* 批量删除测试信息
*
* @param testinfoIds
* @return 结果
*/
public int deleteTestinfoByIds(String[] testinfoIds);
}
ITestinfoService.java
package com.ruoyi.project.system.testinfo.service;
import com.ruoyi.project.system.testinfo.domain.Testinfo;
import java.util.List;
/**
* 测试信息 服务层
*
* @author XYM_
*/
public interface ITestinfoService
{
/**
* 查询测试信息
*
* @param testinfoId
* @return 信息
*/
public Testinfo selectTestinfoById(Long testinfoId);
/**
* 查询信息列表
*
* @param testinfo
* @return 信息集合
*/
public List<Testinfo> selectTestinfoList(Testinfo testinfo);
/**
* 新增测试信息
*
* @param testinfo
* @return 结果
*/
public int insertTestinfo(Testinfo testinfo);
/**
* 修改测试信息
*
* @param testinfo
* @return 结果
*/
public int updateTestinfo(Testinfo testinfo);
/**
* 批量删除测试信息
*
* @param testinfoIds
* @return 结果
*/
public int deleteTestinfoByIds(String testinfoIds);
}
TestinfoServiceImpl.java
package com.ruoyi.project.system.testinfo.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.system.testinfo.mapper.TestinfoMapper;
import com.ruoyi.project.system.testinfo.domain.Testinfo;
import com.ruoyi.project.system.testinfo.service.ITestinfoService;
/**
* 测试信息 服务层实现
*
* @author XYM_
* @date 2021-04-30
*/
@Service
public class TestinfoServiceImpl implements ITestinfoService
{
@Autowired
private TestinfoMapper testinfoMapper;
/**
* 查询测试信息
*
* @param testinfoId
* @return 信息
*/
@Override
public Testinfo selectTestinfoById(Long testinfoId){
return testinfoMapper.selectTestinfoById(testinfoId); }
/**
* 查询信息列表
*
* @param testinfo
* @return 信息集合
*/
@Override
public List<Testinfo> selectTestinfoList(Testinfo testinfo){
return testinfoMapper.selectTestinfoList(testinfo); }
/**
* 新增测试信息
*
* @param testinfo
* @return 结果
*/
@Override
public int insertTestinfo(Testinfo testinfo)
{
testinfo.setCreateBy(ShiroUtils.getLoginName());
return testinfoMapper.insertTestinfo(testinfo);
}
/**
* 修改测试信息
*
* @param testinfo
* @return 结果
*/
@Override
public int updateTestinfo(Testinfo testinfo)
{
testinfo.setUpdateBy(ShiroUtils.getLoginName());
return testinfoMapper.updateTestinfo(testinfo);
}
/**
* 批量删除测试信息
*
* @param testinfoIds
* @return 结果
*/
@Override
public int deleteTestinfoByIds(String testinfoIds)
{
return testinfoMapper.deleteTestinfoByIds(Convert.toStrArray(testinfoIds));
}
}
TestinfoController,java
package com.ruoyi.project.system.testinfo.controller;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind