Easy Code的使用(带模板)
1、Easy Code插件下载
2、使用idea连接数据库
很多人可能不知道idea本身就可以连接多种数据库并使用,个人感觉idea本身的数据库操作就很方便。
我这里使用的Oracle数据库,填写好信息后,最下面会有一个Test Connection按钮,点击可以测试自己配置的信息是否正确
成功后会在idea右侧变成如图
3、测试你想要生成的代码(以dtp_test表为例)
选中要用的表,然后右键选择EasyCode->Generate Code
点击后,进入如图所示界面
然后选择需要生成的包路径,选中all,点击 ok
4、生成效果如下
5、以下是模板和对应的效果展示
entity.java.vm
##定义初始变量
#set($tablename = $tableInfo.name)
#set($subtablename = $tableInfo.name.substring(3))
$!{define.vm}
##设置回调
$!callback.setFileName($tool.append($!{tablename}, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/mybatis/model"))
package ks.future.dtp.mybatis.model;
##自动导入包(全局变量)
$!{autoImport.vm}
import io.swagger.annotations.ApiModelProperty;
/**
* ${tableInfo.comment}
*
* @author $!author
* @date $!time.currTime()
*/
public class $!{tablename} {
#foreach($column in $tableInfo.fullColumn)
#if(${column.comment})/**
* ${column.comment}
*/#end
@ApiModelProperty(value = "${column.comment}")
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
#foreach($column in $tableInfo.fullColumn)
##使用宏定义实现get,set方法
#getSetMethod($column)
#end
@Override
public String toString() {
return "$!{tablename}{" +
#foreach($column in $tableInfo.fullColumn)
"$!{column.name}='" + $!{column.name} + '\'' +
#end
"}";
}
}
package ks.future.dtp.mybatis.model;
import io.swagger.annotations.ApiModelProperty;
/**
* 测试表
*
* @author makejava
* @date 2024-07-15 15:42:29
*/
public class DtpTest {
/**
* 测试ID
*/
@ApiModelProperty(value = "测试ID")
private String testid;
/**
* 测试编号
*/
@ApiModelProperty(value = "测试编号")
private Long testno;
/**
* 设置操作员
*/
@ApiModelProperty(value = "设置操作员")
private String setoperatorcode;
/**
* 操作日期
*/
@ApiModelProperty(value = "操作日期")
private String operatordate;
/**
* 操作时间
*/
@ApiModelProperty(value = "操作时间")
private String operatortime;
public String getTestid() {
return testid;
}
public void setTestid(String testid) {
this.testid = testid;
}
public Long getTestno() {
return testno;
}
public void setTestno(Long testno) {
this.testno = testno;
}
public String getSetoperatorcode() {
return setoperatorcode;
}
public void setSetoperatorcode(String setoperatorcode) {
this.setoperatorcode = setoperatorcode;
}
public String getOperatordate() {
return operatordate;
}
public void setOperatordate(String operatordate) {
this.operatordate = operatordate;
}
public String getOperatortime() {
return operatortime;
}
public void setOperatortime(String operatortime) {
this.operatortime = operatortime;
}
@Override
public String toString() {
return "DtpTest{" +
"testid='" + testid + '\'' +
"testno='" + testno + '\'' +
"setoperatorcode='" + setoperatorcode + '\'' +
"operatordate='" + operatordate + '\'' +
"operatortime='" + operatortime + '\'' +
"}";
}
}
req.java.vm
##定义初始变量
#set($tablename = $tableInfo.name)
#set($subtablename = $tableInfo.name.substring(3))
$!{define.vm}
##设置回调
$!callback.setFileName($tool.append($!{subtablename}, "Req.java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/entity/req"))
package ks.future.dtp.entity.req;
##自动导入包(全局变量)
$!{autoImport.vm}
/**
* ${tableInfo.comment}
*
* @author $!author
* @date $!time.currTime()
*/
public class $!{subtablename}Req {
#foreach($column in $tableInfo.pkColumn)
#if(${column.comment})/**
* ${column.comment}
*/#end
@ApiModelProperty(value = "${column.comment}")
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
#foreach($column in $tableInfo.pkColumn)
##使用宏定义实现get,set方法
#getSetMethod($column)
#end
}
package ks.future.dtp.entity.req;
import io.swagger.annotations.ApiModelProperty;
/**
* 测试表
*
* @author makejava
* @date 2024-07-15 15:42:30
*/
public class TestReq {
/**
* 测试ID
*/
@ApiModelProperty(value = "测试ID")
private String testid;
/**
* 测试编号
*/
@ApiModelProperty(value = "测试编号")
private Long testno;
public String getTestid() {
return testid;
}
public void setTestid(String testid) {
this.testid = testid;
}
public Long getTestno() {
return testno;
}
public void setTestno(Long testno) {
this.testno = testno;
}
}
resp.java.vm
##定义初始变量
#set($tablename = $tableInfo.name)
#set($subtablename = $tableInfo.name.substring(3))
##设置回调
$!callback.setFileName($tool.append($!{subtablename}, "Resp.java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/entity/resp"))
package ks.future.dtp.entity.resp;
##自动导入包(全局变量)
$!{autoImport.vm}
import ks.future.dtp.mybatis.model.$!{tablename};
/**
* ${tableInfo.comment}
*
* @author $!author
* @date $!time.currTime()
*/
public class $!{subtablename}Resp extends $!{tablename} {
}
package ks.future.dtp.entity.resp;
import ks.future.dtp.mybatis.model.DtpTest;
/**
* 测试表
*
* @author makejava
* @date 2024-07-15 15:42:30
*/
public class TestResp extends DtpTest {
}
api.java.vm
##定义初始变量
#set($tablename = $tableInfo.name)
#set($subtablename = $tableInfo.name.substring(3))
#set($lowertablename = $subtablename.toLowerCase())
##设置回调
$!callback.setFileName($tool.append($!{subtablename}, "Api.java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/api"))
package ks.future.dtp.api;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import ks.future.dtp.config.Dict;
import ks.future.dtp.entity.req.$!{subtablename}Req;
import ks.future.dtp.entity.resp.$!{subtablename}Resp;
import ks.future.dtp.services.$!{subtablename}Service;
import ks.future.dtp.utils.ExceptionDefined;
import ks.future.dtp.utils.RespBody;
import ks.future.dtp.utils.RespBody.RetCode;
import org.apache.commons.math3.util.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
* ${tableInfo.comment}
*
* @author $!author
* @date $!time.currTime()
*/
@RestController
@RequestMapping("rq/v1/setting/$!{lowertablename}/")
@Api(tags = "${tableInfo.comment}")
public class $!{subtablename}Api {
@Autowired
private $!{subtablename}Service service;
@ApiOperation(value = "查询")
@RequestMapping(value = "find", method = RequestMethod.POST)
public RespBody find($!{subtablename}Req $!{lowertablename},
@RequestParam(value = "page", required = true) int page,
@RequestParam(value = "limit", required = true) int limit,
@RequestParam(value = "isSeek", required = true) Boolean isSeek,
HttpServletRequest req) {
String operator = req.getHeader(Dict.OPERATOR_ID);
Pair<Long, List<$!{subtablename}Resp>> res = service.find($!{lowertablename}, page, limit, isSeek, operator);
if (res.getKey() <= 0 || res.getValue() == null) {
return new RespBody(RetCode.SUCC, ExceptionDefined.NODATAFOUND);
}
return new RespBody(res.getKey(), res.getValue());
}
@ApiOperation(value = "增加")
@RequestMapping(value = "insert", method = RequestMethod.POST)
public RespBody insert(@RequestBody $!{tablename} $!{lowertablename}, HttpServletRequest req) {
String operator = req.getHeader(Dict.OPERATOR_ID);
$!{lowertablename}.setSetoperatorcode(operator);
long iResult = service.insert($!{lowertablename}, operator);
if (iResult == -1) {
return new RespBody(RetCode.PRIMARYKEYCONFLICT, ExceptionDefined.PRIMARYKEYCONFLICT);
} else if (iResult <= 0) {
return new RespBody(RetCode.FAIL, ExceptionDefined.INSERTFAIL);
} else {
return new RespBody(RetCode.SUCC, Dict.SUCC);
}
}
@ApiOperation(value = "修改")
@RequestMapping(value = "update", method = RequestMethod.POST)
public RespBody update(@RequestBody $!{tablename} $!{lowertablename}, HttpServletRequest req) {
String operator = req.getHeader(Dict.OPERATOR_ID);
long result = service.update($!{lowertablename}, operator);
if (result <= 0) {
return new RespBody(RetCode.FAIL, ExceptionDefined.UPDATEFAIL);
}
return new RespBody(RetCode.SUCC, Dict.SUCC);
}
@ApiOperation(value = "删除")
@RequestMapping(value = "delete", method = RequestMethod.POST)
public RespBody delete(@RequestBody $!{tablename} $!{lowertablename}, HttpServletRequest req) {
String operator = req.getHeader(Dict.OPERATOR_ID);
long result = service.delete($!{lowertablename}, operator);
if (result == 0) {
return new RespBody(RespBody.RetCode.FAIL, ExceptionDefined.ZEROOPERATION);
}
if (result < 0) {
return new RespBody(RespBody.RetCode.FAIL, ExceptionDefined.DELETEFAIL);
}
return new RespBody(RetCode.SUCC, Dict.SUCC);
}
}
package ks.future.dtp.api;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import ks.future.dtp.config.Dict;
import ks.future.dtp.entity.req.TestReq;
import ks.future.dtp.entity.resp.TestResp;
import ks.future.dtp.mybatis.model.DtpTest;
import ks.future.dtp.services.TestService;
import ks.future.dtp.utils.ExceptionDefined;
import ks.future.dtp.utils.RespBody;
import ks.future.dtp.utils.RespBody.RetCode;
import org.apache.commons.math3.util.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
* 测试表
*
* @author makejava
* @date 2024-07-15 15:42:31
*/
@RestController
@RequestMapping("rq/v1/setting/test/")
@Api(tags = "测试表")
public class TestApi {
@Autowired
private TestService service;
@ApiOperation(value = "查询")
@RequestMapping(value = "find", method = RequestMethod.POST)
public RespBody find(TestReq test,
@RequestParam(value = "page", required = true) int page,
@RequestParam(value = "limit", required = true) int limit,
@RequestParam(value = "isSeek", required = true) Boolean isSeek,
HttpServletRequest req) {
String operator = req.getHeader(Dict.OPERATOR_ID);
Pair<Long, List<TestResp>> res = service.find(test, page, limit, isSeek, operator);
if (res.getKey() <= 0 || res.getValue() == null) {
return new RespBody(RetCode.SUCC, ExceptionDefined.NODATAFOUND);
}
return new RespBody(res.getKey(), res.getValue());
}
@ApiOperation(value = "增加")
@RequestMapping(value = "insert", method = RequestMethod.POST)
public RespBody insert(@RequestBody DtpTest test, HttpServletRequest req) {
String operator = req.getHeader(Dict.OPERATOR_ID);
test.setSetoperatorcode(operator);
long iResult = service.insert(test, operator);
if (iResult == -1) {
return new RespBody(RetCode.PRIMARYKEYCONFLICT, ExceptionDefined.PRIMARYKEYCONFLICT);
} else if (iResult <= 0) {
return new RespBody(RetCode.FAIL, ExceptionDefined.INSERTFAIL);
} else {
return new RespBody(RetCode.SUCC, Dict.SUCC);
}
}
@ApiOperation(value = "修改")
@RequestMapping(value = "update", method = RequestMethod.POST)
public RespBody update(@RequestBody DtpTest test, HttpServletRequest req) {
String operator = req.getHeader(Dict.OPERATOR_ID);
long result = service.update(test, operator);
if (result <= 0) {
return new RespBody(RetCode.FAIL, ExceptionDefined.UPDATEFAIL);
}
return new RespBody(RetCode.SUCC, Dict.SUCC);
}
@ApiOperation(value = "删除")
@RequestMapping(value = "delete", method = RequestMethod.POST)
public RespBody delete(@RequestBody DtpTest test, HttpServletRequest req) {
String operator = req.getHeader(Dict.OPERATOR_ID);
long result = service.delete(test, operator);
if (result == 0) {
return new RespBody(RespBody.RetCode.FAIL, ExceptionDefined.ZEROOPERATION);
}
if (result < 0) {
return new RespBody(RespBody.RetCode.FAIL, ExceptionDefined.DELETEFAIL);
}
return new RespBody(RetCode.SUCC, Dict.SUCC);
}
}
service.java.vm
##定义初始变量
#set($tablename = $tableInfo.name)
#set($subtablename = $tableInfo.name.substring(3))
#set($lowertablename = $subtablename.toLowerCase())
##设置回调
$!callback.setFileName($tool.append($!{subtablename}, "Service.java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/services"))
package ks.future.dtp.services;
import ks.future.dtp.config.Dict;
import ks.future.dtp.entity.req.$!{subtablename}Req;
import ks.future.dtp.entity.resp.$!{subtablename}Resp;
import ks.future.dtp.mybatis.mapper.$!{subtablename}Mapper;
import ks.future.dtp.mybatis.model.$!{tablename};
import ks.future.dtp.entity.resp.KsFunctionResp;
import ks.future.dtp.utils.CommonMethod;
import ks.future.dtp.config.CommonData;
import org.apache.commons.math3.util.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import org.springframework.stereotype.Service;
/**
* $!{tableInfo.comment}
*
* @author $!author
* @date $!time.currTime()
*/
@Service
public class $!{subtablename}Service {
@Autowired
private $!{subtablename}Mapper mapper;
@Autowired
private CommonMethod commonMethod;
@Autowired
private CommonData commondata;
/**
* 查询
*
* @param $!{lowertablename}
* @return 实例对象
*/
public Pair<Long, List<$!{subtablename}Resp>> find($!{subtablename}Req $!{lowertablename}, int page, int limit, Boolean isSeek, String operator) {
#foreach($pkcolumn in $tableInfo.pkColumn)
$!{pkcolumn.shortType} $!{pkcolumn.name} = $!{lowertablename}.get$tool.firstUpperCase($!{pkcolumn.name})();
#end
List<$!{subtablename}Resp> result = mapper.find($!{lowertablename}#foreach($pkcolumn in $tableInfo.pkColumn), $!{pkcolumn.name}#end, page, limit);
long count = 0;
if (isSeek) {
count = mapper.count($!{lowertablename}#foreach($pkcolumn in $tableInfo.pkColumn), $!{pkcolumn.name}#end);
return new Pair<>(count, result);
} else {
return new Pair<>((long) result.size(), result);
}
}
/**
* 新增
*
* @param $!{lowertablename}
* @param operator
* @return
*/
public long insert($!{tablename} $!{lowertablename}, String operator) {
List<KsFunctionResp> getfuncmessage = commondata.getfuncmessage("$!{subtablename}.xwl");
//获取功能号并截取
String funcno = getfuncmessage.get(0).getFuncid().toString();
if (funcno.substring(12, 14).equals(Dict.PRODUCT_TAG)) {
funcno = funcno.substring(0, 12);
}
//插入日志
commonMethod.insertOperLog("新增", funcno, operator, "",$!{lowertablename}.toString());
#foreach($pkcolumn in $tableInfo.pkColumn)
$!{pkcolumn.shortType} $!{pkcolumn.name} = $!{lowertablename}.get$tool.firstUpperCase($!{pkcolumn.name})();
#end
//判断数据是否存在
long isexist = mapper.isexist(#foreach($pkcolumn in $tableInfo.pkColumn)$!{pkcolumn.name}#if($foreach.hasNext), #end#end);
if (isexist > 0) {
return -1;
} else {
return mapper.insert($!{lowertablename}#foreach($pkcolumn in $tableInfo.pkColumn), $!{pkcolumn.name}#end, false);
}
}
/**
* 修改
*
* @param $!{lowertablename}
* @param operator
* @return
*/
public long update($!{tablename} $!{lowertablename}, String operator) {
//插入日志
List<KsFunctionResp> getfuncmessage = commondata.getfuncmessage("$!{subtablename}.xwl");
//获取功能号并截取
String funcno = getfuncmessage.get(0).getFuncid().toString();
if (funcno.substring(12, 14).equals(Dict.PRODUCT_TAG)) {
funcno = funcno.substring(0, 12);
}
//插入日志
commonMethod.insertOperLog("修改", funcno, operator, "", $!{lowertablename}.toString());
#foreach($pkcolumn in $tableInfo.pkColumn)
$!{pkcolumn.shortType} $!{pkcolumn.name} = $!{lowertablename}.get$tool.firstUpperCase($!{pkcolumn.name})();
#end
return mapper.update($!{lowertablename}#foreach($pkcolumn in $tableInfo.pkColumn), $!{pkcolumn.name}#end, false);
}
/**
* 删除
*
* @param $!{lowertablename}
* @param operator
* @return
*/
public long delete($!{tablename} $!{lowertablename}, String operator) {
//插入日志
List<KsFunctionResp> getfuncmessage = commondata.getfuncmessage("$!{subtablename}.xwl");
//获取功能号并截取
String funcno = getfuncmessage.get(0).getFuncid().toString();
if (funcno.substring(12, 14).equals(Dict.PRODUCT_TAG)) {
funcno = funcno.substring(0, 12);
}
//插入日志
commonMethod.insertOperLog("删除", funcno, operator, "", $!{lowertablename}.toString());
#foreach($pkcolumn in $tableInfo.pkColumn)
$!{pkcolumn.shortType} $!{pkcolumn.name} = $!{lowertablename}.get$tool.firstUpperCase($!{pkcolumn.name})();
#end
return mapper.delete($!{lowertablename}#foreach($pkcolumn in $tableInfo.pkColumn), $!{pkcolumn.name}#end, false);
}
}
package ks.future.dtp.services;
import ks.future.dtp.config.CommonData;
import ks.future.dtp.config.Dict;
import ks.future.dtp.entity.req.TestReq;
import ks.future.dtp.entity.resp.KsFunctionResp;
import ks.future.dtp.entity.resp.TestResp;
import ks.future.dtp.mybatis.mapper.TestMapper;
import ks.future.dtp.mybatis.model.DtpTest;
import ks.future.dtp.utils.CommonMethod;
import org.apache.commons.math3.util.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 测试表
*
* @author makejava
* @date 2024-07-15 15:42:31
*/
@Service
public class TestService {
@Autowired
private TestMapper mapper;
@Autowired
private CommonMethod commonMethod;
@Autowired
private CommonData commondata;
/**
* 查询
*
* @param test
* @return 实例对象
*/
public Pair<Long, List<TestResp>> find(TestReq test, int page, int limit, Boolean isSeek, String operator) {
String testid = test.getTestid();
Long testno = test.getTestno();
List<TestResp> result = mapper.find(test, testid, testno, page, limit);
long count = 0;
if (isSeek) {
count = mapper.count(test, testid, testno);
return new Pair<>(count, result);
} else {
return new Pair<>((long) result.size(), result);
}
}
/**
* 新增
*
* @param test
* @param operator
* @return
*/
public long insert(DtpTest test, String operator) {
List<KsFunctionResp> getfuncmessage = commondata.getfuncmessage("Test.xwl");
//获取功能号并截取
String funcno = getfuncmessage.get(0).getFuncid().toString();
if (funcno.startsWith(Dict.PRODUCT_TAG, 12)) {
funcno = funcno.substring(0, 12);
}
//插入日志
commonMethod.insertOperLog("新增", funcno, operator, "", test.toString());
String testid = test.getTestid();
Long testno = test.getTestno();
//判断数据是否存在
long isexist = mapper.isexist(testid, testno);
if (isexist > 0) {
return -1;
} else {
return mapper.insert(test, testid, testno, false);
}
}
/**
* 修改
*
* @param test
* @param operator
* @return
*/
public long update(DtpTest test, String operator) {
//插入日志
List<KsFunctionResp> getfuncmessage = commondata.getfuncmessage("Test.xwl");
//获取功能号并截取
String funcno = getfuncmessage.get(0).getFuncid().toString();
if (funcno.startsWith(Dict.PRODUCT_TAG, 12)) {
funcno = funcno.substring(0, 12);
}
//插入日志
commonMethod.insertOperLog("修改", funcno, operator, "", test.toString());
String testid = test.getTestid();
Long testno = test.getTestno();
return mapper.update(test, testid, testno, false);
}
/**
* 删除
*
* @param test
* @param operator
* @return
*/
public long delete(DtpTest test, String operator) {
//插入日志
List<KsFunctionResp> getfuncmessage = commondata.getfuncmessage("Test.xwl");
//获取功能号并截取
String funcno = getfuncmessage.get(0).getFuncid().toString();
if (funcno.startsWith(Dict.PRODUCT_TAG, 12)) {
funcno = funcno.substring(0, 12);
}
//插入日志
commonMethod.insertOperLog("删除", funcno, operator, "", test.toString());
String testid = test.getTestid();
Long testno = test.getTestno();
return mapper.delete(test, testid, testno, false);
}
}
mapper.java.vm
##定义初始变量
#set($tablename = $tableInfo.name)
#set($subtablename = $tableInfo.name.substring(3))
#set($lowertablename = $subtablename.toLowerCase())
#set($underlinetablename = $tablename.replaceAll("([a-z])([A-Z])", "$1_$2").toLowerCase())
##设置回调
$!callback.setFileName($tool.append($!{subtablename}, "Mapper.java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/mybatis/mapper"))
package ks.future.dtp.mybatis.mapper;
import ks.future.dtp.mybatis.drivers.SimpleInsertLangDriver;
import org.apache.ibatis.annotations.*;
import ks.future.dtp.mybatis.model.$!{tablename};
import ks.future.dtp.entity.req.${subtablename}Req;
import ks.future.dtp.entity.resp.${subtablename}Resp;
import java.util.List;
/**
* ${tableInfo.comment}
*
* @author $!author
* @date $!time.currTime()
*/
@Mapper
public interface $!{subtablename}Mapper {
/**
* 查询
* @param $!{lowertablename}
#foreach($pkcolumn in $tableInfo.pkColumn)
* @Param $!{pkcolumn.name} $!{pkcolumn.comment}
#end
* @param page
* @param limit
* @return
*/
@Select("<script>" +
"select * from ${underlinetablename} t" +
" where 1=1 " +
#foreach($pkcolumn in $tableInfo.pkColumn)
" and (#{$!{pkcolumn.name}} = '' or #{$!{pkcolumn.name}} is null or t.$!{pkcolumn.name} = #{$!{pkcolumn.name}})" +
#end
" order by #foreach($pkcolumn in $tableInfo.pkColumn)t.$!{pkcolumn.name}#if($foreach.hasNext) ,#end#end" +
"</script>")
List<$!{subtablename}Resp> find($!{subtablename}Req $!{lowertablename},
#foreach($pkcolumn in $tableInfo.pkColumn)
@Param("$!{pkcolumn.name}") $!{pkcolumn.shortType} $!{pkcolumn.name},
#end
@Param("page") int page,
@Param("limit") int limit);
@Select("select count(1) from ${underlinetablename} t" +
" where 1=1 " +
#foreach($pkcolumn in $tableInfo.pkColumn)
" and (#{$!{pkcolumn.name}} = '' or #{$!{pkcolumn.name}} is null or t.$!{pkcolumn.name} = #{$!{pkcolumn.name}})" #if($foreach.hasNext)+
#else)
#end
#end
long count($!{subtablename}Req $!{lowertablename},
#foreach($pkcolumn in $tableInfo.pkColumn)
@Param("$!{pkcolumn.name}") $!{pkcolumn.shortType} $!{pkcolumn.name}#if($foreach.hasNext),
#end
#end);
/**
* 新增
* @param $!{lowertablename}
#foreach($pkcolumn in $tableInfo.pkColumn)
* @Param $!{pkcolumn.name} $!{pkcolumn.comment}
#end
* @param issync 是否上场
* @return
*/
@Insert("insert into ${underlinetablename} select " +
#foreach($fullcolumn in $tableInfo.fullColumn)
" #{$!{lowertablename}.$!{fullcolumn.name}}#if($foreach.hasNext),#end" +
#end
" from dual")
long insert(@Param("$!{lowertablename}") $!{tablename} $!{lowertablename},
#foreach($pkcolumn in $tableInfo.pkColumn)
@Param("$!{pkcolumn.name}") $!{pkcolumn.shortType} $!{pkcolumn.name},
#end
@Param("issync") boolean issync);
@Select("select count(1) from ${underlinetablename} t" +
" where 1=1 " +
#foreach($pkcolumn in $tableInfo.pkColumn)
" and t.$!{pkcolumn.name} = #{$!{pkcolumn.name}}" #if($foreach.hasNext)+
#else)
#end
#end
long isexist(#foreach($pkcolumn in $tableInfo.pkColumn)@Param("$!{pkcolumn.name}") $!{pkcolumn.shortType} $!{pkcolumn.name}#if($foreach.hasNext),
#end
#end);
/**
* 修改
* @param $!{lowertablename}
#foreach($pkcolumn in $tableInfo.pkColumn)
* @Param $!{pkcolumn.name} $!{pkcolumn.comment}
#end
* @param issync 是否上场
* @return
*/
@Update("update ${underlinetablename} t set " +
#foreach($othercolumn in $tableInfo.otherColumn)
" t.$!{othercolumn.name} = #{$!{lowertablename}.$!{othercolumn.name}}#if($foreach.hasNext),#end" +
#end
" where 1=1 " +
#foreach($pkcolumn in $tableInfo.pkColumn)
" and t.$!{pkcolumn.name} = #{$!{pkcolumn.name}}" #if($foreach.hasNext)+
#else)
#end
#end
long update(@Param("$!{lowertablename}") $!{tablename} $!{lowertablename},
#foreach($pkcolumn in $tableInfo.pkColumn)
@Param("$!{pkcolumn.name}") $!{pkcolumn.shortType} $!{pkcolumn.name},
#end
@Param("issync") boolean issync);
/**
* 删除
* @param $!{lowertablename}
#foreach($pkcolumn in $tableInfo.pkColumn)
* @Param $!{pkcolumn.name} $!{pkcolumn.comment}
#end
* @param issync 是否上场
* @return
*/
@Delete("delete from ${underlinetablename} t " +
" where 1=1" +
#foreach($pkcolumn in $tableInfo.pkColumn)
" and t.$!{pkcolumn.name} = #{$!{pkcolumn.name}}" #if($foreach.hasNext)+
#else)
#end
#end
long delete(@Param("$!{lowertablename}") $!{tablename} $!{lowertablename},
#foreach($pkcolumn in $tableInfo.pkColumn)
@Param("$!{pkcolumn.name}") $!{pkcolumn.shortType} $!{pkcolumn.name},
#end
@Param("issync") boolean issync);
}
package ks.future.dtp.mybatis.mapper;
import ks.future.dtp.entity.req.TestReq;
import ks.future.dtp.entity.resp.TestResp;
import ks.future.dtp.mybatis.model.DtpTest;
import org.apache.ibatis.annotations.*;
import java.util.List;
/**
* 测试表
*
* @author makejava
* @date 2024-07-15 15:42:32
*/
@Mapper
public interface TestMapper {
/**
* 查询
*
* @param test
* @param page
* @param limit
* @return
* @Param testid 测试ID
* @Param testno 测试编号
*/
@Select("<script>" +
"select * from dtp_test t" +
" where 1=1 " +
" and (#{testid} = '' or #{testid} is null or t.testid = #{testid})" +
" and (#{testno} = '' or #{testno} is null or t.testno = #{testno})" +
" order by t.testid ,t.testno" +
"</script>")
List<TestResp> find(TestReq test,
@Param("testid") String testid,
@Param("testno") Long testno,
@Param("page") int page,
@Param("limit") int limit);
@Select("select count(1) from dtp_test t" +
" where 1=1 " +
" and (#{testid} = '' or #{testid} is null or t.testid = #{testid})" +
" and (#{testno} = '' or #{testno} is null or t.testno = #{testno})")
long count(TestReq test,
@Param("testid") String testid,
@Param("testno") Long testno);
/**
* 新增
*
* @param test
* @param issync 是否上场
* @return
* @Param testid 测试ID
* @Param testno 测试编号
*/
@Insert("insert into dtp_test select " +
" #{test.testid}," +
" #{test.testno}," +
" #{test.setoperatorcode}," +
" #{test.operatordate}," +
" #{test.operatortime}" +
" from dual")
long insert(@Param("test") DtpTest test,
@Param("testid") String testid,
@Param("testno") Long testno,
@Param("issync") boolean issync);
@Select("select count(1) from dtp_test t" +
" where 1=1 " +
" and t.testid = #{testid}" +
" and t.testno = #{testno}")
long isexist(@Param("testid") String testid,
@Param("testno") Long testno);
/**
* 修改
*
* @param test
* @param issync 是否上场
* @return
* @Param testid 测试ID
* @Param testno 测试编号
*/
@Update("update dtp_test t set " +
" t.setoperatorcode = #{test.setoperatorcode}," +
" t.operatordate = #{test.operatordate}," +
" t.operatortime = #{test.operatortime}" +
" where 1=1 " +
" and t.testid = #{testid}" +
" and t.testno = #{testno}")
long update(@Param("test") DtpTest test,
@Param("testid") String testid,
@Param("testno") Long testno,
@Param("issync") boolean issync);
/**
* 删除
*
* @param test
* @param issync 是否上场
* @return
* @Param testid 测试ID
* @Param testno 测试编号
*/
@Delete("delete from dtp_test t " +
" where 1=1" +
" and t.testid = #{testid}" +
" and t.testno = #{testno}")
long delete(@Param("test") DtpTest test,
@Param("testid") String testid,
@Param("testno") Long testno,
@Param("issync") boolean issync);
}