java - spring-mybatis与sybase any where无法执行SQL
大家讲道理
大家讲道理 2017-04-18 10:40:59
0
1
653
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

Antworte allen(1)
PHPzhong

MybatisMapper文件的映射,如果结果复杂对象需要指定属性resultMap

<mapper namespace="com.pis.entity.UserRoleMapper" >
   <resultMap id="BaseResultMap" type="com.pis.entity.UserRole" >
        <id column="id" property="roleId" jdbcType="INTEGER" />
        <result column="rolename" property="roleName" jdbcType="VARCHAR" />
        <result column="note" property="note" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    roleid, rolename, note
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap"        parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from userrole
    where roleid = #{roleid,jdbcType=INTEGER}
  </select>
</mapper>

解释一下其中的几个属性值。<resultMap> 标签内存放的是结果集映射,如果是从javaweb基础学起的话,直接接触jdbc,应该对ResultSet这个比较了解,这里的resultMap指定的就是一个数据库字段column 和 你自己建的 pojo/entity 对象的映射关系。其中标签内的id是用来标识resultMap的,就是代码里的BaseResultMap,可以在下方select标签selectByPrimaryKeyresultMap属性中指定,表示使用这个结果集去接收查询到的结果并映射为UserRole对象。resultMap 标签内的id 是主键对应的映射,result 是其他列的映射。column属性是数据库里字段的名称,propertyUserRole对象中对应的属性名称,jdbcType表示的是数据库中该字段的存储类型。下边的没什么难度,有问题还可以再私信我。另外,能用 mybatis-generator 生成这些文件就最好不要在手动写这些基础性的代码,容易错误和遗漏。自行百度mybatis-generator

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!