解决了Mybatis注入Pojo类同名的问题

This commit is contained in:
tangpeng 2019-06-11 20:53:40 +08:00
parent 6975c9b52d
commit 31d3a6a6d5
9 changed files with 823 additions and 0 deletions

View File

@ -0,0 +1,124 @@
package com.ruoyi.web.controller.template;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.template.domain.Server;
import com.ruoyi.template.service.IServerService;
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.*;
import java.util.List;
/**
* 服务器模板 信息操作处理
*
* @author TP
* @date 2019-06-11
*/
@Controller
@RequestMapping("/template/server")
public class ServerlController extends BaseController
{
private String prefix = "template/server";
@Autowired
private IServerService serverService;
@RequiresPermissions("template:server:view")
@GetMapping()
public String server()
{
return prefix + "/server";
}
/**
* 查询服务器模板列表
*/
@RequiresPermissions("template:server:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(Server server)
{
startPage();
List<Server> list = serverService.selectServerList(server);
return getDataTable(list);
}
/**
* 导出服务器模板列表
*/
@RequiresPermissions("template:server:export")
@PostMapping("/export")
@ResponseBody
public AjaxResult export(Server server)
{
List<Server> list = serverService.selectServerList(server);
ExcelUtil<Server> util = new ExcelUtil<Server>(Server.class);
return util.exportExcel(list, "server");
}
/**
* 新增服务器模板
*/
@GetMapping("/add")
public String add()
{
return prefix + "/add";
}
/**
* 新增保存服务器模板
*/
@RequiresPermissions("template:server:add")
@Log(title = "服务器模板", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(Server server)
{
return toAjax(serverService.insertServer(server));
}
/**
* 修改服务器模板
*/
@GetMapping("/edit/{serverId}")
public String edit(@PathVariable("serverId") Integer serverId, ModelMap mmap)
{
Server server = serverService.selectServerById(serverId);
mmap.put("server", server);
return prefix + "/edit";
}
/**
* 修改保存服务器模板
*/
@RequiresPermissions("template:server:edit")
@Log(title = "服务器模板", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(Server server)
{
return toAjax(serverService.updateServer(server));
}
/**
* 删除服务器模板
*/
@RequiresPermissions("template:server:remove")
@Log(title = "服务器模板", businessType = BusinessType.DELETE)
@PostMapping( "/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
return toAjax(serverService.deleteServerByIds(ids));
}
}

View File

@ -0,0 +1,72 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
<th:block th:include="include :: header('新增服务器模板')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-server-add">
<div class="form-group">
<label class="col-sm-3 control-label">服务器品牌:</label>
<div class="col-sm-8">
<input id="serverBrand" name="serverBrand" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">服务器型号:</label>
<div class="col-sm-8">
<input id="serverType" name="serverType" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">CPU主频</label>
<div class="col-sm-8">
<input id="cpuFreq" name="cpuFreq" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">CPU数量</label>
<div class="col-sm-8">
<input id="cpuNum" name="cpuNum" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">IPMI端口</label>
<div class="col-sm-8">
<input id="ipmiPort" name="ipmiPort" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">服务器电源数量:</label>
<div class="col-sm-8">
<input id="powerNum" name="powerNum" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">服务器raid卡</label>
<div class="col-sm-8">
<input id="raidCard" name="raidCard" class="form-control" type="text">
</div>
</div>
</form>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
var prefix = ctx + "template/server"
$("#form-server-add").validate({
rules:{
xxxx:{
required:true,
},
},
focusCleanup: true
});
function submitHandler() {
if ($.validate.form()) {
$.operate.save(prefix + "/add", $('#form-server-add').serialize());
}
}
</script>
</body>
</html>

View File

@ -0,0 +1,73 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
<th:block th:include="include :: header('修改服务器模板')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-server-edit" th:object="${server}">
<input id="serverId" name="serverId" th:field="*{serverId}" type="hidden">
<div class="form-group">
<label class="col-sm-3 control-label">服务器品牌:</label>
<div class="col-sm-8">
<input id="serverBrand" name="serverBrand" th:field="*{serverBrand}" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">服务器型号:</label>
<div class="col-sm-8">
<input id="serverType" name="serverType" th:field="*{serverType}" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">CPU主频</label>
<div class="col-sm-8">
<input id="cpuFreq" name="cpuFreq" th:field="*{cpuFreq}" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">CPU数量</label>
<div class="col-sm-8">
<input id="cpuNum" name="cpuNum" th:field="*{cpuNum}" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">IPMI端口</label>
<div class="col-sm-8">
<input id="ipmiPort" name="ipmiPort" th:field="*{ipmiPort}" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">服务器电源数量:</label>
<div class="col-sm-8">
<input id="powerNum" name="powerNum" th:field="*{powerNum}" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">服务器raid卡</label>
<div class="col-sm-8">
<input id="raidCard" name="raidCard" th:field="*{raidCard}" class="form-control" type="text">
</div>
</div>
</form>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
var prefix = ctx + "template/server";
$("#form-server-edit").validate({
rules:{
xxxx:{
required:true,
},
},
focusCleanup: true
});
function submitHandler() {
if ($.validate.form()) {
$.operate.save(prefix + "/edit", $('#form-server-edit').serialize());
}
}
</script>
</body>
</html>

View File

@ -0,0 +1,142 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
<th:block th:include="include :: header('服务器模板列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
<div class="row">
<div class="col-sm-12 search-collapse">
<form id="formId">
<div class="select-list">
<ul>
<li>
服务器品牌:<input type="text" name="serverBrand"/>
</li>
<li>
服务器型号:<input type="text" name="serverType"/>
</li>
<li>
CPU主频<input type="text" name="cpuFreq"/>
</li>
<li>
CPU数量<input type="text" name="cpuNum"/>
</li>
<li>
IPMI端口<input type="text" name="ipmiPort"/>
</li>
<li>
服务器电源数量:<input type="text" name="powerNum"/>
</li>
<li>
服务器raid卡<input type="text" name="raidCard"/>
</li>
<li>
<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
</li>
</ul>
</div>
</form>
</div>
<div class="btn-group-sm" id="toolbar" role="group">
<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="template:server:add">
<i class="fa fa-plus"></i> 添加
</a>
<a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()" shiro:hasPermission="template:server:edit">
<i class="fa fa-edit"></i> 修改
</a>
<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="template:server:remove">
<i class="fa fa-remove"></i> 删除
</a>
<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="template:server:export">
<i class="fa fa-download"></i> 导出
</a>
</div>
<div class="col-sm-12 select-table table-striped">
<table id="bootstrap-table" data-mobile-responsive="true"></table>
</div>
</div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
var editFlag = [[${@permission.hasPermi('template:server:edit')}]];
var removeFlag = [[${@permission.hasPermi('template:server:remove')}]];
var prefix = ctx + "template/server";
$(function() {
var options = {
url: prefix + "/list",
createUrl: prefix + "/add",
updateUrl: prefix + "/edit/{id}",
removeUrl: prefix + "/remove",
exportUrl: prefix + "/export",
modalName: "服务器模板",
showExport: true,
columns: [{
checkbox: true
},
{
field : 'serverId',
title : '服务器模板编号',
visible: false
},
{
field : 'serverBrand',
title : '服务器品牌',
sortable: true
},
{
field : 'serverType',
title : '服务器型号',
sortable: true
},
{
field : 'cpuFreq',
title : 'CPU主频',
sortable: true
},
{
field : 'cpuNum',
title : 'CPU数量',
sortable: true
},
{
field : 'ipmiPort',
title : 'IPMI端口',
sortable: true
},
{
field : 'powerNum',
title : '服务器电源数量',
sortable: true
},
{
field : 'raidCard',
title : '服务器raid卡',
sortable: true
},
{
title: '操作',
align: 'center',
formatter: function(value, row, index) {
var actions = [];
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.serverId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.serverId + '\')"><i class="fa fa-remove"></i>删除</a>');
return actions.join('');
}
}]
};
$.table.init(options);
});
</script>
</body>
</html>

View File

@ -0,0 +1,122 @@
package com.ruoyi.template.domain;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.ibatis.type.Alias;
import com.ruoyi.common.core.domain.BaseEntity;
/**
* 服务器模板表 tmpl_server
*
* @author TP
* @date 2019-06-11
*/
@Alias("serverTemplte")
public class Server extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 服务器模板编号 */
private Integer serverId;
/** 服务器品牌 */
private String serverBrand;
/** 服务器型号 */
private String serverType;
/** CPU主频 */
private String cpuFreq;
/** CPU数量 */
private Integer cpuNum;
/** IPMI端口 */
private Integer ipmiPort;
/** 服务器电源数量 */
private Integer powerNum;
/** 服务器raid卡 */
private String raidCard;
public void setServerId(Integer serverId)
{
this.serverId = serverId;
}
public Integer getServerId()
{
return serverId;
}
public void setServerBrand(String serverBrand)
{
this.serverBrand = serverBrand;
}
public String getServerBrand()
{
return serverBrand;
}
public void setServerType(String serverType)
{
this.serverType = serverType;
}
public String getServerType()
{
return serverType;
}
public void setCpuFreq(String cpuFreq)
{
this.cpuFreq = cpuFreq;
}
public String getCpuFreq()
{
return cpuFreq;
}
public void setCpuNum(Integer cpuNum)
{
this.cpuNum = cpuNum;
}
public Integer getCpuNum()
{
return cpuNum;
}
public void setIpmiPort(Integer ipmiPort)
{
this.ipmiPort = ipmiPort;
}
public Integer getIpmiPort()
{
return ipmiPort;
}
public void setPowerNum(Integer powerNum)
{
this.powerNum = powerNum;
}
public Integer getPowerNum()
{
return powerNum;
}
public void setRaidCard(String raidCard)
{
this.raidCard = raidCard;
}
public String getRaidCard()
{
return raidCard;
}
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("serverId", getServerId())
.append("serverBrand", getServerBrand())
.append("serverType", getServerType())
.append("cpuFreq", getCpuFreq())
.append("cpuNum", getCpuNum())
.append("ipmiPort", getIpmiPort())
.append("powerNum", getPowerNum())
.append("raidCard", getRaidCard())
.toString();
}
}

View File

@ -0,0 +1,62 @@
package com.ruoyi.template.mapper;
import com.ruoyi.template.domain.Server;
import java.util.List;
/**
* 服务器模板 数据层
*
* @author TP
* @date 2019-06-11
*/
public interface ServerMapper
{
/**
* 查询服务器模板信息
*
* @param serverId 服务器模板ID
* @return 服务器模板信息
*/
public Server selectServerById(Integer serverId);
/**
* 查询服务器模板列表
*
* @param server 服务器模板信息
* @return 服务器模板集合
*/
public List<Server> selectServerList(Server server);
/**
* 新增服务器模板
*
* @param server 服务器模板信息
* @return 结果
*/
public int insertServer(Server server);
/**
* 修改服务器模板
*
* @param server 服务器模板信息
* @return 结果
*/
public int updateServer(Server server);
/**
* 删除服务器模板
*
* @param serverId 服务器模板ID
* @return 结果
*/
public int deleteServerById(Integer serverId);
/**
* 批量删除服务器模板
*
* @param serverIds 需要删除的数据ID
* @return 结果
*/
public int deleteServerByIds(String[] serverIds);
}

View File

@ -0,0 +1,54 @@
package com.ruoyi.template.service;
import com.ruoyi.template.domain.Server;
import java.util.List;
/**
* 服务器模板 服务层
*
* @author TP
* @date 2019-06-11
*/
public interface IServerService
{
/**
* 查询服务器模板信息
*
* @param serverId 服务器模板ID
* @return 服务器模板信息
*/
public Server selectServerById(Integer serverId);
/**
* 查询服务器模板列表
*
* @param server 服务器模板信息
* @return 服务器模板集合
*/
public List<Server> selectServerList(Server server);
/**
* 新增服务器模板
*
* @param server 服务器模板信息
* @return 结果
*/
public int insertServer(Server server);
/**
* 修改服务器模板
*
* @param server 服务器模板信息
* @return 结果
*/
public int updateServer(Server server);
/**
* 删除服务器模板信息
*
* @param ids 需要删除的数据ID
* @return 结果
*/
public int deleteServerByIds(String ids);
}

