@Override public int countGroupMasterByUid(String uid) { return getSqlSessionTemplate().selectOne("countGroupMasterByUid", uid); } @Override public int countGroupMaster(String uid, String groupId) { Map map = new HashMap (); map.put("uid", uid); map.put("groupId", groupId); return getSqlSessionTemplate().selectOne("countGroupMaster", map); } @Override public GetGroupMember queryMasterByGroupId(String groupId) { return getSqlSessionTemplate().selectOne("queryMasterByGroupId", groupId); } @Override public String queryMasterIdByUid(String uid) { return getSqlSessionTemplate().selectOne("queryMasterIdByUid", uid); } @Override public List queryMasterList(int index, int pageSize) { Map map = new HashMap (); map.put("index", (index-1)*pageSize); map.put("pageSize", pageSize); return getSqlSessionTemplate().selectList("queryMasterList",map); }
亦可以参考:
动态SQL参考:
selectKey的使用
<!-- 这里需要说明一下不同的数据库主键的生成,对各自的数据库有不同的方式: --><!-- mysql:SELECT LAST_INSERT_ID() AS VALUE --><!-- mssql:select @@IDENTITY as value --><!-- oracle:SELECT STOCKIDSEQUENCE.NEXTVAL AS VALUE FROM DUAL --><!-- 还有一点需要注意的是不同的数据库生产商生成主键的方式不一样,有些是预先生成 (pre-generate)主键的,如Oracle和PostgreSQL。 有些是事后生成(post-generate)主键的,如MySQL和SQL Server 所以如果是Oracle数据库,则需要将selectKey写在insert之前 -->
INSERT INTO t_mc_store_group_master (id,u_id,u_name,dept_name) VALUES (#{masterId},#{uid},#{uName},#{deptName}) SELECT LAST_INSERT_ID() AS masterId
组合查询设置不存在的列
SELECT tu.id casualId, tu.name name, tu.expire_time validdate, tu.pb_upload, tu.pb_down, tu.pb_share, tu.pb_rename, tu.pb_view, tu.pb_delete, tu.account, IF(ul.id>0,1,0) status FROM t_mc_store_casual_user tu JOIN t_mc_store_manage_department md ON tu.dept_id = md.dept_id LEFT JOIN t_mc_store_user_lock ul ON tu.account = ul.account WHERE md.u_id = #{uid} AND tu.is_delete = 0 LIMIT #{index},#{pageSize}