Skip to content

Commit

Permalink
清理数据
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Mar 3, 2019
1 parent 237dbf3 commit d54fae5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
15 changes: 10 additions & 5 deletions GoMybatisTempleteDecoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ type ExampleActivityMapper struct {
//初始化mapper文件和结构体
var exampleActivityMapper = ExampleActivityMapper{}

func init() {
func getMapper() ExampleActivityMapper{
initMapper()
return exampleActivityMapper
}

func initMapper() {
bytes := []byte(`<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://raw.githubusercontent.com/zhuxiujia/GoMybatis/master/mybatis-3-mapper.dtd">
Expand Down Expand Up @@ -184,7 +189,7 @@ func TestGoMybatisTempleteDecoder_Create(t *testing.T) {
act,
}
var session = TempleteSession{}
n, err := exampleActivityMapper.InsertTemplete(args, &session)
n, err := getMapper().InsertTemplete(args, &session)
if err != nil {
t.Fatal(err)
}
Expand All @@ -194,7 +199,7 @@ func TestGoMybatisTempleteDecoder_Create(t *testing.T) {

func TestGoMybatisTempleteDecoder_Select(t *testing.T) {
var session = TempleteSession{}
n, err := exampleActivityMapper.SelectTemplete("test", &session)
n, err := getMapper().SelectTemplete("test", &session)
if err != nil {
t.Fatal(err)
}
Expand All @@ -208,7 +213,7 @@ func TestGoMybatisTempleteDecoder_Update(t *testing.T) {
Name: "test",
}
var session = TempleteSession{}
n, err := exampleActivityMapper.UpdateTemplete(act, &session)
n, err := getMapper().UpdateTemplete(act, &session)
if err != nil {
t.Fatal(err)
}
Expand All @@ -218,7 +223,7 @@ func TestGoMybatisTempleteDecoder_Update(t *testing.T) {

func TestGoMybatisTempleteDecoder_Delete(t *testing.T) {
var session = TempleteSession{}
n, err := exampleActivityMapper.DeleteTemplete("test", &session)
n, err := getMapper().DeleteTemplete("test", &session)
if err != nil {
t.Fatal(err)
}
Expand Down
13 changes: 1 addition & 12 deletions XmlLoader.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func LoadMapperXml(bytes []byte) (items map[string]etree.Token) {
items = make(map[string]etree.Token)
root := doc.SelectElement(Element_Mapper)
for _, s := range root.ChildElements() {
var attrMap = attrToProperty(s.Attr)
if s.Tag == Element_Insert ||
s.Tag == Element_Delete ||
s.Tag == Element_Update ||
Expand All @@ -29,11 +28,10 @@ func LoadMapperXml(bytes []byte) (items map[string]etree.Token) {
s.Tag == Element_Delete_Templete ||
s.Tag == Element_Update_Templete ||
s.Tag == Element_Select_Templete {
var elementID = attrMap[ID]
var elementID = s.SelectAttrValue(ID,"")

if elementID == "" {
//如果id不存在,id设置为tag
attrMap[ID] = s.Tag
elementID = s.Tag
}
if elementID != "" {
Expand Down Expand Up @@ -77,15 +75,6 @@ func includeElementReplace(xml *etree.Element, xmlMap *map[string]etree.Token) {
}
}
}

func attrToProperty(attrs []etree.Attr) map[string]string {
var m = make(map[string]string)
for _, v := range attrs {
m[v.Key] = v.Value
}
return m
}

////标签上下级关系检查
//func elementRuleCheck(fatherElement *etree.Element, childElementItem ElementItem) {
// if fatherElement.Tag != Element_choose && (childElementItem.ElementType == Element_when || childElementItem.ElementType == Element_otherwise) {
Expand Down
2 changes: 2 additions & 0 deletions XmlLoader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"os"
"testing"
"time"
)

func Test_Load_Xml(t *testing.T) {
Expand All @@ -19,5 +20,6 @@ func Test_Load_Xml(t *testing.T) {
if xmlItems == nil {
t.Fatal(`Test_Load_Xml fail,LoadMapperXml "example/Example_ActivityMapper.xml"`)
}
time.Sleep(time.Second)
fmt.Println(xmlItems)
}

0 comments on commit d54fae5

Please sign in to comment.