不管我怎么弄,有且只有一条,而且是最后一条。。。
实体类Users中有属性cardId,为主键,是实体类RealEstate的外键,RealState中有1对多关系属性private Users user;
dao接口和映射文件代码:
public interface RealEstateMapper { @MapKey("users") public Map<Users,RealEstate> getReListByUsers(Users users); @MapKey("id") public Map<Integer,RealEstate> getReListById(Integer Id); public Integer insertRes(RealEstate realEstate); public Integer deleteRes(RealEstate realEstate); public Integer updateRes(RealEstate realEstate); }
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="dao.RealEstateMapper"> <select id="getReListById" resultType="RealEstate" parameterType="RealEstate"> select * from real_estate where id=#{id} </select> <select id="getReListByUsers" resultType="RealEstate" parameterType="Users"> select * from real_estate where cardId=#{cardId} </select> <select id="insertRes" parameterType="RealEstate"> insert into real_estate(id,cardId,projectName,address,houseType,area,buildTime) values( #{id},#{cardId},#{projectName},#{address},#{houseType},#{area},#{buildTime} ) </select> <select id="updateRes" parameterType="RealEstate"> update real_estate set cardId=#{cardId},projectName=#{projectName},address=#{address},houseType=#{houseType},area=#{area},buildTime=#{buildTime} where cardId=#{cardId} </select> <select id="deleteRes" parameterType="RealEstate"> delete from real_estate where cardId=#{cardId} or id=#{id} </select> </mapper>
controller中调用了getReListByUsers(users)方法,users对象的cardId属性已赋值,控制台输出语句如下:
[DEBUG] 2017-09-01 20:26:09,375 dao.RealEstateMapper.getReListByUsers - ==> Preparing: select * from real_estate where cardId=?
[DEBUG] 2017-09-01 20:26:09,375 dao.RealEstateMapper.getReListByUsers - ==> Parameters: 123456789123456789(String)
用foreach输出查询到的对象只显示mysql中符合条件的最后一个数据,但是在mysql中能全部查出,参数我试了好几种,结果都一样,求解啊!
精慕门9254224
慕UI9581161