Mybatis基础问题---resultType=hashmap有何特殊?
首先说明,我这个是springh+mybatis的东西。
我在java里面有一个model包,里面的类叫UserInf,定义如下:
package zxw.model;
public class UserInf {
private Integer userId;
private String userName;
private String userPasswd;
//getter and setter
}
<mapper namespace="zxw.dao.UserInfMapper" >
<!-- public UserInf selectPublicName(String userName); -->
<select id="obtainedPublicName" resultType="zxw.model.UserInf" parameterType="java.lang.String">
select * from userInf where user_name = #{userName,jdbcType=VARCHAR}
</select>
</mapper>
package zxw.dao;
import zxw.model.UserInf;
public interface UserInfMapper {
/**根据名字查询数据*/
UserInf obtainedPublicName(String userName);
}
public static boolean checkUser(String userName , String userPasswd){
UserInfServiceI userInf = (UserInfServiceImpl)CreateBean.beanFactory("userInfService");
System.out.println(userInf.maxId());
UserInf user = userInf.findByName(userName);
System.out.println(user);
if( null == user )
return false ;
return (
! user.getUserName().equals(userName)
||
! user.getUserPasswd().equals(userPasswd)
)
?
false
:
true;
}
<resultMap id="ShopCar" type="com.able.mycu.model.course.ShopCar">
<result property="shopCarId" column="SHOP_CAR_ID" />
<result property="recruitId" column="RECRUIT_ID" />
<result property="number" column="NUMBER" />
<result property="courseId" column="COURSE_ID" />
<result property="mode" column="MODE" />
<result property="importMoney" column="IMPORT_MONEY" />
<result property="courseName" column="COURSE_NAME" />
<result property="isDeleted" column="IS_DELETED" />
<result property="updateAt" column="UPDATE_AT" />
<result property="createAt" column="CREATE_AT" />
</resultMap>
<resultMap id="BaseResultMap" type="cn.caculate.model.CalData" >
<id column="cal_data_id" property="calDataId" jdbcType="INTEGER" />
<result column="prjid" property="prjid" jdbcType="INTEGER" />
<result column="data_file_id" property="dataFileId" jdbcType="INTEGER" />
<result column="data_type" property="dataType" jdbcType="INTEGER" />
</resultMap>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from cal_data
where cal_data_id = #{calDataId,jdbcType=INTEGER}
</select>
<?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="ShopCarMapper">
<sql id="notDeletedSql"> is_deleted = 0 </sql>
<sql id="isDeletedSql"> is_deleted = 1 </sql>
<resultMap id="ShopCar" type="com.able.mycu.model.course.ShopCar">
<result property="shopCarId" column="SHOP_CAR_ID" />
<result property="recruitId" column="RECRUIT_ID" />
<result property="number" column="NUMBER" />
<result property="courseId" column="COURSE_ID" />
<result property="mode" column="MODE" />
<result property="importMoney" column="IMPORT_MONEY" />
<result property="courseName" column="COURSE_NAME" />
<result property="isDeleted" column="IS_DELETED" />
<result property="updateAt" column="UPDATE_AT" />
<result property="createAt" column="CREATE_AT" />
</resultMap>
<select id="getShopCarById" parameterType="int" resultMap="ShopCar">
select * from TBL_SHOP_CAR where shop_car_id = #{shopCarId} and <include refid="notDeletedSql"/>
</select>
<select id="listShopCar" parameterType="com.able.mycu.search.course.ShopCarSearch" resultMap="ShopCar">
select * from TBL_SHOP_CAR where <include refid="notDeletedSql"/>
<!--<if test="shopCarId != null"> and SHOP_CAR_ID = #{shopCarId} </if>-->
<!--<if test="recruitId != null"> and RECRUIT_ID = #{recruitId} </if>-->
<!--<if test="number != null"> and NUMBER = #{number} </if>-->
<!--<if test="courseId != null"> and COURSE_ID = #{courseId} </if>-->
<!--<if test="mode != null"> and MODE = #{mode} </if>-->
<!--<if test="importMoney != null"> and IMPORT_MONEY = #{importMoney} </if>-->
<!--<if test="courseName != null"> and COURSE_NAME like CONCAT('%','${COURSE_NAME}','%') </if>-->
<!--<if test="isDeleted != null"> and IS_DELETED like CONCAT('%','${IS_DELETED}','%') </if>-->
<!--<if test="updateAt != null"> and UPDATE_AT = #{updateAt} </if>-->
<!--<if test="createAt != null"> and CREATE_AT like CONCAT('%','${CREATE_AT}','%') </if>-->
<if test="schoolId != null"> and SCHOOL_ID=#{schoolId} </if>
<if test="userId != null"> and USER_ID=#{userId} </if>
limit #{start},#{limit}
</select>
<select id="countShopCar" parameterType="com.able.mycu.search.course.ShopCarSearch" resultType="int">
select count(1) from TBL_SHOP_CAR where <include refid="notDeletedSql"/>
<!--<if test="shopCarId != null"> and SHOP_CAR_ID = #{shopCarId} </if>-->
<!--<if test="recruitId != null"> and RECRUIT_ID = #{recruitId} </if>-->
<!--<if test="number != null"> and NUMBER = #{number} </if>-->
<!--<if test="courseId != null"> and COURSE_ID = #{courseId} </if>-->
<!--<if test="mode != null"> and MODE = #{mode} </if>-->
<!--<if test="importMoney != null"> and IMPORT_MONEY = #{importMoney} </if>-->
<!--<if test="courseName != null"> and COURSE_NAME like CONCAT('%','${COURSE_NAME}','%') </if>-->
<!--<if test="isDeleted != null"> and IS_DELETED like CONCAT('%','${IS_DELETED}','%') </if>-->
<!--<if test="updateAt != null"> and UPDATE_AT = #{updateAt} </if>-->
<!--<if test="createAt != null"> and CREATE_AT like CONCAT('%','${CREATE_AT}','%') </if>-->
</select>
<select id="listAllShopCar" parameterType="com.able.mycu.search.course.ShopCarSearch" resultMap="ShopCar">
select * from TBL_SHOP_CAR where <include refid="notDeletedSql"/>
<!--<if test="shopCarId != null"> and SHOP_CAR_ID = #{shopCarId} </if>-->
<!--<if test="recruitId != null"> and RECRUIT_ID = #{recruitId} </if>-->
<!--<if test="number != null"> and NUMBER = #{number} </if>-->
<!--<if test="courseId != null"> and COURSE_ID = #{courseId} </if>-->
<!--<if test="mode != null"> and MODE = #{mode} </if>-->
<!--<if test="importMoney != null"> and IMPORT_MONEY = #{importMoney} </if>-->
<!--<if test="courseName != null"> and COURSE_NAME like CONCAT('%','${COURSE_NAME}','%') </if>-->
<!--<if test="isDeleted != null"> and IS_DELETED like CONCAT('%','${IS_DELETED}','%') </if>-->
<!--<if test="updateAt != null"> and UPDATE_AT = #{updateAt} </if>-->
<!--<if test="createAt != null"> and CREATE_AT like CONCAT('%','${CREATE_AT}','%') </if>-->
<if test="schoolId != null"> and SCHOOL_ID=#{schoolId} </if>
<if test="userId != null"> and USER_ID=#{userId} </if>
</select>
<insert id="saveShopCar" parameterType="com.able.mycu.model.course.ShopCar">
insert into TBL_SHOP_CAR (
<if test="recruitId != null"> RECRUIT_ID </if>
<if test="number != null"> ,NUMBER </if>
<if test="courseId != null"> ,COURSE_ID </if>
<if test="mode != null"> ,MODE </if>
<if test="importMoney != null"> ,IMPORT_MONEY </if>
<if test="courseName != null"> ,COURSE_NAME </if>
<if test="isDeleted != null"> ,IS_DELETED </if>
<if test="updateAt != null"> ,UPDATE_AT </if>
<if test="createAt != null"> ,CREATE_AT </if>
<if test="userId != null"> ,USER_ID </if>
<if test="schoolId != null"> ,SCHOOL_ID </if>
)
values (
<if test="recruitId != null"> #{recruitId} </if>
<if test="number != null"> ,#{number} </if>
<if test="courseId != null"> ,#{courseId} </if>
<if test="mode != null"> ,#{mode} </if>
<if test="importMoney != null"> ,#{importMoney} </if>
<if test="courseName != null"> ,#{courseName} </if>
<if test="isDeleted != null"> ,#{isDeleted} </if>
<if test="updateAt != null"> ,#{updateAt} </if>
<if test="createAt != null"> ,#{createAt} </if>
<if test="userId != null"> ,#{userId} </if>
<if test="schoolId != null"> ,#{schoolId} </if>
)
<selectKey resultType="int" order="AFTER" keyProperty="shopCarId">
SELECT LAST_INSERT_ID() AS shop_car_id
</selectKey>
</insert>
<update id="removeShopCarByRecruitId" parameterType="hashmap" >
delete from TBL_SHOP_CAR where RECRUIT_ID = #{recruitId} and USER_ID=#{userId} and schoolId =#{schoolId}
</update>
<update id="updateShopCarById" parameterType="com.able.mycu.model.course.ShopCar">
update TBL_SHOP_CAR set
<!--<if test="shopCarId != null"> ,SHOP_CAR_ID = #{shopCarId} </if>-->
<if test="recruitId != null"> RECRUIT_ID = #{recruitId} </if>--
<if test="number != null"> ,NUMBER = #{number} </if>
<!--<if test="courseId != null"> ,COURSE_ID = #{courseId} </if>-->
<!--<if test="mode != null"> ,MODE = #{mode} </if>-->
<!--<if test="importMoney != null"> ,IMPORT_MONEY = #{importMoney} </if>-->
<!--<if test="courseName != null"> ,COURSE_NAME = #{courseName} </if>-->
<!--<if test="isDeleted != null"> ,IS_DELETED = #{isDeleted} </if>-->
<if test="updateAt != null"> ,UPDATE_AT = #{updateAt} </if>
<!--<if test="createAt != null"> ,CREATE_AT = #{createAt} </if>-->
where RECRUIT_ID = #{recruitId} and USER_ID = #{userId} and SCHOOL_ID = #{schoolId}
</update>
</mapper>