MyBatis映射

package com.kaishengit.dto;

import lombok.Data;

/**
 * Created by wgs on 2017/2/24.
 */
@Data
public class EChartsResult {
    public static final String TYPE_IN = "收入";
    public static final String TYPE_OUT = "支出";
    private String name;
    private Float value;

    public EChartsResult() {
    }

    public EChartsResult(String name, Float value) {
        this.name = name;
        this.value = value;
    }
}


/**
     * 饼图 异步加载加载数据
     * @param request
     * @return
     */
    @GetMapping("/month/pie")
    @ResponseBody
    public AjaxResult data(HttpServletRequest request) {
        //获取表单的值
        String month = request.getParameter("moth");
        System.out.println("----------------->" + month+"<------------------");
        //取数据库查找数据
        List<EChartsResult> eChartsResults = financeService.findByQuery(month);
        System.out.println(eChartsResults);
        if (eChartsResults != null) {
            return new AjaxResult(eChartsResults);
        } else {
            return new AjaxResult(AjaxResult.ERROR, "该内容不存在");
        }

    }

映射文件
 <select id="findByQuery" resultType="com.kaishengit.dto.EChartsResult">
         SELECT tf.module AS "name" ,SUM(tf.money)AS "value" FROM t_finance AS tf
              WHERE tf.create_date LIKE CONCAT('%',#{month},'%') GROUP BY tf.module
    </select>

resultMap

public class Dept {
    private Integer id;
    private  String deptname;
    private List<Employee> employeeList;
// getXxx  setXxx
}

public class Employee {

    private Integer id;
    private String empname;
    private Integer deptid;
    private Dept dept;
}
 <select id="findById" parameterType="int" resultMap="empMap">
        SELECT employee.id,empname,deptid,deptname
        FROM
        employee
        INNER JOIN dept ON employee.deptid = dept.id
        WHERE
        employee.id =  #{id}
    </select>


    <!--配置结果集映射-->
    <resultMap id="empMap" type="Employee">
        <id column="id" property="id"/>
        <result column="empname" property="empname"/>
        <result column="deptid" property="deptid"/>
        <association property="dept" javaType="Dept" column="deptid">
            <id property="id" column="deptid"></id>
            <result property="deptname" column="dept.deptname"></result>
        </association>
    </resultMap>

ONGL 特性

    <select id="findById" parameterType="int" resultType="Employee">
       SELECT employee.id,empname,deptid,
            dept.id AS 'dept.id',deptname AS 'dept.deptname'
        FROM
            employee
        INNER JOIN dept ON employee.deptid = dept.id
        WHERE
            employee.id =  #{id}
    </select>





最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容