mybatis的查询问题 在线等
以前都是单一的一个表查询 现在有两个表 一个是news表 一个是newstext表
现在news表的newsID是newstext表的主键 要根据newsID=newstextID取newstext的text字段的值 在mybatis里应该怎么配置这两个表 sql语句该怎么写 在线等
------解决方案--------------------mybatis里不就是直接写sql语句吗
select t.text from news s, newstext t where s.newsId = t.newstextId
------解决方案--------------------楼上sql正解,是不是还要返回的问题啊 这个最好定义的实体类中要返回这个t.txt的值,对应你查询出的结果集!!!是不是这个情况!!!
------解决方案--------------------类似情况。
<resultMap id="userResult" type="Usertable">
<id property="id" column="id" />
<result property="no" column="no" />
<result property="realName" column="realName" />
<result property="gender" column="gender" />
<result property="loginName" column="loginName" />
<result property="mobile" column="mobile" />
<result property="comefrom" column="comefrom" />
<result property="address" column="address" />
<result property="disabled" column="disabled" />
<result property="department_name" column="department_name" />
<result property="password" column="PASSWORD"/>
<result property="fax" column="FAX"/>
<result property="tel" column="TEL"/>
<result property="unit" column="unit" />
<result property="email" column="EMAIL"/>
</resultMap>
<select id="getUsers" resultMap="userResult">
SELECT
c.USER_ID AS ID,
c.LOGIN_NAME AS LOGINNAME,
c.REAL_NAME AS REALNAME,
c.PASSWORD,
c.EMAIL,
c.UNREAD_MSG AS UNREADMSG,
c.FAX,
c.TEL,
c.MOBILE,
c.ZIP,
c.COMEFROM,
c.ADDRESS,
c.GENDER,
c.BIRTHDAY,
c.CREATE_TIME,
c.LAST_LOGIN_TIME,
c.LAST_LOGIN_IP AS LASTLOGINIP,
c.CURRENT_LOGIN_TIME AS CURRENTLOGINTIME,
c.CURRENT_LOGIN_IP AS CURRENTLOGINIP,
c.LOGIN_COUNT AS LOGINCOUNT,
t.department_name as department_name,
t.unit as unit ,
c.IS_DISABLED AS DISABLED
FROM core_user c ,t_mp_department t
where c.COMEFROM = t.id
</select>
------解决方案--------------------是这样的,ibatis中的语句该怎么写和正常sql的顺序一样,只不过需要建一个实体包含这两个表的字段即可。参考如下
Java code
<select id="mentEntity.info" parameterClass="com.model.mentEntity" resultClass="com.model.mentEntity">
SELECT
*
FROM ment
WHERE nment_id = #ment_id#
</select>
------解决方案--------------------
你直接定义个实体类让它为你返回的结果类,然后直接在ibatis映射实体类和查询字段的类型关系,最后写你的查询语句在
<select id="pip" parameterClass="java.util.hasmap" resultClass="com.model.实体类就ok">
SELECT
*
FROM newstex ,news
WHERE newsID=newstextID
</select> 这就ok了