servicImpl层:
SqlSession sqlSession = sqlSessionFactory.openSession();
// 3.获取对应mapper
TUserMapper mapper = sqlSession.getMapper(TUserMapper.class);
String inCol = "id, user_name, real_name, sex, mobile, email, note";
String tableName = "t_user";
Byte sex = 1;
String orderStr = "sex,user_name";
List<TUser> list = mapper.selectBySymbol(tableName, inCol, orderStr, sex);
mapper层:
List<TUser> selectBySymbol(@Param("tableName")String tableName,
@Param("inCol")String inCol,
@Param("orderStr")String orderStr,
@Param("sex")Byte sex);
xml层:
<select id="selectBySymbol" resultMap="BaseResultMap">
select
#{inCol}
from ${tableName} a
where a.sex = #{sex}
order by ${orderStr}
</select>