" />

"/>
 首页 > 作文

Mybatis的resultMap返回map问题

更新时间:2023-04-04 22:21:07 阅读: 评论:0

目录
resultmap返回map问题简单封装resultmap返回对象为map

resultmap返回map问题

<resultmap type="map" id="bankmaintainmap">      <result column="bank_name" property="bankname"/>      <result column="maintain_time_interval" property="maintaintimeinterval"/>  </resultmap>  <lect id="getmaintainnotice" parametertype="map" resultmap="bankmaintainmap">      lect           bank_name,          maintain_time_interval      from          fp_channel_prd_bank      where           channel_prd_id=7       and               maintain_time_interval  </lect>

简单封装resultmap返回对象为map

public class dbutils {    private static string host = "47.93.******";    private static string port = "3306";    private static string urname = "*****";    private static string password = "******";    private static string databa = "******";    static {        try {            class.forname("com.mysql.jdbc.driver");        } catch (exception e) {        }    }    private static connection getconn() {        connection conn = null;        try {            string url = "jdbc:mysql://" + host + ":" + port + "/" + databa;            conn = drivermanager.getconnection(url, urname, password);        } catch (exception e) {            e.printstacktrace();        }        return conn;    }    public static list<map<string, object>> execquery(string sql, object[] args) throws exception {        connection conn = getconn();        preparedstatement ps = conn.库存产品preparecall(sql);        resultt rs = null;        int count = stringutils.countmatches(sql, "?");        //变量赋值。。。。。。        for (int i = 0; i < count; i++) {            ps.tobject(i, args[i]);        }        list<map<string, object>> list = new arraylist<map<string, object>>();        rs = ps.executequery();        resulttmetadata metadata = rs.getmetadata();      //注意。。metadata.getcolumnname 获取字段名,rs.getobject 获取属性 是从 1 开始的,而不是从0 开始        while (rs.next()) {            int rowsize = metadata.getcolumncount();            map<string, object> map = new hashmap&l极限推理t;>();            for (int i = 1; i <= rowsize; i++) {                string labelname = metadata.getcolumnname(i);                object obj = rs.getobject(labelname);                map.put(labelname, obj);            }            list.add(map);        }        clo(conn, ps, rs);        ret物管法urn list;    }    /**     * @param conn     * @param ps     * @param rs     * @throws exception     */    private static void clo(connection conn, preparedstatement ps, resultt rs) throws exce冬至祝福语简短ption {     体面歌词   rs.clo();        ps.clo();        conn.clo();    }

以上为个人经验,希望能给大家一个参考,也希望大家多多支持www.887551.com。

本文发布于:2023-04-04 22:21:05,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/5d8941a8536f1a4d8423d431c106545f.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:Mybatis的resultMap返回map问题.doc

本文 PDF 下载地址:Mybatis的resultMap返回map问题.pdf

标签:是从   对象   简单   赋值
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图