Java的Mybatis中xml的传参方式
1.@Param值传递
//mapper int insertBlog(@Param("name") String name,@Param("age") int age); //xml <insert id="insertBlog"> insert into blog(name,age) values(#{name},#{age}); </insert>
2.对象传值
//mapper int insertBlog(Blog blog); //xml <insert id="insertBlog" parameterType="com.example.entity.Blog"> insert into blog(name,age) values(#{name},#{age}); </insert> //service Blog blog=new Blog(); blog.setAge(13); blog.setName("zzl3"); blogMapper.insertBlog(blog);
3.map传值
//mapper int insertBlog(Map<String,Object> map); //xml <insert id="insertBlog" parameterType="map"> insert into blog(name,age) values(#{name},#{age}); </insert> //service Map<String,Object> map = new HashMap<>(); map.put("name","zzl4"); map.put("age",14); blogMapper.insertBlog(map);