1 Star 2 Fork 1

我被自己帅瞎了! / codesmith-java代码模板

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Mapper.cst 4.91 KB
一键复制 编辑 原始数据 按行查看 历史
我被自己帅瞎了! 提交于 2021-02-08 14:25 . 第一次提交
<%@ CodeTemplate Inherits="CodeTemplate" Language="C#" TargetLanguage="XML" Description="NetTiers main template." Debug="True" ResponseEncoding="UTF-8"%>
<%@ Assembly Name="SchemaExplorer"%>
<%@ Import Namespace="SchemaExplorer"%>
<%@ Import Namespace="System.Collections.Generic"%>
<%@ Property Name="Table" Type="TableSchema" DeepLoad="True" Optional="False" Category="01. Getting Started - Required" Description=""%>
<!-- #include file="Common/Common.cst" -->
<%
string TablePascal = GetPascal(Table.Name);
string DaoPascal = GetPascal(Table.Name) +"Dao";
string DaoHump = GetHump(Table.Name) +"Dao";
string DtoPascal = GetPascal(Table.Name) +"Dto";
string DtoHump = GetHump(Table.Name) +"Dto";
var clist = Table.Columns.Where(l=>!l.IsForeignKeyMember).ToList().Where(l=>!IsGenerateColumn(l.Name)).ToList();
var Primary = Table.PrimaryKey.MemberColumns[0].ToString().Split('.')[1];
var isdel = clist.Any(l=>l.Name == delfield);
var columns = Table.Columns.Where(l=>l.Name != delfield);
var columnsNoPri = Table.Columns.Where(l=>!l.IsPrimaryKeyMember).ToList().Where(l=>!IsGenerateColumn(l.Name)).ToList();
string [] Methods = GetMethods(Table.Name);
bool isSelect = Methods.Contains("select");
bool IsUpdate = Methods.Contains("update");
bool IsInsert = Methods.Contains("insert");
bool IsDelete = Methods.Contains("delete");
%>
<?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= "<%= DaoNamespacesStr %>.<%= DaoPascal %>">
<resultMap id="BaseResultMap" type="<%= ModelNamespacesStr %>.<%= DtoPascal %>">
<%foreach(ColumnSchema col in columns){
%>
<result column="<%= col.Name %>" jdbcType="<%= GetDataJdbcType(col.DataType)%>" property="<%= GetHump(col.Name) %>" />
<% } %>
</resultMap>
<sql id="Base_Column_List">
<%
List<string> list = new List<string>();
foreach(ColumnSchema col in columns){
list.Add(col.Name.ToString());
}
%>
<%= string.Join(",",list) %>
</sql>
<%=isSelect?"":"<!--" %>
<select id="get<%= TablePascal %>List" parameterType="java.util.HashMap" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from <%= Table.Name %>
<% if(isdel){ %>
where <%=delfield%>='0'
<% }%>
</select>
<select id="get<%= TablePascal %>" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from <%= Table.Name %>
where
<% if(isdel){ %>
<%=delfield%>='0' and
<% }%>
<%= Primary %> = #{<%=Primary%>,jdbcType=INTEGER}
</select>
<%=isSelect?"":"-->" %>
<%=IsUpdate?"":"<!--" %>
<update id="update<%= TablePascal %>" parameterType="<%= ModelNamespacesStr %>.<%= DtoPascal %>">
update <%= Table.Name %>
set
<%
int a = 1;
foreach(ColumnSchema col in columnsNoPri){
a++;
if(col.Name == "createtime"){ continue; }
var iszh = a==columnsNoPri.Count;
%>
<%= col.Name %> = #{<%= GetHump(col.Name) %>,jdbcType=<%= GetDataJdbcType(col.DataType) %>}<% if(!iszh){ %>,<% }%>
<% } %>
where <%= Primary %> = #{<%=Primary%>,jdbcType=INTEGER}
</update>
<%=IsUpdate?"":"-->" %>
<%=IsInsert?"":"<!--" %>
<insert id="insert<%= TablePascal %>" parameterType="<%= ModelNamespacesStr %>.<%= DtoPascal %>">
insert into <%= Table.Name %>
<trim prefix="(" suffix=")" suffixOverrides=",">
<%foreach(ColumnSchema col in columns){
if(col.Name=="updatetime" || col.Name == "createtime"){ continue; }
%>
<if test="<%= GetHump(col.Name) %> != null">
<%= col.Name %>,
</if>
<% } %>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<%foreach(ColumnSchema col in columns){
if(col.Name=="updatetime" || col.Name == "createtime"){ continue; }
%>
<if test="<%= GetHump(col.Name) %> != null">
#{<%= col.Name %>,jdbcType=<%= GetDataJdbcType(col.DataType) %>},
</if>
<% } %>
</trim>
</insert>
<%=IsInsert?"":"-->" %>
<%=IsDelete?"":"<!--" %>
<% if(isdel){ %>
<update id="delete<%= TablePascal %>" parameterType="java.lang.Integer">
update <%= Table.Name %>
set <%= delfield %> = 1
where <%= Primary %> = #{<%=Primary%>,jdbcType=INTEGER}
</update>
<% } %>
<% else{ %>
<delete id="delete<%= TablePascal %>" parameterType="java.lang.Integer">
delete from <%= Table.Name %>
where
<%= Primary %> = #{<%=Primary%>,jdbcType=INTEGER}
</delete>
<% } %>
<%=IsDelete?"":"-->" %>
</mapper>
其他
1
https://gitee.com/momentzhj/codesmith-java-code-template.git
git@gitee.com:momentzhj/codesmith-java-code-template.git
momentzhj
codesmith-java-code-template
codesmith-java代码模板
master

搜索帮助