mybatis 返回 Map类型数据; 插入数据生成uuid

Map类型数据

当查询结果返回时取别名时,有时候实体对象没有相应的属性接收,这时就需要返回一个Map类型:

Mapper.xml 文件,返回类型用:resultType

    <select id="statisticsByDay" parameterType="java.util.Map" resultType="java.util.Map">
        SELECT DATE_FORMAT(create_time,'%Y年%m月%d日') AS statisticsDate,SUM(amount) amount, COUNT(id) headcount FROM `remittanceHistory`
        <include refid="statistics_where"/>
        GROUP BY DATE_FORMAT(create_time,'%Y年%m月%d日')
        ORDER BY create_time DESC
    </select>

Mapper.java 文件接收方式:

    List<Map<String, Object>> statisticsByDay(Map<String, Object> paramMap);

插入数据生成uuid

  <insert id="insert" parameterType="com.xxx.xxxx" >
    <selectKey keyProperty="id" resultType="string" order="BEFORE">
      select replace(uuid(), '-', '') as id from dual
    </selectKey>
insert into xxxTable(id,createtime, status) values (#{id,jdbcType=VARCHAR}, #{createtime,jdbcType=TIMESTAMP}, #{status,jdbcType=INTEGER})
</insert>

猜你喜欢

转载自www.cnblogs.com/L237/p/12347183.html