国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

mybatis中Error attempting to get column ‘xx‘ from result set 問題解決

這篇具有很好參考價值的文章主要介紹了mybatis中Error attempting to get column ‘xx‘ from result set 問題解決。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

場景描述

在使用ssm框架寫項目的時候,在構(gòu)建mybatis中發(fā)現(xiàn)報錯;

報錯內(nèi)容(如下):

Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'singerName' from result set. Cause: java.sql.SQLDataException: Cannot convert string '周杰倫' to java.sql.Time value

項目中的實體類:
public class music{

? ? private Integer MucId;

    private String MucName;

    private String singerName;

    private Time MucTime;

    private String MucPath;

    private String MucImg;

? ? public Integer getMucId() {
        return MucId;
    }

    public void setMucId(Integer mucId) {
        MucId = mucId;
    }

    public String getMucName() {
        return MucName;
    }

    public void setMucName(String mucName) {
        MucName = mucName;
    }

    public String getSingerName() {
        return singerName;
    }

    public void setSingerName(String singerName) {
        this.singerName = singerName;
    }

? ? public Time getMucTime() {
        return MucTime;
    }

    public void setMucTime(Time mucTime) {
        MucTime = mucTime;
    }

    public String getMucPath() {
        return MucPath;
    }

    public void setMucPath(String mucPath) {
        MucPath = mucPath;
    }

    public String getMucImg() {
        return MucImg;
    }

    public void setMucImg(String mucImg) {
        MucImg = mucImg;
    }
? ? 
? ?  public music(String mucName, String singerName, Time mucTime, String mucPath, String mucImg) {
        MucName = mucName;
        this.singerName = singerName;
        MucTime = mucTime;
        MucPath = mucPath;
        MucImg = mucImg;
    }

    @Override
    public String toString() {
        return "music{" +
                "MucId=" + MucId +
                ", MucName='" + MucName + '\'' +
                ", singerName='" + singerName + '\'' +
                ", MucTime=" + MucTime +
                ", MucPath='" + MucPath + '\'' +
                ", MucImg='" + MucImg + '\'' +
                '}';
    }
}
Dao層:
public interface MusicAskDao {

    List<music> findAll();
    

