Commit efdcd319 by guanchen

添加动态sql

parent a09be9fd
...@@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; ...@@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lanren.huhu.partner.domain.UserAgent; import com.lanren.huhu.partner.domain.UserAgent;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.SelectProvider;
import java.util.List; import java.util.List;
...@@ -24,18 +24,24 @@ public interface UserAgentMapper extends BaseMapper<UserAgent> { ...@@ -24,18 +24,24 @@ public interface UserAgentMapper extends BaseMapper<UserAgent> {
* @param agentId * @param agentId
* @return * @return
*/ */
@Select("SELECT b.* " + // @Select("SELECT b.* " +
"FROM user_agent a " + // "FROM user_agent a " +
"JOIN user_agent b on a.#{parentColumnName}=b.agent_id " + // "JOIN user_agent b on a.#{parentColumnName}=b.agent_id " +
"WHERE a.agent_id=#{agentId} and b.agent_level<=4") // "WHERE a.agent_id=#{agentId} and b.agent_level<=4")
UserAgent getParentAgent(Integer agentId, String parentColumnName); // UserAgent getParentAgent(Integer agentId, String parentColumnName);
@SelectProvider(type = UserAgentSqlProvider.class, method = "getParentAgent")
UserAgent getParentAgent(@Param("agentId") Integer agentId, @Param("parentColumnName") String parentColumnName);
/** /**
* 按uid查找下级 UserAgent * 按uid查找下级 UserAgent
*/ */
@Select("SELECT b.* " + // @Select("SELECT b.* " +
"FROM user_agent a " + // "FROM user_agent a " +
"JOIN user_agent b on a.#{parentColumnName}=b.agent_id " + // "JOIN user_agent b on a.#{parentColumnName}=b.agent_id " +
"WHERE a.user_id=#{userId}") // "WHERE a.user_id=#{userId}")
List<UserAgent> getChildrenByUserId(Integer userId, String parentColumnName); // List<UserAgent> getChildrenByUserId(Integer userId, String parentColumnName);
@SelectProvider(type = UserAgentSqlProvider.class, method = "getChildrenByUserId")
List<UserAgent> getChildrenByUserId(@Param("userId") Integer userId, @Param("parentColumnName") String parentColumnName);
} }
\ No newline at end of file
package com.lanren.huhu.partner.dao;
import org.apache.ibatis.annotations.Param;
/**
* @author chen
* @title: UserAgentSqlProvider
* @projectName partner
* @description: 提供动态sql
* @package com.lanren.huhu.partner.dao
* @date 2019-07-03 16:29
*/
public class UserAgentSqlProvider {
public String getParentAgent(@Param("agentId") Integer agentId, @Param("parentColumnName") String parentColumnName) {
return "SELECT b.* " +
"FROM user_agent a " +
"JOIN user_agent b on a." + parentColumnName + "=b.agent_id " +
"WHERE a.agent_id=#{agentId} and b.agent_level<=4";
}
public String getChildrenByUserId(@Param("userId") Integer userId, @Param("parentColumnName") String parentColumnName) {
return "SELECT b.* " +
"FROM user_agent a " +
"JOIN user_agent b on a." + parentColumnName + "=b.agent_id " +
"WHERE a.user_id=#{userId}";
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment