您的位置:首页 > 其它

mybatis传递多个参数

2017-11-13 16:42 357 查看
通过JavaBean传递多个参数     <select id="selectBlogByBean" parameterType="Blog" resultType="Blog"> select t.ID, t.title, t.content from blog t wheret.title = #{title} and t.content =#{content}         </select>   public void testSelectByBean() {                  SqlSession session = sqlSessionFactory.openSession();                  Blog blog=new Blog();                  blog.setTitle("oracle");                   blog.setContent("使用序列!");                  Blog newBlog = (Blog)session.selectOne("cn.enjoylife.BlogMapper.selectBlogByBean",blog);                 session.close();                  System.out.println("new Blog ID:"+newBlog.getId());         }通过Map传递多个参数Dao层的函数方法
Public
User
selectUser(Map
paramMap);
对应的Mapper.xml
个人认为此方法不够直观,见到接口方法不能直接的知道要传的参数是什么。Dao层的函数方法
Public
User
selectUser(@param(“userName”)Stringname,@param(“userArea”)Stringarea);
[/code]对应的Mapper.xml
[/code]通过{}传递多个参数
DAO层的函数方法
[/code]
 Public
User
selectUser(String
name
,Stringarea);
[/code]
对应的Mapper.xml 
[/code]
[/code]其中,#{0}代表接收的是dao层中的第一个参数,#{1}代表dao层中第二参数,更多参数一致往后加即可。原文:https://www.2cto.com/database/201409/338155.html,https://yq.aliyun.com/articles/67832?spm=5176.8246799.0.0.mAaqch
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: