<select id="querySections" resultMap="resultListPerformanceBaseData">
select distinct(Section) from tableName
</select>
查询实体类的某一个字段,返回的是实体类的集合,其中实体类只有被查询的字段的有值;
List<实体类名>
取值:对象get查询字段名
mybatis的sql和你在数据库客户端执行的sql是一样的,但是在mybatis中调用的sql一般都是动态的,所以用到了参数传递。这个mybatis有对应的标签以及相应的变量来实现。你可以搜索下mybatis标签。同时给你一个参考的你看看,这个是一个查询用户的
<select id="queryUsers" parameterType="map" resultType="xxxxxxbeanUserBean">
<![CDATA[
select
ID,
LOGIN_NAME AS loginName,
PASSWORD,
REAL_NAME AS realName,
POSITION,
(SELECT DPOSITION_NAME FROM UNIT_POSITION D WHERE DPOSITION_CODE=TPOSITION) POSITIONNAME,
USER_TYPE AS userType,
SEX,
PID,
TO_CHAR(TBIRTHDAY,'YYYY-MM-DD') BIRTHDAY,
EMAIL,
CONTACT_TEL AS contactTel,
CONTACT_MOBILE AS contactMobile,
CONTACT_FAX AS contactFax,
CONTACT_ZIP AS contactZip,
CONTACT_ADDR AS contactAddr,
STATUS,
EDUCATION,
(SELECT DEDUCATION_NAME FROM UNIT_EDUCATION D WHERE DEDUCATION_CODE=TEDUCATION AND DSTATUS=0) EDUCATIONNAME,
NATION,
POLITICAL,
REMARK,
TO_CHAR(TCREATE_DATE,'YYYY-MM-DD HH24:MI:SS') createDate,
(SELECT DREAL_NAME FROM UNIT_USER D WHERE DID= TCREATE_USER_ID) createUserId,
TO_CHAR(TUPDATE_DATE,'YYYY-MM-DD HH24:MI:SS') updateDate,
(SELECT DREAL_NAME FROM UNIT_USER D WHERE DID= TUPDATE_USER_ID) updateUserId
from UNIT_USER T
]]>
<where>
TSTATUS='1'
<if test="realName !=null and realName !=''">
and TREAL_NAME like '%${realName}%'
</if>
<if test="nexusDpartment !=null">
AND TID IN (SELECT DISTINCT DUSER_ID FROM UNIT_USER_DEPT D WHERE DDEPT_CODE IN (${nexusDpartment}))
</if>
<if test="deptCode !=null and deptCode !=''">
AND TID IN (SELECT DISTINCT DUSER_ID FROM UNIT_USER_DEPT D WHERE DDEPT_CODE = #{deptCode})
</if>
</where>
<if test="sort != null and sort != ''">
order by ${sort}
<if test="direction != null and direction != ''">
${direction}
</if>
</if>
</select>
自定义一个TypeHander继承FloatTypeHandler,例子
public class TwoDecimalFloatTypeHander extends FloatTypeHandler{
@Override
public void setNonNullParameter(PreparedStatement ps, int i, Float parameter, JdbcType jdbcType)
throws SQLException {
pssetFloat(i, parameter);
}
以上就是关于mybatis 查询数据库返回值某字段是 List 该怎么搞全部的内容,包括:mybatis 查询数据库返回值某字段是 List 该怎么搞、mybatis根据价格区间查物品sql怎么写、oracle数据库中是两位小数mybatis查出来怎么办等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)