The main research here is to study several ways to transfer ginseng to Mybatis. To sum up, by the way record here.
1. Entity class input parameters
dao method
public void addAdmin(Admin admin);
in mapper
<insert id="addAdmin" parameterType="com.znkj.entity.Admin"> insert into t_admin (a_acount,a_password,a_power,a_name) values(#{a_acount},#{a_password},#{a_power},#{a_name}) </insert>
2. Enter the parameters by subscripting, it should be noted that the subscript of the first parameter is 0
dao method
public List<T_user> queryT_userByPage(String page,String pageSize);
in mapper
<select id="queryT_userByPage" resultMap="ResultMap"> select u_id,u_account,u_password,u_power,u_phone,u_name from t_user limit #{0},#{1} </select>
3. Input parameters through the @param annotation in the dao method
dao method
public int addUserrolemanage(@Param("userid") int userid,@Param("roleid") int roleid);
in mapper
<insert id="addUserrolemanage"> INSERT INTO `userrolemanage` (`user_id`, `role_id`) VALUES (#{userid},#{roleid}) </insert>
4. Enter the parameters through the list collection
dao method
public int insertUserNoticeStatus(@Param("list")List<UserNoticeStatus> list);in mapper
<select id="insertUserNoticeStatus"> insert into usernoticestatus (notice_id,user_id,status) values <foreach collection="list" item="uns"> (#{uns.user_id},#{uns.c_id},#{uns.status}) </foreach> </select>
5. Enter the parameters through the map set
First, the parameters are encapsulated into the map collection, and then passed into the dao method
dao method
public int addAdmin(Map<String, Object> map) ;
in mapper
Basically, there are several ways to enter the parameters, welcome to correct me.
<insert id="addAdmin" parameterType="Map"> insert into t_admin (a_acount,a_password,a_power,a_name) values(#{a_acount},#{a_password},#{a_power},#{a_name}) </insert>
Basically, there are several ways to enter the parameters, welcome to correct me.