The syntax described below, when the usage scenario is to move a node in the tree, modifies the node and all parent nodes (Parentids) of its child nodes.
<update id= "Uptparentid" parametertype= "Map" >
Update trainstaff_dept Set parentids = replace (Parentids,#{oldpid},#{newpid}) where Companyid=#{companyid}
<if test= "Null!=id" > and Id=#{id} </if>
</update>
<update id= "Uptparentids" parametertype= "Map" >
Update trainstaff_dept Set Parentids=concat (#{newpid},substring (parentids,#{length}+1)) where substring (parentids,1 , #{length}) =#{oldpid} and Companyid=#{companyid};
</update>
SUBSTRING (filed,m): Intercepts the filed field from the first m character to the end of the string;
SUBSTRING (filed,m,n): Intercepts the string of length n of the filed field starting with the first m character;
Cancat (string1,sting2,......): string1, string2, ... strings are concatenated together.
Replace (Parentids,#{oldpid},#{newpid})
Parentids: Fields that need to be replaced
Oldpid: The old string
Newpid: New String
MySQL (substring function, contact function, and use of replace function)