Mybatis parameterType 与 resultMap
来源:互联网 发布:mac jenkins 配置文件 编辑:程序博客网 时间:2024/05/28 18:43
一、parameterType传递多个参数
默认情况只能有一个parameterType;parameterType 可以为简单类型(int . String 等),自定义pojo,hashMap...等等如果要分开传多个参数,可以使用pojo,或者hashMap也可以通过注解实现传递多个参数
- mapper接口参数列表有多个,使用注解 param(“”), param中value是什么 , xml中就通过什么取
void insertWithManyParam(@Param("name") String name, @Param("birthday") Date date, @Param("age") int age);
- xml中取值
<insert id="insertWithManyParam"> INSERT user1 SET NAME = #{name},age=#{age},birthday=#{birthday} </insert>
3.单元测试代码
@Test public void testManyParam() { SqlSession sqlSession = sqlSessionFactory.openSession(); UserMapper1 mapper = sqlSession.getMapper(UserMapper1.class); mapper.insertWithManyParam("多个参数传递", new Date(), 48); sqlSession.commit(); sqlSession.close(); }
4.控制台日志
二、resultMap不配置个性映射,默认根据pojo属性名称映射
下面是例子:
1.User类
public class User { private Integer id; private String name; private Integer age; private Date birthday;
2.xml文件配置
<resultMap id="testResultMap" type="user"> <id property="id" column="_id"/> <result property="name" column="_name"/> </resultMap>``<select id="findUserById" parameterType="Integer" resultMap="testResultMap"> SELECT a.id AS _id,a.name AS _name,a.age,a.* FROM ssm.user1 AS a WHERE id=#{id} </select>`User类中还有birthday age属性,resultMap不配置,也可以映射成功;3.测试代码
@Testpublic void testFindById() { SqlSession sqlSession = sqlSessionFactory.openSession(); UserMapper1 mapper = sqlSession.getMapper(UserMapper1.class); User user = mapper.findUserById(3); System.out.println(user); sqlSession.close();}
“`
4.控制台日志
如果查询到的列存在重复字段,mybatis会自动去重
1 0
- Mybatis parameterType 与 resultMap
- MyBatis之输入(parameterType)与输出(resultType、resultMap)映射
- Mybatis输入映射parameterType与输出映射ResultMap是Map类型的解决方案
- MyBatis学习笔记(五)输入(parameterType)与输出(resultType、resultMap)映射
- MyBatis传入参数与parameterType
- MyBatis传入参数与parameterType
- MyBatis传入参数与parameterType
- MyBatis传入参数与parameterType
- MyBatis传入参数与parameterType
- MyBatis传入参数与parameterType
- MyBatis传入参数与parameterType
- MyBatis传入参数与parameterType
- MyBatis传入参数与parameterType
- MyBatis传入参数与parameterType
- MyBatis传入参数与parameterType
- MyBatis传入参数与parameterType
- resultMap与resultType、parameterMap与 parameterType的区别
- resultMap与resultType、parameterMap与 parameterType的区别
- Set up the Virtual switch and Virtual adapter in Windows 2012R2
- Python 机器学习过程小结
- Java7里try-with-resources分析
- $.param()
- Vue.js做todo日常事务任务列表
- Mybatis parameterType 与 resultMap
- oracle 获取自增主键--mybatsi
- ubuntu 查看内存插槽数最大容量和频率
- 详解Laravel依赖注入(DI)和Ioc容器
- eclipse 反编译插件安装步骤
- poj3020-Antenna Placement-最小点覆盖
- session的详情和cookie的不足
- JavaScript详细类型判断
- kickstar自动安装脚本