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

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

reply all(1)
PHPzhong

Mybatis’s Mapper file mapping, if the result is a complex object, you need to specify the attribute 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>

Explain some of the attribute values. <resultMap> The result set mapping is stored in the tag. If you are starting from the basics of <resultMap> 标签内存放的是结果集映射,如果是从javaweb基础学起的话,直接接触jdbc,应该对ResultSet这个比较了解,这里的resultMap指定的就是一个数据库字段column 和 你自己建的 pojo/entity 对象的映射关系。其中标签内的id是用来标识resultMap的,就是代码里的BaseResultMap,可以在下方select标签selectByPrimaryKeyresultMap属性中指定,表示使用这个结果集去接收查询到的结果并映射为UserRole对象。resultMap 标签内的id 是主键对应的映射,result 是其他列的映射。column属性是数据库里字段的名称,propertyUserRole对象中对应的属性名称,jdbcType表示的是数据库中该字段的存储类型。下边的没什么难度,有问题还可以再私信我。另外,能用 mybatis-generatorjavaweb and directly contact jdbc

, you should be familiar with 🎜ResultSet🎜. Here is the resultMap specifies the mapping relationship between a database field column and the 🎜pojo/entity🎜 object you created yourself. The id in the tag is used to identify resultMap, which is the BaseResultMap in the code. You can select below Specified in the resultMap attribute of the tag selectByPrimaryKey, indicating that this result set is used to receive the query results and map them to 🎜UserRole🎜 objects. The id in the resultMap tag is the mapping corresponding to the primary key, and result is the mapping of other columns. The column attribute is the name of the field in the database, property is the corresponding attribute name in the UserRole object, represented by jdbcType Is the storage type of this field in the database. The following is not difficult at all. If you have any questions, feel free to message me privately. In addition, if you can use mybatis-generator to generate these files, it is best not to write these basic codes manually, which is prone to errors and omissions. Baidu by yourself🎜mybatis-generator🎜🎜
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template