Spring data jpa 调用存储进程ITeye - AG环亚娱乐集团

Spring data jpa 调用存储进程ITeye

2019-01-11 09:24:13 | 作者: 吉星 | 标签: 添加,确保,晋级 | 浏览: 2383

1,先确保晋级相关的类库

org.springframework-version 4.1.7.RELEASE /org.springframework-version

spring.data.jpa.version 1.9.6.RELEASE /spring.data.jpa.version

org.hibernate-version 5.0.8.Final /org.hibernate-version

2,create stored procedure

PROCEDURE xxSearch_member(xPara in nvarchar2, xcur_ret out nvarchar2) is

  xkey1                 varchar2(100);
  xkey2                 varchar2(100);
  xname                 varchar2(100);
begin

    xkey1 := xxXml_child_text(xPara,key1);
    xkey2 := xxXml_child_text(xPara,key2);
    xName := xxXml_child_text(xPara,name);
   
   xcur_ret := users user userId 1 /userId userName Tom /userName /user user userId 2 /userId userName Jos /userName /user /users

end xxSearch_member;

3,修正PO

@Entity
@Table(name="W_USER")
@NamedQuery(name="UserId.findAll", query="SELECT u FROM UserId u")
@NamedStoredProcedureQueries(value = {
    @NamedStoredProcedureQuery(name="UserId.searchMember", procedureName = "TRAN_PROC.xxSearch_member",parameters = {
        @StoredProcedureParameter(mode = ParameterMode.IN, type = String.class),
        @StoredProcedureParameter(mode = ParameterMode.OUT, type = String.class) })
,
@NamedStoredProcedureQuery(name = "UserId.testPro", procedureName = "TRAN_PROC.testPro", parameters = {
        @StoredProcedureParameter(mode = ParameterMode.IN, type = Integer.class),
        @StoredProcedureParameter(mode = ParameterMode.OUT, type = Integer.class)
})
})

public class UserId implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private long id; 4,在repository里边添加 @Procedure(name="UserId.searchMember", procedureName = "TRAN_PROC.xxSearch_member")
String searchMember(String xPara);

@Procedure(name="UserId.testPro", procedureName = "TRAN_PROC.testPro")
Integer testPro(Integer x); 5,service 添加办法,运用dom4j解析xml public List UserUI2 searchMember(String paras){
List UserUI2 l=new ArrayList UserUI2
String xml=this.repository.searchMember(paras);
Document document = null;
UserUI2 vo = null;
try {
document = DocumentHelper.parseText(xml);
Element root = document.getRootElement();//users

// iterate through child elements of root
for ( Iterator k = root.elementIterator(); k.hasNext(); ) {
Element element = (Element) k.next();//user
vo = new UserUI2();
for ( int i = 0, size = element.nodeCount(); i size; i++ ) {
Node node = element.node(i); 
if ( node instanceof Element ) {
Element e=( (Element) node );
if(e.getName().equals("userId"))
vo.setUserId(e.getTextTrim());
else if(e.getName().equals("userName")){
vo.setUserName(e.getTextTrim());
}
//this.logger.info("e.getText()="+e.getText()+" e.getStringValue()="+e.getStringValue()+" e.getName()="+e.getName());

}
l.add(vo);
}
} catch (Exception e) {
this.logger.error("Parse xml error:",e);
}

return l;
}

 

版权声明
本文来源于网络,版权归原作者所有,其内容与观点不代表AG环亚娱乐集团立场。转载文章仅为传播更有价值的信息,如采编人员采编有误或者版权原因,请与我们联系,我们核实后立即修改或删除。

猜您喜欢的文章