乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Mybatis的CRUD

       python_lover 2021-04-24

      1、namespace

      namespace中的包名要和Dao/mapper接口的包名一致!

      2、 select

      選擇,查詢語(yǔ)句;

      • id:就是對(duì)應(yīng)的namespace中的方法名;

      • resultType: Sql語(yǔ)句執(zhí)行的返回類(lèi)型!

      • parameterType:參數(shù)類(lèi)型!

        1.編寫(xiě)接口

      //根據(jù)id查詢用戶
          User getUserById(int id);
      

      ? 2.編寫(xiě)對(duì)應(yīng)的mapper.xml中的sql語(yǔ)句

      <select id="getUserById" parameterType="int" resultType="com.kuang.pojo.User">
              select * from mybatis.user where id = #{id}
      </select>
      

      ? 3.測(cè)試

      @Test
          public void getUserLike(){
      
              SqlSession sqlSession = MybatisUtils.getSqlSession();
      
              UserMapper mapper = sqlSession.getMapper(UserMapper.class);
      
              List<User> userList = mapper.getUserLike("李");
      
              for (User user : userList) {
                  System.out.println(user);
              }
      
              sqlSession.close();
          }
      

      3、Insert

      <!--對(duì)象中的屬性,可以直接取出來(lái)-->
      <insert id="addUser" parameterType="com.kuang.pojo.User">
          insert into mybatis.user (id,name,pwd) values (#{id},#{name},#{pwd});
      </insert>
      

      4、update

      <update id="updateUser" parameterType="com.kuang.pojo.User">
          update mybatis.user set name = #{name},pwd=#{pwd} where id = #{id};
      </update>
      

      5、Delete

      <delete id="deleteUser" parameterType="int">
          delete from mybatis.user where id = #{id};
      </delete>
      

      注意點(diǎn):

      • 增刪改需要提交事務(wù)(sqlSession.commit())

      6、分析增刪改查會(huì)遇到的錯(cuò)誤

      • 標(biāo)簽不要匹配錯(cuò)
      • resource綁定mapper,需要使用路徑
      • 程序配置文件必須符合規(guī)范
      • NullPointerException,沒(méi)有注冊(cè)到資源!
      • 輸出的xml文件中存在中文亂碼問(wèn)題!
      • maven資源沒(méi)有導(dǎo)出問(wèn)題

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類(lèi)似文章 更多