grails - 使用grails从XML读取并将值存储在数据库中

标签 grails

这个问题已经在这里有了答案:




已关闭8年。




Possible Duplicate:
Import XML into a Grails Domain Class



说我有如下所示的xml文件,
现在我想使用grails将这些名字,deptname和empid插入数据库
谁能在这方面提出一个想法。
<employees> <employee> <firstname>Marios</firstname> <deptname>ITdepartment</deptname> <empid>123</empid> </employee> <employee> <firstname>Ben</firstname> <deptname>Management</deptname> <empid>124</empid> </employee></employees>

最佳答案

谢谢大家,我得到了答案,如果需要更改可以建议我,请在这里为其他人发布知识
def Employee = new XmlParser().parse("Your Xml file path") def set1 = sql.dataSet("Your field name in Xml") Employee.employee.each { def firstname = it.firstname.text() def deptname = it.deptname.text() def empid = it.empid.text() set1.add(first_name:firstname,dept_name:deptname,emp_id:empid)}

关于grails - 使用grails从XML读取并将值存储在数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12054808/

相关文章:

grails - Grails g:if = null不起作用

jquery - Grails g :link to call jquery function

grails - Netbeans和Grails-停止服务器

grails - 在单元测试中,如何替换域对象上的接口(interface)方法?

grails - 我有一堆数据,我需要一个使用 Grails 的数据过滤器

grails - ils。域类。 1:米

json - 如何在grails中导出json文件?

loops - Grails GSP循环遍历索引,并对选定的行进行处理

grails - 我如何使用 grails 应用程序中安装的 spring security 从我自己创建的 gsp View 注销?

grails - 如何在 Grails 中表示一对多,并对另一个域类进行约束?