mybatis 参数及mybatis返回类型汇总

1、增加

<insert id="insertUserAddress" parameterType="com.api.entity.Address">
		INSERT INTO ADDRESS (ID, RECEIVER, PHONE, PROVINCE, CITY, ADDRESS, ISDEFAULT, ENTER_DATE) 
		VALUES
		(#{userId},#{receiver},#{telphone},#{province},#{city},#{street},#{isDefault},getdate())
	</insert>

2、删除

<delete id="delAddressByUserId" parameterType="map">
		delete from ADDRESS where ID = #{userId} and ROWID = #{rowId}
	</delete>
3、更新
<update id="setAddressDefault" parameterType="string">
		update ADDRESS set ISDEFAULT = 0 where ID = #{userId}
	</update>

4、查询

4.1查询输入参数为string,返回值类型为映射的类

<select id="getUserAdress" parameterType="string"  resultMap="addressResultMap">
		select ID, RECEIVER, PHONE, PROVINCE, CITY, ADDRESS, ISDEFAULT from OS_ADDRESS where ID = #{userId}
	</select>

4.2 查询输入参数为string,返回值map

<select id="listCateGoryNum" parameterType="string" resultType="map">
		select category,num from ORDER_V where id = #{userId}
	</select>

4.3查询输入参数为string,返回string

<select id="getCodeByCodeId" parameterType="string" resultType="string">
		select CODE_VALUE from CODE where CODE_ID=#{codeId}
	</select>

4.4查询输入参数为类,返回string

<select id="getHoustList" parameterType="com.entity.HousePage" resultMap="houseMap"> </select >

4.5查询输入参数为map,返回类

<select id="getHostHouse" parameterType="map"  resultMap="houseMap"></select>

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MyBatis是一种使用XML或注解与数据库进行交互的Java持久层框架。在MyBatis中,各种SQL指令和参数都需要绑定到Java对象上,使用不同的参数类型可以使我们更轻松地操作数据库。 在MyBatis中,参数类型包括基本数据类型、包装类、Java Bean、Map和注解@Param等几种。 1. 基本数据类型和包装类:例如int、double、float等基本类型以及它们对应的包装类型Integer、Double、Float等都可以作为参数类型。在SQL语句中,我们使用#{}或${}占位符来代替这些参数。 2. Java Bean:我们也可以将自己封装的Java类作为参数传递给MyBatis的SQL语句。在这种情况下,可以使用“.”符号将属性名连接在一起进行映射。例如: ```java public class User { private int id; private String name; private int age; //getter和setter } <select id="getUserById" resultType="com.example.User"> select * from user where user_id = #{id} </select> ``` 3. Map类型MyBatis中也可以使用Map类型来传递参数。使用Map类型的好处是我们可以灵活地在程序中添加或删除参数。例如: ```java <select id="getUserById" resultType="com.example.User"> select * from user where user_id = #{map.userId} </select> ``` 4. 注解@Param:使用@Param注解可以给SQL语句中的参数指定一个名称,使我们更加方便地调用。例如: ```java @Select("select * from user where user_name = #{name}") User getUserByName(@Param("name") String name); ``` 总之,在使用MyBatis框架的时候,我们要根据实际情况选择不同的参数类型,在这些参数类型中进行转化操作,方便我们与数据库进行交互。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值