View File

@ -0,0 +1,84 @@
package com.ruoyi.template.service.impl;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.template.domain.Server;
import com.ruoyi.template.mapper.ServerMapper;
import com.ruoyi.template.service.IServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 服务器模板 服务层实现
*
* @author TP
* @date 2019-06-11
*/
@Service
public class ServerServiceImpl implements IServerService
{
@Autowired
private ServerMapper serverMapper;
/**
* 查询服务器模板信息
*
* @param serverId 服务器模板ID
* @return 服务器模板信息
*/
@Override
public Server selectServerById(Integer serverId)
{
return serverMapper.selectServerById(serverId);
}
/**
* 查询服务器模板列表
*
* @param server 服务器模板信息
* @return 服务器模板集合
*/
@Override
public List<Server> selectServerList(Server server)
{
return serverMapper.selectServerList(server);
}
/**
* 新增服务器模板
*
* @param server 服务器模板信息
* @return 结果
*/
@Override
public int insertServer(Server server)
{
return serverMapper.insertServer(server);
}
/**
* 修改服务器模板
*
* @param server 服务器模板信息
* @return 结果
*/
@Override
public int updateServer(Server server)
{
return serverMapper.updateServer(server);
}
/**
* 删除服务器模板对象
*
* @param ids 需要删除的数据ID
* @return 结果
*/
@Override
public int deleteServerByIds(String ids)
{
return serverMapper.deleteServerByIds(Convert.toStrArray(ids));
}
}

