Skip to content

Commit

Permalink
add json decode.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Jun 6, 2020
1 parent a7a3001 commit ec44a32
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 36 deletions.
1 change: 0 additions & 1 deletion GoMybatis.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ func makeResultMaps(xmls map[string]etree.Token) map[string]map[string]*ResultPr
var property = ResultProperty{
XMLName: elementItem.Tag,
Column: elementItem.SelectAttrValue("column", ""),
Property: elementItem.SelectAttrValue("property", ""),
LangType: elementItem.SelectAttrValue("langType", ""),
}
resultPropertyMap[property.Column] = &property
Expand Down
4 changes: 0 additions & 4 deletions GoMybatisSqlResultDecoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,25 +225,21 @@ func Test_Decode_Interface(t *testing.T) {
resultMap["id"] = &ResultProperty{
XMLName: "id",
Column: "id",
Property: "id",
LangType: "string",
}
resultMap["name"] = &ResultProperty{
XMLName: "result",
Column: "name",
Property: "Name",
LangType: "string",
}
resultMap["Amount_1"] = &ResultProperty{
XMLName: "result",
Column: "Amount_1",
Property: "amount_1",
LangType: "string",
}
resultMap["amount_2"] = &ResultProperty{
XMLName: "result",
Column: "Amount_2",
Property: "amount_2",
LangType: "string",
}
var result map[string]string
Expand Down
16 changes: 8 additions & 8 deletions README-ch.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ func main() {
<!--logic_undelete 逻辑删除 未删除字段-->
<!--version_enable 乐观锁版本字段,支持int,int8,int16,int32,int64-->
<resultMap id="BaseResultMap" tables="biz_activity">
<id column="id" property="id"/>
<result column="name" property="Name" langType="string"/>
<result column="pc_link" property="PcLink" langType="string"/>
<result column="h5_link" property="H5Link" langType="string"/>
<result column="remark" property="Remark" langType="string"/>
<result column="version" property="Version" langType="int"
<id column="id" />
<result column="name" langType="string"/>
<result column="pc_link" langType="string"/>
<result column="h5_link" langType="string"/>
<result column="remark" langType="string"/>
<result column="version" langType="int"
version_enable="true"/>
<result column="create_time" property="CreateTime" langType="time.Time"/>
<result column="delete_flag" property="DeleteFlag" langType="int"
<result column="create_time" langType="time.Time"/>
<result column="delete_flag" langType="int"
logic_enable="true"
logic_undelete="1"
logic_deleted="0"/>
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ func main() {
<!--logic_undelete Logically Delete Undeleted Fields-->
<!--version_enable Optimistic lock version field, support int, int8, int16, int32, Int64-->
<resultMap id="BaseResultMap" tables="biz_activity">
<id column="id" property="id"/>
<result column="name" property="Name" langType="string"/>
<result column="pc_link" property="PcLink" langType="string"/>
<result column="h5_link" property="H5Link" langType="string"/>
<result column="remark" property="Remark" langType="string"/>
<result column="version" property="Version" langType="int"
<id column="id" />
<result column="name" langType="string"/>
<result column="pc_link" langType="string"/>
<result column="h5_link" langType="string"/>
<result column="remark" langType="string"/>
<result column="version" langType="int"
version_enable="true"/>
<result column="create_time" property="CreateTime" langType="time.Time"/>
<result column="delete_flag" property="DeleteFlag" langType="int"
<result column="create_time" langType="time.Time"/>
<result column="delete_flag" langType="int"
logic_enable="true"
logic_undelete="1"
logic_deleted="0"/>
Expand Down
1 change: 0 additions & 1 deletion ResultMap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ package GoMybatis
type ResultProperty struct {
XMLName string //`xml:"result/id"`
Column string
Property string
LangType string
}
26 changes: 13 additions & 13 deletions example/Example_ActivityMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!--logic_undelete 逻辑删除 未删除字段-->
<!--version_enable 乐观锁版本字段,支持int,int8,int16,int32,int64-->
<resultMap id="BaseResultMap" tables="biz_activity">
<id column="id"/>
<id column="id" langType="string"/>
<result column="name" langType="string"/>
<result column="pc_link" langType="string"/>
<result column="h5_link" langType="string"/>
Expand Down Expand Up @@ -105,11 +105,11 @@
update biz_activity
<set>
<if test="name != nil">name = #{name},</if>
<if test="pcLink != nil">pc_link = #{pcLink},</if>
<if test="h5Link != nil">h5_link = #{h5Link},</if>
<if test="pc_link != nil">pc_link = #{pc_link},</if>
<if test="h5_link != nil">h5_link = #{h5_link},</if>
<if test="remark != nil">remark = #{remark},</if>
<if test="createTime != nil">create_time = #{createTime},</if>
<if test="deleteFlag != nil ">delete_flag = #{deleteFlag},</if>
<if test="create_time != nil">create_time = #{create_time},</if>
<if test="delete_flag != nil ">delete_flag = #{delete_flag},</if>
</set>
where id = #{id} and delete_flag = 1
</update>
Expand All @@ -118,21 +118,21 @@
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != nil">id,</if>
<if test="name != nil">name,</if>
<if test="pcLink != nil">pc_link,</if>
<if test="h5Link != nil">h5_link,</if>
<if test="pc_link != nil">pc_link,</if>
<if test="h5_link != nil">h5_link,</if>
<if test="remark != nil">remark,</if>
<if test="createTime != nil">create_time,</if>
<if test="deleteFlag != nil">delete_flag,</if>
<if test="create_time != nil">create_time,</if>
<if test="delete_flag != nil">delete_flag,</if>
</trim>

<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != nil">#{id},</if>
<if test="name != nil">#{name},</if>
<if test="pcLink != nil">#{pcLink},</if>
<if test="h5Link != nil">#{h5Link},</if>
<if test="pc_link != nil">#{pc_link},</if>
<if test="h5_link != nil">#{h5_link},</if>
<if test="remark != nil">#{remark},</if>
<if test="createTime != nil">#{createTime},</if>
<if test="deleteFlag != nil">#{deleteFlag},</if>
<if test="create_time != nil">#{create_time},</if>
<if test="delete_flag != nil">#{delete_flag},</if>
</trim>
</insert>

Expand Down
2 changes: 1 addition & 1 deletion example/Example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func Test_inset(t *testing.T) {
//推荐使用snowflake雪花算法 代替uuid防止ID碰撞,id最好用string类型. 否则客户端有可能不支持long类型例如JavaScript
var id = SnowflakeNode.Generate().String()
//使用mapper
var result, err = exampleActivityMapper.Insert(Activity{Id: id, Name: "test_insert", CreateTime: time.Now(), DeleteFlag: 1})
var result, err = exampleActivityMapper.Insert(Activity{Id: id, Name: "test_insert", PcLink: "ssss", CreateTime: time.Now(), DeleteFlag: 1})
if err != nil {
panic(err)
}
Expand Down

0 comments on commit ec44a32

Please sign in to comment.