Cordys 后端增删改查 例子

增加:

第一种方法:【利用参数】

 public static String GetDepartmentIDByInsert(String DepartName, int ParentID)
    {
    	String sqlInsert="insert into department (DepartName,ParentID) values('"+DepartName+"',"+ParentID+" )";

    	DMLStatement dml = new DMLStatement(sqlInsert);
    	
    	
    	String sqlQuery="select  LAST_INSERT_ID() as id from dual ";
    	
    	QueryObject query = new QueryObject(sqlQuery); 
    	query.setResultClass(AnonymousBusObject.class);
    	
    	dml.executeDML();
    	AnonymousBusObject boit = (AnonymousBusObject)query.getObject();
    	String resultValue = boit.getStringProperty("id");
        return resultValue;
    }
    


第二种方法:【利用利用对象,在定义接口时候,可以把整个对象作为一个参数】

Cordys 后端增删改查 例子_第1张图片

WebService接口


  
    
      
        
          PARAMETER
          PARAMETER
          PARAMETER
          PARAMETER
          PARAMETER
          PARAMETER
          PARAMETER
          PARAMETER
          PARAMETER
          PARAMETER
          PARAMETER
          PARAMETER
          PARAMETER
          PARAMETER
          PARAMETER
        
      
    
  



后台接口

    public static String saveOrganization(com.unicom.bopm.organization.SM_ORGANIZATION organization)
    {
        return OrganizationManager.saveOrganization(organization);
    }
    


删除


第一种方法:

    public static void DeleteByID(int ID)
    {
        String stringText = "delete from department where ID =:ID";
        DMLStatement dml = new DMLStatement(stringText);
        dml.addParameter("ID", "department.ID", ID);
        dml.executeDML();
    }

第二种方法:


   		SM_MENU currentMenuObj=null;
    		String currentMenuQT="SELECT * FROM SM_MENU M WHERE M.MENU_ID=:MENU_ID";
    		QueryObject currentMenuQ = new QueryObject(currentMenuQT);
    		currentMenuQ.addParameter("MENU_ID","SM_MENU.MENU_ID", QueryObject.PARAM_STRING, menu_id);
    		currentMenuQ.setResultClass(SM_MENU.class);
    		currentMenuObj=(SM_MENU) currentMenuQ.getObject();
    		currentMenuObj.setSTATUS_SIGN(status_sign);
    		currentMenuObj.delete();




修改

第一种方法

    public static void UpdateByName(String Name,int ID)
    {
    	String sqlUpdate="update department set DepartName='"+Name+"' where ID="+ID;
        DMLStatement dml = new DMLStatement(sqlUpdate);
        dml.executeDML();
    }

第二种方法:


    		BusObjectIterator childMenusObj = null;
    		String childMenusQT="SELECT * FROM SM_MENU M WHERE M.PARENT_ID=:MENU_ID";
    		QueryObject childMenusQ = new QueryObject(childMenusQT);
    		childMenusQ.addParameter("MENU_ID","SM_MENU.MENU_ID", QueryObject.PARAM_STRING, menu_id);
    		childMenusQ.setResultClass(SM_MENU.class);
    		childMenusObj=childMenusQ.getObjects();
    		while(childMenusObj.hasMoreElements())
    		{
    			SM_MENU obj=(SM_MENU)childMenusObj.nextElement();
    			obj.setSTATUS_SIGN(status_sign);
    			obj.update();
    		}


查询

    public static BusObjectIterator GetDepartmentByParentID(int ParentID)
    {
        String queryText = "select * from department where ParentID= :ID";
        QueryObject query = new QueryObject(queryText);
        query.addParameter("ID", "department.ParentID", QueryObject.PARAM_INT ,ParentID);
        query.setResultClass(department.class);
        return query.getObjects();
    }


你可能感兴趣的:(Cordys)