SSM数据库查询有值,但是到后台某个属性丢失!

现在有一个Blog类(博客类),一个BlogType类(博客类别类),一个查询语句

@Select({"<script>" ,
            "select * from t_blog",
            "<where>",
                "<if test=\"title!=null and title!='' \">",
                    "and title like #{title}",
                "</if>",
                "<if test=\"typeId!=null and typeId!='' \">",
                    "and typeId = #{typeId}",
                "</if>",
                "<if test=\"releaseDateStr!=null and releaseDateStr!='' \">",
                    "and date_format(releaseDate,'%Y年%m月')= #{releaseDateStr}",
                "</if>",
            "</where>",
                "order by releaseDate desc",
            "<if test=\"start!=null and size!=null\">",
                 "limit #{start},#{size}",
            "</if>",
            "</script>"})
    @Results(id="BlogMap", value={
            @Result(column="id", property="id", id=true),
            @Result(column="title", property="title"),
            @Result(column="releaseDate", property="releaseDate",jdbcType= JdbcType.TIMESTAMP),
            @Result(column="clickHit", property="clickHit"),
            @Result(column="summary ", property="summary"),
            @Result(column="replyHit", property="replyHit"),
            @Result(column="content", property="content"),
            @Result(column="keyWord", property="keyWord"),
            @Result(column="typeId", property="blogType", javaType=BlogType.class,
                    one=@One(select="com.blog.dao.BlogTypeDao.findBlogTypeById")),
    })
    public List<Blog> findBlog(Map<String,Object> paramMap);

其中这个博客类中有一个博客类别类的对象。
sql查询结果:

这个sql语句查询结果是有summary的。但是到了后台赋值summary就null了

图片说明

问题不是那个类中的自定义对象,而是这个类的自己的String属性summary赋值失败。

图片说明

如图:BlogType对象是赋值成功的,就是这个summary失败了

下面是Blog和BlogType类

package com.blog.entity;

import java.io.Serializable;
import java.util.Date;

public class Blog implements Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    /**主键*/
    private Integer id;
    /**标题*/
    private String title;
    /**摘要*/
    private String summary;
    /**发表时间*/
    private Date releaseDate;
    /**点击数*/
    private Integer clickHit;
    /**评论数*/
    private Integer replyHit;
    /**内容*/
    private String content;
    /**所属博客类型*/
    private BlogType blogType;
    /**关键字*/
    private String keyWord;

    /**纯文本格式的内容*/
    private String contentNoTag;
    /**发表时间*/
    private String releaseDateStr;
    /**博客数量*/
    private Integer blogCount;

    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public Date getReleaseDate() {
        return releaseDate;
    }
    public void setReleaseDate(Date releaseDate) {
        this.releaseDate = releaseDate;
    }
    public Integer getClickHit() {
        return clickHit;
    }
    public void setClickHit(Integer clickHit) {
        this.clickHit = clickHit;
    }
    public Integer getReplyHit() {
        return replyHit;
    }
    public void setReplyHit(Integer replyHit) {
        this.replyHit = replyHit;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    public BlogType getBlogType() {
        return blogType;
    }
    public void setBlogType(BlogType blogType) {
        this.blogType = blogType;
    }
    public String getKeyWord() {
        return keyWord;
    }
    public void setKeyWord(String keyWord) {
        this.keyWord = keyWord;
    }
    public String getContentNoTag() {
        return contentNoTag;
    }
    public void setContentNoTag(String contentNoTag) {
        this.contentNoTag = contentNoTag;
    }
    public String getReleaseDateStr() {
        return releaseDateStr;
    }
    public void setReleaseDateStr(String releaseDateStr) {
        this.releaseDateStr = releaseDateStr;
    }
    public Integer getBlogCount() {
        return blogCount;
    }
    public void setBlogCount(Integer blogCount) {
        this.blogCount = blogCount;
    }

    public String getSummary() {
        return summary;
    }

    public void setSummary(String summary) {
        this.summary = summary;
    }

    @Override
    public String toString() {
        return "Blog{" +
                "id=" + id +
                ", title='" + title + '\'' +
                ", summary='" + summary + '\'' +
                ", releaseDate=" + releaseDate +
                ", clickHit=" + clickHit +
                ", replyHit=" + replyHit +
                ", content='" + content + '\'' +
                ", blogType=" + blogType +
                ", keyWord='" + keyWord + '\'' +
                ", contentNoTag='" + contentNoTag + '\'' +
                ", releaseDateStr='" + releaseDateStr + '\'' +
                ", blogCount=" + blogCount +
                '}';
    }
}

package com.blog.entity;

import java.io.Serializable;

/**
 * 博客类型
 *
 */
public class BlogType implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    /**主键*/
    private Integer blogtypeid;
    /**类型名称*/
    private String typeName;
    /**序号*/
    private Integer orderNo;
    /**该类型下博客的数量*/
    private Integer blogCount;
    public String getTypeName() {
        return typeName;
    }
    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }
    public Integer getOrderNo() {
        return orderNo;
    }
    public void setOrderNo(Integer orderNo) {
        this.orderNo = orderNo;
    }
    public Integer getBlogCount() {
        return blogCount;
    }
    public void setBlogCount(Integer blogCount) {
        this.blogCount = blogCount;
    }
    public Integer getBlogtypeid() {
        return blogtypeid;
    }
    public void setBlogtypeid(Integer blogtypeid) {
        this.blogtypeid = blogtypeid;
    }

    @Override
    public String toString() {
        return "BlogType{" +
                "blogtypeid=" + blogtypeid +
                ", typeName='" + typeName + '\'' +
                ", orderNo=" + orderNo +
                ", blogCount=" + blogCount +
                '}';
    }
}

求问这个summary为什么不能放进对象里面?

3个回答

SM数据库查询有值,但是到后台某个属性丢失!

weixin_44617722
风情小皮球 就是这个问题,但是怎么解决呢?
大约一年之前 回复

你看看resultType跟resultMap是不是同时存在了。

weixin_44617722
风情小皮球 用的注解,不是xml
大约一年之前 回复

1、打印sql
2、将实体类的参数名换一个试试

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