增加MyBatis的Map参数传递和返回实例,支持分页。

This commit is contained in:
thinkgem
2018-08-04 15:54:47 +08:00
parent 6895d57cfa
commit dc088a4764
4 changed files with 36 additions and 4 deletions

View File

@@ -12,6 +12,7 @@ import org.springframework.core.NamedThreadLocal;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import com.jeesite.common.lang.ByteUtils;
import com.jeesite.common.lang.DateUtils;
import com.jeesite.common.lang.TimeUtils;
import com.jeesite.common.service.BaseService;
@@ -61,10 +62,10 @@ public class LogInterceptor extends BaseService implements HandlerInterceptor {
// 打印JVM信息。
if (logger.isDebugEnabled()){
logger.debug("计时结束: {} 用时: {} URI: {} 最大内存: {}m 已分配内存: {}m 已分配内存中的剩余空间: {}m 最大可用内存: {}m",
DateUtils.formatDate(endTime, "hh:mm:ss.SSS"), TimeUtils.formatDateAgo(executeTime),
request.getRequestURI(), Runtime.getRuntime().maxMemory()/1024/1024, Runtime.getRuntime().totalMemory()/1024/1024, Runtime.getRuntime().freeMemory()/1024/1024,
(Runtime.getRuntime().maxMemory()-Runtime.getRuntime().totalMemory()+Runtime.getRuntime().freeMemory())/1024/1024);
Runtime runtime = Runtime.getRuntime();
logger.debug("计时结束: {} 用时: {} URI: {} 总内存: {} 已用内存: {}",
DateUtils.formatDate(endTime, "hh:mm:ss.SSS"), TimeUtils.formatDateAgo(executeTime), request.getRequestURI(),
ByteUtils.formatByteSize(runtime.totalMemory()), ByteUtils.formatByteSize(runtime.totalMemory()-runtime.freeMemory()));
}
}

View File

@@ -3,6 +3,9 @@
*/
package com.jeesite.modules.test.dao;
import java.util.List;
import java.util.Map;
import com.jeesite.common.dao.CrudDao;
import com.jeesite.common.mybatis.annotation.MyBatisDao;
import com.jeesite.modules.test.entity.TestData;
@@ -15,4 +18,9 @@ import com.jeesite.modules.test.entity.TestData;
@MyBatisDao
public interface TestDataDao extends CrudDao<TestData> {
/**
* 演示Map参数和返回值支持分页
*/
public List<Map<String, Object>> findListForMap(Map<String, Object> params);
}

View File

@@ -51,6 +51,16 @@ public class TestDataService extends CrudService<TestDataDao, TestData> {
*/
@Override
public Page<TestData> findPage(Page<TestData> page, TestData testData) {
// // 演示Map参数和返回值支持分页
// Page<Map<String, Object>> pageMap = new Page<>();
// Map<String, Object> params = MapUtils.newHashMap();
// params.put("testInput", "123");
// params.put("page", pageMap);
// pageMap.setList(dao.findListForMap(params));
// System.out.println(pageMap.getList());
// System.out.println(pageMap.getCount());
return super.findPage(page, testData);
}

View File

@@ -12,4 +12,17 @@
ORDER BY ${sqlMap.order.toSql()}
</select> -->
<!-- 演示Map参数和返回值支持分页 -->
<select id="findListForMap" resultType="map">
SELECT * FROM test_data a
<where>
<if test="testInput != null and testInput != ''">
AND a.test_input = #{testInput}
</if>
</where>
<if test="page != null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</if>
</select>
</mapper>