View File

@ -0,0 +1,90 @@
<?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.template.mapper.ServerMapper">
<resultMap type="serverTemplte" id="ServerResult">
<result property="serverId" column="server_id" />
<result property="serverBrand" column="server_brand" />
<result property="serverType" column="server_type" />
<result property="cpuFreq" column="cpu_freq" />
<result property="cpuNum" column="cpu_num" />
<result property="ipmiPort" column="ipmi_port" />
<result property="powerNum" column="power_num" />
<result property="raidCard" column="raid_card" />
</resultMap>
<sql id="selectServerVo">
select server_id, server_brand, server_type, cpu_freq, cpu_num, ipmi_port, power_num, raid_card from tmpl_server
</sql>
<select id="selectServerList" parameterType="serverTemplte" resultMap="ServerResult">
<include refid="selectServerVo"/>
<where>
<if test="serverId != null "> and server_id = #{serverId}</if>
<if test="serverBrand != null and serverBrand != '' "> and server_brand = #{serverBrand}</if>
<if test="serverType != null and serverType != '' "> and server_type = #{serverType}</if>
<if test="cpuFreq != null and cpuFreq != '' "> and cpu_freq = #{cpuFreq}</if>
<if test="cpuNum != null "> and cpu_num = #{cpuNum}</if>
<if test="ipmiPort != null "> and ipmi_port = #{ipmiPort}</if>
<if test="powerNum != null "> and power_num = #{powerNum}</if>
<if test="raidCard != null and raidCard != '' "> and raid_card = #{raidCard}</if>
</where>
</select>
<select id="selectServerById" parameterType="Integer" resultMap="ServerResult">
<include refid="selectServerVo"/>
where server_id = #{serverId}
</select>
<insert id="insertServer" parameterType="serverTemplte">
insert into tmpl_server
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="serverId != null ">server_id,</if>
<if test="serverBrand != null and serverBrand != '' ">server_brand,</if>
<if test="serverType != null and serverType != '' ">server_type,</if>
<if test="cpuFreq != null and cpuFreq != '' ">cpu_freq,</if>
<if test="cpuNum != null ">cpu_num,</if>
<if test="ipmiPort != null ">ipmi_port,</if>
<if test="powerNum != null ">power_num,</if>
<if test="raidCard != null and raidCard != '' ">raid_card,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="serverId != null ">#{serverId},</if>
<if test="serverBrand != null and serverBrand != '' ">#{serverBrand},</if>
<if test="serverType != null and serverType != '' ">#{serverType},</if>
<if test="cpuFreq != null and cpuFreq != '' ">#{cpuFreq},</if>
<if test="cpuNum != null ">#{cpuNum},</if>
<if test="ipmiPort != null ">#{ipmiPort},</if>
<if test="powerNum != null ">#{powerNum},</if>
<if test="raidCard != null and raidCard != '' ">#{raidCard},</if>
</trim>
</insert>
<update id="updateServer" parameterType="serverTemplte">
update tmpl_server
<trim prefix="SET" suffixOverrides=",">
<if test="serverBrand != null and serverBrand != '' ">server_brand = #{serverBrand},</if>
<if test="serverType != null and serverType != '' ">server_type = #{serverType},</if>
<if test="cpuFreq != null and cpuFreq != '' ">cpu_freq = #{cpuFreq},</if>
<if test="cpuNum != null ">cpu_num = #{cpuNum},</if>
<if test="ipmiPort != null ">ipmi_port = #{ipmiPort},</if>
<if test="powerNum != null ">power_num = #{powerNum},</if>
<if test="raidCard != null and raidCard != '' ">raid_card = #{raidCard},</if>
</trim>
where server_id = #{serverId}
</update>
<delete id="deleteServerById" parameterType="Integer">
delete from tmpl_server where server_id = #{serverId}
</delete>
<delete id="deleteServerByIds" parameterType="String">
delete from tmpl_server where server_id in
<foreach item="serverId" collection="array" open="(" separator="," close=")">
#{serverId}
</foreach>
</delete>
</mapper>