    Integer addMusic(music music);

}
Mapper:
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.yohane.dao.MusicAskDao">

    <resultMap id="musicDo" type="com.yohane.pojo.music">
        <id column="id" property="MucId"/>
        <result column="name" property="MucName"/>
        <result column="musicTime" property="MucTime"/>
        <result column="musicPath" property="MucPath"/>
        <result column="musicImg" property="MucImg"/>
    </resultMap>

    <select id="findAll" resultMap="musicDo">
        select * from music_table
    </select>

    <insert id="addMusic" parameterType="com.yohane.pojo.music">
        insert into music_table(name,singerName,musicTime,musicPath,musicImg) values(#{MucName},#{singerName},#{MucTime},#{MucPath},#{MucImg})
    </insert>



</mapper>
test:
 @Test
    public void testMybatis(){

        SqlSession sqlSession = LoadMybatis.getSqlSession();

        MusicAskDao ask = sqlSession.getMapper(MusicAskDao.class);

        List<music> musicList = ask.findAll();

        for (music value:musicList){
            System.out.println(value.toString());
        }

    }
數(shù)據(jù)庫:
mybatis中Error attempting to get column ‘xx‘ from result set 問題解決
問題:

在查詢所有數(shù)據(jù)的時候出現(xiàn)了

Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'singerName' from result set. Cause: java.sql.SQLDataException: Cannot convert string '周杰倫' to java.sql.Time value

報錯

翻譯過來就是:

原因:org.apache.ibatis.executor.result.ResultMapException:嘗試從結(jié)果集中獲取列“singerName”時出錯。原因:java.sql.SQLDataException:無法轉(zhuǎn)換字符串'周杰倫' 到j(luò)ava.sql.Time值

解決方案:

在使用添加Music到數(shù)據(jù)庫中方法使創(chuàng)建了一個有參構(gòu)造函數(shù)(id不包含,因為在數(shù)據(jù)中是自增)。

添加完之后,查詢的時候就發(fā)現(xiàn)了報錯。

原因是有了有參構(gòu)造函數(shù)之后無參構(gòu)造函數(shù)則不存在,添加上后即可解決。

擴展問題:

mybatis實體為什么要提供一個無參的構(gòu)造函數(shù)

Mybatis 會調(diào)用這個默認構(gòu)造函數(shù)來構(gòu)造實例,即實體類需要通過Mybatis進行動態(tài)反射生成。文章來源地址http://www.zghlxwxcb.cn/news/detail-509613.html

到了這里,關(guān)于mybatis中Error attempting to get column ‘xx‘ from result set 問題解決的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 解決Proxy error: Could not proxy request /api/index/webconfig from localhost:8080 to http://www.xx.com

    解決Proxy error: Could not proxy request /api/index/webconfig from localhost:8080 to http://www.xx.com

    報錯信息: Proxy error: Could not proxy request /api/index/webconfig from localhost:8080 to http://www.xxxxxx.com 報錯截圖: 解決辦法: 確保本地跨域配置正常,尤其是rewrite要設(shè)置 / ,否則會不生效; 最后,設(shè)置好之后記得重啟前端先項目,讓代理配置生效。 其他原因分析參考: https://blog.csd

    2024年02月03日
    瀏覽(23)
  • 問題解決記錄=-=[Error response from daemon:Get... http: server gave HTTP response to HTTs client]

    問題: 通過服務(wù)器docker登錄harbor,發(fā)現(xiàn)登陸報錯; Error response from daemon:Get “https:.//.../v2/\\\"\\\": http: server gave HTTP response to HTTs client 或者docker登錄成功,鏡像可以拉下來,但是k8s拉取鏡像時候就會報上述錯誤 原因: harbor默認是https協(xié)議的,如果想要通過http協(xié)議拉取harbor的鏡像需要

    2024年02月09日
    瀏覽(18)
  • 【異常解決】(二)解決docker報錯Error response from daemon: Get... http: server gave HTTP response to HTTPS

    【異常解決】(二)解決docker報錯Error response from daemon: Get... http: server gave HTTP response to HTTPS

    場景:本機個人電腦Windows系統(tǒng)安裝了docker客戶端,遠程Linux服務(wù)器部署了鏡像倉庫,遠程倉庫可以接收別的服務(wù)器的鏡像推送,但接收本機電腦鏡像時失?。▽嶋H為推送失敗)。使用docker login XXXX:XX:XX:XX:8081命令登錄時,報錯 Error response from daemon: Get “https://XXXX:XX:XX:XX:8081/v2

    2024年02月11日
    瀏覽(31)
  • 報錯AttributeError: Attempted to set WANDB to False, but CfgNode is immutable

    報錯AttributeError: Attempted to set WANDB to False, but CfgNode is immutable

    ?今天在跑代碼的時候,使用到了wandb記錄訓(xùn)練數(shù)據(jù)。 ?我在23服務(wù)器上跑的好好的,但將環(huán)境遷移到80服務(wù)器上重新開始跑時,卻遇到了如下報錯 ?看這個報錯信息是由于wandb沒有apis這個屬性,于是我定位到具體的報錯代碼 ???原來程序在import wandb時就拋出異常了。 ?我

    2024年02月08日
    瀏覽(44)
  • maven編譯failed to transfer from http://0.0.0.0/ during a previous attempt.

    報錯如上,核心報錯是:“failed to transfer from http://0.0.0.0/ during a previous attempt.”。 經(jīng)過檢查,發(fā)現(xiàn)https://maven.aliyun.com/nexus/content/groups/public/ 是https頭,而setting.xml配置文件中寫的是http。

    2024年02月12日
    瀏覽(22)
  • GET http://localhost:8080/xx/xx 404 (Not Found) 和Uncaught (in promise) Error: failed報錯的原因

    GET http://localhost:8080/xx/xx 404 (Not Found) 和Uncaught (in promise) Error: failed報錯的原因

    這兩天,我遇見了一個很離譜的錯誤,我找不到原因發(fā)生在哪里,但是知道代理服務(wù)器出錯了,代理了后端給的接口,但是,卻向本地發(fā)起請求,快把我整崩潰了 GET http://localhost:8080/xx/xx 404 (Not Found) 和Uncaught (in promise) Error: failed 開啟代理后,發(fā)起請求,因為后端給的路徑?jīng)]有

    2024年02月07日
    瀏覽(25)
  • 解決Error response from daemon: Get**問題

    解決Error response from daemon: Get**問題

    安裝docker后,使用docker search java時,出現(xiàn)如下問題(最后面是 no such host) 改用中國的docker鏡像倉庫 進入etc/docker目錄下 ls查看目錄下有無daemon.json文件,如果沒有創(chuàng)建一個 輸入 然后保存退出 重啟docker服務(wù) 搜索java鏡像 安裝docker后,使用docker search java時,出現(xiàn)如下問題(最后面是

    2024年02月14日
    瀏覽(18)
  • logstash問題記錄:Attempted to resurrect connection to dead ES instance, but got an error

    logstash問題記錄:Attempted to resurrect connection to dead ES instance, but got an error

    發(fā)現(xiàn)kibana中日志不在更新了,停留在了一個時間點沒有繼續(xù)更新,然后就去檢查各個服務(wù),發(fā)現(xiàn)es、logstash、kibana均正常,不過發(fā)現(xiàn)es里面沒有新日志產(chǎn)生,初步懷疑是logstash沒有成功推送過來日志。 1.檢查logstash日志,logstahs是java開發(fā)的,筆者將日志記錄到了nohup.out文件中 檢查

    2024年02月11日
    瀏覽(18)
  • Access to XMLHttpRequest at ‘http://xx‘ from origin ‘http://xx‘ has been blocked by CORS policy

    Access to XMLHttpRequest at ‘http://xx‘ from origin ‘http://xx‘ has been blocked by CORS policy

    在進行前后端項目聯(lián)調(diào)時,出現(xiàn)跨域問題,就是axios調(diào)用后端接口出現(xiàn)跨域 具體報錯如下,原因是因為瀏覽器的 同源策略 ,會檢查兩個URL地址是否同源(協(xié)議,端口,IP地址是否相同),不同源就會出現(xiàn)跨域問題 針對跨域問題,有很多解決辦法,比如前端配置跨域,后端配

    2024年02月16日
    瀏覽(93)
  • Result window is too large, from + size must be less than or equal to: [10000] but was

    Result window is too large, from + size must be less than or equal to: [10000] but was

    做分頁查詢,當(dāng)分頁達到一定量的時候,報如下錯誤: 原因分析: es對from + size的大小進行限制,必須小于等于10000。 方案一(有風(fēng)險) 將max_result_window參數(shù)閾值調(diào)大,在業(yè)務(wù)中限制分頁大小,使from+size=10000; 具體操作 改法一: 動態(tài)更改索引設(shè)置,為max_result_window參數(shù)賦值足夠

    2024年02月16日
    瀏覽(19)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包