parent
e1d3a417da
commit
274358c359
@ -0,0 +1,141 @@
|
|||||||
|
package ${packageName}.controller;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
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 io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import com.ruoyi.common.annotation.Log;
|
||||||
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import ${packageName}.domain.${ClassName};
|
||||||
|
import ${packageName}.service.I${ClassName}Service;
|
||||||
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||||
|
#if($table.crud || $table.sub)
|
||||||
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
|
#elseif($table.tree)
|
||||||
|
#end
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${functionName}Controller
|
||||||
|
*
|
||||||
|
* @author ${author}
|
||||||
|
* @date ${datetime}
|
||||||
|
*/
|
||||||
|
@Api(tags="${functionName}管理")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/${moduleName}/${businessName}")
|
||||||
|
public class ${ClassName}Controller extends BaseController
|
||||||
|
{
|
||||||
|
@Autowired
|
||||||
|
private I${ClassName}Service ${className}Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询${functionName}列表
|
||||||
|
*/
|
||||||
|
@ApiOperation("查询${functionName}列表")
|
||||||
|
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:list')")
|
||||||
|
@GetMapping("/list")
|
||||||
|
#if($table.crud || $table.sub)
|
||||||
|
public TableDataInfo list(${ClassName} ${className})
|
||||||
|
{
|
||||||
|
startPage();
|
||||||
|
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
|
||||||
|
return getDataTable(list);
|
||||||
|
}
|
||||||
|
#elseif($table.tree)
|
||||||
|
public AjaxResult list(${ClassName} ${className})
|
||||||
|
{
|
||||||
|
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
|
||||||
|
return success(list);
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出${functionName}列表
|
||||||
|
*/
|
||||||
|
@ApiOperation("导出${functionName}列表")
|
||||||
|
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:export')")
|
||||||
|
@Log(title = "${functionName}", businessType = BusinessType.EXPORT)
|
||||||
|
@PostMapping("/export")
|
||||||
|
public void export(HttpServletResponse response, ${ClassName} ${className})
|
||||||
|
{
|
||||||
|
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
|
||||||
|
ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
|
||||||
|
util.exportExcel(response, list, "${functionName}数据");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取${functionName}详细信息
|
||||||
|
*/
|
||||||
|
@ApiOperation("获取${functionName}详细信息")
|
||||||
|
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:query')")
|
||||||
|
@GetMapping(value = "/{${pkColumn.javaField}}")
|
||||||
|
public AjaxResult getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField})
|
||||||
|
{
|
||||||
|
#if($table.sub)
|
||||||
|
return success(${className}Service.select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField}));
|
||||||
|
#else
|
||||||
|
return success(${className}Service.getById(${pkColumn.javaField}));
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增${functionName}
|
||||||
|
*/
|
||||||
|
@ApiOperation("新增${functionName}")
|
||||||
|
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:add')")
|
||||||
|
@Log(title = "${functionName}", businessType = BusinessType.INSERT)
|
||||||
|
@PostMapping
|
||||||
|
public AjaxResult add(@RequestBody ${ClassName} ${className})
|
||||||
|
{
|
||||||
|
#if($table.sub)
|
||||||
|
return toAjax(${className}Service.insert${ClassName}(${className}));
|
||||||
|
#else
|
||||||
|
return toAjax(${className}Service.save(${className}));
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改${functionName}
|
||||||
|
*/
|
||||||
|
@ApiOperation("修改${functionName}")
|
||||||
|
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:edit')")
|
||||||
|
@Log(title = "${functionName}", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping
|
||||||
|
public AjaxResult edit(@RequestBody ${ClassName} ${className})
|
||||||
|
{
|
||||||
|
#if($table.sub)
|
||||||
|
return toAjax(${className}Service.update${ClassName}(${className}));
|
||||||
|
#else
|
||||||
|
return toAjax(${className}Service.updateById(${className}));
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除${functionName}
|
||||||
|
*/
|
||||||
|
@ApiOperation("删除${functionName}")
|
||||||
|
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:remove')")
|
||||||
|
@Log(title = "${functionName}", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{${pkColumn.javaField}s}")
|
||||||
|
public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s)
|
||||||
|
{
|
||||||
|
#if($table.sub)
|
||||||
|
return toAjax(${className}Service.delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaField}s));
|
||||||
|
#else
|
||||||
|
return toAjax(${className}Service.removeByIds(Arrays.asList(${pkColumn.javaField}s)));
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package ${packageName}.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import ${packageName}.domain.${ClassName};
|
||||||
|
#if($table.sub)
|
||||||
|
import java.util.List;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import ${packageName}.domain.${subClassName};
|
||||||
|
#end
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${functionName}Mapper接口
|
||||||
|
*
|
||||||
|
* @author ${author}
|
||||||
|
* @date ${datetime}
|
||||||
|
*/
|
||||||
|
public interface ${ClassName}Mapper extends BaseMapper<${ClassName}> {
|
||||||
|
#if($table.sub)
|
||||||
|
/**
|
||||||
|
* 查询${functionName}
|
||||||
|
*
|
||||||
|
* @param ${pkColumn.javaField} ${functionName}主键
|
||||||
|
* @return ${functionName}
|
||||||
|
*/
|
||||||
|
List<${subClassName}> select${subClassName}By${pkColumn.capJavaField}(@Param("${pkColumn.javaField}")${pkColumn.javaType} ${pkColumn.javaField});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除${functionName}信息
|
||||||
|
*
|
||||||
|
* @param ${pkColumn.javaField} ${functionName}主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
int delete${subClassName}By${subTableFkClassName}(@Param("${pkColumn.javaField}")${pkColumn.javaType} ${pkColumn.javaField});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量新增${subTable.functionName}
|
||||||
|
*
|
||||||
|
* @param ${subclassName}List ${subTable.functionName}列表
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
int batchInsert${subClassName}(List<${subClassName}> ${subclassName}List);
|
||||||
|
#end
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
package ${packageName}.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import ${packageName}.domain.${ClassName};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${functionName}Service接口
|
||||||
|
*
|
||||||
|
* @author ${author}
|
||||||
|
* @date ${datetime}
|
||||||
|
*/
|
||||||
|
public interface I${ClassName}Service extends IService<${ClassName}> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询${functionName}列表
|
||||||
|
*
|
||||||
|
* @param ${className} ${functionName}
|
||||||
|
* @return ${functionName}集合
|
||||||
|
*/
|
||||||
|
public List<${ClassName}> select${ClassName}List(${ClassName} ${className});
|
||||||
|
|
||||||
|
#if($table.sub)
|
||||||
|
/**
|
||||||
|
* 查询${functionName}
|
||||||
|
*
|
||||||
|
* @param ${pkColumn.javaField} ${functionName}主键
|
||||||
|
* @return ${functionName}
|
||||||
|
*/
|
||||||
|
public ${ClassName} select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增${functionName}
|
||||||
|
*
|
||||||
|
* @param ${className} ${functionName}
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int insert${ClassName}(${ClassName} ${className});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改${functionName}
|
||||||
|
*
|
||||||
|
* @param ${className} ${functionName}
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int update${ClassName}(${ClassName} ${className});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除${functionName}
|
||||||
|
*
|
||||||
|
* @param ${pkColumn.javaField}s 需要删除的${functionName}主键集合
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaType}[] ${pkColumn.javaField}s);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除${functionName}信息
|
||||||
|
*
|
||||||
|
* @param ${pkColumn.javaField} ${functionName}主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField});
|
||||||
|
#end
|
||||||
|
}
|
@ -0,0 +1,179 @@
|
|||||||
|
package ${packageName}.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
#if($table.sub)
|
||||||
|
import java.util.Arrays;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import ${packageName}.domain.${subClassName};
|
||||||
|
#end
|
||||||
|
import ${packageName}.mapper.${ClassName}Mapper;
|
||||||
|
import ${packageName}.domain.${ClassName};
|
||||||
|
import ${packageName}.service.I${ClassName}Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${functionName}Service业务层处理
|
||||||
|
*
|
||||||
|
* @author ${author}
|
||||||
|
* @date ${datetime}
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Mapper, ${ClassName}> implements I${ClassName}Service {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ${ClassName}Mapper ${className}Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询${functionName}列表
|
||||||
|
*
|
||||||
|
* @param ${className} ${functionName}
|
||||||
|
* @return ${functionName}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<${ClassName}> select${ClassName}List(${ClassName} ${className})
|
||||||
|
{
|
||||||
|
List<${ClassName}> ${className}List = ${className}Mapper.selectList(buildQueryWrapper(${className}));
|
||||||
|
#if($table.sub)
|
||||||
|
if (StringUtils.isNotNull(${className}List)) {
|
||||||
|
for (${ClassName} temp : ${className}List) {
|
||||||
|
List<${subClassName}> ${subclassName}List = ${className}Mapper.select${subClassName}By${pkColumn.capJavaField}(temp.get${pkColumn.capJavaField}());
|
||||||
|
temp.set${subClassName}List(${subclassName}List);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
return ${className}List;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if($table.sub)
|
||||||
|
/**
|
||||||
|
* 查询${functionName}
|
||||||
|
*
|
||||||
|
* @param ${pkColumn.javaField} ${functionName}主键
|
||||||
|
* @return ${functionName}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ${ClassName} select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField})
|
||||||
|
{
|
||||||
|
${ClassName} ${className} = ${className}Mapper.selectById(${pkColumn.javaField});
|
||||||
|
List<${subClassName}> ${subclassName}List = ${className}Mapper.select${subClassName}By${pkColumn.capJavaField}(${pkColumn.javaField});
|
||||||
|
${className}.set${subClassName}List(${subclassName}List);
|
||||||
|
return ${className};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增${functionName}
|
||||||
|
*
|
||||||
|
* @param ${className} ${functionName}
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
@Override
|
||||||
|
public int insert${ClassName}(${ClassName} ${className})
|
||||||
|
{
|
||||||
|
int rows = ${className}Mapper.insert(${className});
|
||||||
|
insert${subClassName}(${className});
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改${functionName}
|
||||||
|
*
|
||||||
|
* @param ${className} ${functionName}
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
@Override
|
||||||
|
public int update${ClassName}(${ClassName} ${className})
|
||||||
|
{
|
||||||
|
${className}Mapper.delete${subClassName}By${subTableFkClassName}(${className}.get${pkColumn.capJavaField}());
|
||||||
|
insert${subClassName}(${className});
|
||||||
|
return ${className}Mapper.updateById(${className});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除${functionName}
|
||||||
|
*
|
||||||
|
* @param ${pkColumn.javaField}s 需要删除的${functionName}主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
@Override
|
||||||
|
public int delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaType}[] ${pkColumn.javaField}s)
|
||||||
|
{
|
||||||
|
List<${pkColumn.javaType}> ${pkColumn.javaField}List = Arrays.asList(${pkColumn.javaField}s);
|
||||||
|
for (${pkColumn.javaType} ${pkColumn.javaField} : ${pkColumn.javaField}List) {
|
||||||
|
${className}Mapper.delete${subClassName}By${subTableFkClassName}(${pkColumn.javaField});
|
||||||
|
}
|
||||||
|
return ${className}Mapper.deleteBatchIds(${pkColumn.javaField}List);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除${functionName}信息
|
||||||
|
*
|
||||||
|
* @param ${pkColumn.javaField} ${functionName}主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
@Override
|
||||||
|
public int delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField})
|
||||||
|
{
|
||||||
|
${className}Mapper.delete${subClassName}By${subTableFkClassName}(${pkColumn.javaField});
|
||||||
|
return ${className}Mapper.deleteById(${pkColumn.javaField});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增${subTable.functionName}信息
|
||||||
|
*
|
||||||
|
* @param ${className} ${functionName}对象
|
||||||
|
*/
|
||||||
|
private void insert${subClassName}(${ClassName} ${className})
|
||||||
|
{
|
||||||
|
List<${subClassName}> ${subclassName}List = ${className}.get${subClassName}List();
|
||||||
|
${pkColumn.javaType} ${pkColumn.javaField} = ${className}.get${pkColumn.capJavaField}();
|
||||||
|
if (StringUtils.isNotNull(${subclassName}List)) {
|
||||||
|
for (${subClassName} ${subclassName} : ${subclassName}List) {
|
||||||
|
${subclassName}.set${subTableFkClassName}(${pkColumn.javaField});
|
||||||
|
}
|
||||||
|
${className}Mapper.batchInsert${subClassName}(${subclassName}List);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
|
private LambdaQueryWrapper<${ClassName}> buildQueryWrapper(${ClassName} query) {
|
||||||
|
Map<String, Object> params = query.getParams();
|
||||||
|
LambdaQueryWrapper<${ClassName}> lqw = Wrappers.lambdaQuery();
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if($column.query)
|
||||||
|
#set($queryType=$column.queryType)
|
||||||
|
#set($javaField=$column.javaField)
|
||||||
|
#set($javaType=$column.javaType)
|
||||||
|
#set($columnName=$column.columnName)
|
||||||
|
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#set($mpMethod=$column.queryType.toLowerCase())
|
||||||
|
#if($queryType != 'BETWEEN')
|
||||||
|
#if($javaType == 'String')
|
||||||
|
#set($condition='StringUtils.isNotBlank(query.get'+$AttrName+'())')
|
||||||
|
#else
|
||||||
|
#set($condition='query.get'+$AttrName+'() != null')
|
||||||
|
#end
|
||||||
|
lqw.$mpMethod($condition, ${ClassName}::get$AttrName, query.get$AttrName());
|
||||||
|
#else
|
||||||
|
lqw.between(params.get("begin$AttrName") != null && params.get("end$AttrName") != null,
|
||||||
|
${ClassName}::get$AttrName ,params.get("begin$AttrName"), params.get("end$AttrName"));
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#if($column.javaField == 'createTime')
|
||||||
|
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
lqw.orderByDesc(${ClassName}::get$AttrName);
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
return lqw;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
<?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="${packageName}.mapper.${ClassName}Mapper">
|
||||||
|
|
||||||
|
<resultMap type="${ClassName}" id="${ClassName}Result">
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
<result property="${column.javaField}" column="${column.columnName}" />
|
||||||
|
#end
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
#if($table.sub)
|
||||||
|
<resultMap type="${subClassName}" id="${subClassName}Result">
|
||||||
|
#foreach ($column in $subTable.columns)
|
||||||
|
<result property="${column.javaField}" column="${column.columnName}" />
|
||||||
|
#end
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<select id="select${subClassName}By${pkColumn.capJavaField}" parameterType="${pkColumn.javaType}" resultType="${packageName}.domain.${subClassName}">
|
||||||
|
select * from ${subTableName} where ${subTableFkName} = #{${pkColumn.javaField}}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<delete id="delete${subClassName}By${subTableFkClassName}" parameterType="${pkColumn.javaType}">
|
||||||
|
delete from ${subTableName} where ${subTableFkName} = #{${pkColumn.javaField}}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<insert id="batchInsert${subClassName}">
|
||||||
|
insert into ${subTableName}(#foreach($column in $subTable.columns) $column.columnName#if($foreach.count != $subTable.columns.size()),#end#end) values
|
||||||
|
<foreach item="item" index="index" collection="list" separator=",">
|
||||||
|
(#foreach($column in $subTable.columns) #{item.$column.javaField}#if($foreach.count != $subTable.columns.size()),#end#end)
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
#end
|
||||||
|
|
||||||
|
</mapper>
|
@ -1,36 +1,78 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<!DOCTYPE mapper
|
<!DOCTYPE mapper
|
||||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="${packageName}.mapper.${ClassName}Mapper">
|
<mapper namespace="${packageName}.mapper.${ClassName}Mapper">
|
||||||
|
|
||||||
<resultMap type="${ClassName}" id="${ClassName}Result">
|
<resultMap type="${ClassName}" id="${ClassName}Result">
|
||||||
#foreach ($column in $columns)
|
#foreach ($column in $columns)
|
||||||
<result property="${column.javaField}" column="${column.columnName}" />
|
<result property="${column.javaField}" column="${column.columnName}" />
|
||||||
#end
|
#end
|
||||||
|
</resultMap>
|
||||||
|
#if($table.sub)
|
||||||
|
|
||||||
|
<resultMap id="${ClassName}${subClassName}Result" type="${ClassName}" extends="${ClassName}Result">
|
||||||
|
<collection property="${subclassName}List" notNullColumn="sub_${subTable.pkColumn.columnName}" javaType="java.util.List" resultMap="${subClassName}Result" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
#if($table.sub)
|
|
||||||
<resultMap type="${subClassName}" id="${subClassName}Result">
|
<resultMap type="${subClassName}" id="${subClassName}Result">
|
||||||
#foreach ($column in $subTable.columns)
|
#foreach ($column in $subTable.columns)
|
||||||
<result property="${column.javaField}" column="${column.columnName}" />
|
<result property="${column.javaField}" column="sub_${column.columnName}" />
|
||||||
#end
|
#end
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
#end
|
||||||
|
|
||||||
|
<sql id="select${ClassName}Vo">
|
||||||
|
select#foreach($column in $columns) $column.columnName#if($foreach.count != $columns.size()),#end#end from ${tableName}
|
||||||
|
</sql>
|
||||||
|
|
||||||
<select id="select${subClassName}By${pkColumn.capJavaField}" parameterType="${pkColumn.javaType}" resultType="${packageName}.domain.${subClassName}">
|
<select id="select${ClassName}List" parameterType="${ClassName}" resultMap="${ClassName}Result">
|
||||||
select * from ${subTableName} where ${subTableFkName} = #{${pkColumn.javaField}}
|
<include refid="select${ClassName}Vo"/>
|
||||||
|
<where>
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#set($queryType=$column.queryType)
|
||||||
|
#set($javaField=$column.javaField)
|
||||||
|
#set($javaType=$column.javaType)
|
||||||
|
#set($columnName=$column.columnName)
|
||||||
|
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#if($column.query)
|
||||||
|
#if($column.queryType == "EQ")
|
||||||
|
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName = #{$javaField}</if>
|
||||||
|
#elseif($queryType == "NE")
|
||||||
|
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName != #{$javaField}</if>
|
||||||
|
#elseif($queryType == "GT")
|
||||||
|
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName > #{$javaField}</if>
|
||||||
|
#elseif($queryType == "GTE")
|
||||||
|
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName >= #{$javaField}</if>
|
||||||
|
#elseif($queryType == "LT")
|
||||||
|
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName < #{$javaField}</if>
|
||||||
|
#elseif($queryType == "LTE")
|
||||||
|
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName <= #{$javaField}</if>
|
||||||
|
#elseif($queryType == "LIKE")
|
||||||
|
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName like concat('%', #{$javaField}, '%')</if>
|
||||||
|
#elseif($queryType == "BETWEEN")
|
||||||
|
<if test="params.begin$AttrName != null and params.begin$AttrName != '' and params.end$AttrName != null and params.end$AttrName != ''"> and $columnName between #{params.begin$AttrName} and #{params.end$AttrName}</if>
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<delete id="delete${subClassName}By${subTableFkClassName}" parameterType="${pkColumn.javaType}">
|
<select id="select${ClassName}By${pkColumn.capJavaField}" parameterType="${pkColumn.javaType}" resultMap="#if($table.sub)${ClassName}${subClassName}Result#else${ClassName}Result#end">
|
||||||
delete from ${subTableName} where ${subTableFkName} = #{${pkColumn.javaField}}
|
#if($table.crud || $table.tree)
|
||||||
</delete>
|
<include refid="select${ClassName}Vo"/>
|
||||||
|
where ${pkColumn.columnName} = #{${pkColumn.javaField}}
|
||||||
<insert id="batchInsert${subClassName}">
|
#elseif($table.sub)
|
||||||
insert into ${subTableName}(#foreach($column in $subTable.columns) $column.columnName#if($foreach.count != $subTable.columns.size()),#end#end) values
|
select#foreach($column in $columns) a.$column.columnName#if($foreach.count != $columns.size()),#end#end,
|
||||||
<foreach item="item" index="index" collection="list" separator=",">
|
#foreach($column in $subTable.columns) b.$column.columnName as sub_$column.columnName#if($foreach.count != $subTable.columns.size()),#end#end
|
||||||
(#foreach($column in $subTable.columns) #{item.$column.javaField}#if($foreach.count != $subTable.columns.size()),#end#end)
|
|
||||||
</foreach>
|
from ${tableName} a
|
||||||
</insert>
|
left join ${subTableName} b on b.${subTableFkName} = a.${pkColumn.columnName}
|
||||||
#end
|
where a.${pkColumn.columnName} = #{${pkColumn.javaField}}
|
||||||
|
#end
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
Loading…
Reference in New Issue