parameterType是必须写的吗? |
您所在的位置:网站首页 › 必须的必字怎样写 › parameterType是必须写的吗? |
一、parameterType详解
在MyBatis的select、insert、update、delete这些元素中都提到了parameterType这个属性。MyBatis现在可以使用的parameterType有基本数据类型和JAVA复杂数据类型: ① 基本数据类型:包含int,String,Date等。基本数据类型作为传参,只能传入一个。通过#{参数名} 即可获取传入的值 ② 复杂数据类型:包含JAVA实体类、Map。通过#{属性名}或#{map的KeyName}即可获取传入的值
二、parameterType例子 现在有一个Mapper配置文件,以下是片段: select from command a left join command_content b on a.id=b.command_id and a.name=#{command.name} and a.description like '%' #{command.description} '%' group by aid order by id a.id aid,a.name,a.description,b.content,b.id,b.command_id下面是IService接口: /** * 拦截器实现分页 */ public List queryCommandListByPage(Mapparameter);上面的xml中没有配置parameterType,但是这是正确的,因为mybatis能自动识别,但返回值类型不能不写,因为mybatis需要将获得结果封装到相应的类中,查询的字段与类的属性需要一致(不一致的需要显示的配置)。 还有一种情况是参数有多个,数据类型多种,无法确认参数类型。用的是#{index}取值。
以上是鄙人愚见,有不当或补充之处,欢迎指正。 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |