05注解

作者: RobertLiu123 | 来源:发表于2019-07-18 16:29 被阅读0次

    注意:相同方法名的注解方式和xml方式只能用一种,xml里不用写对应的statement
    几个注解 @Select @Insert @Update @Delete

    @Select("select * from t_user where user_id = #{user_id}")
    public User selectUserById(int id);
    @Insert("insert into t_user(user_id,user_name,user_pwd,user_email,user_idcard,user_power) values (null,#{user_name},#{user_pwd},#{user_email},#{user_idCard},#{user_power})")
    public int insertUser(User user);
    @Update("update t_user set user_name=#{user_name},user_pwd=#{user_pwd},user_email=#{user_email},user_idcard=#{user_idCard} where user_id=#{user_id}")
    public int updateUser(User user);
    @Delete("delete  from t_user where user_id=#{user_id}")
    public int deleteUser(int id);
    
     @Test
       public void testSelect() throws IOException{
           IUserDao userDao=new UserDaoImpl(factory);
           User u=userDao.selectUserById(1);
           System.out.println(u.getUser_name());
       }
       @Test
       public void testInsert() throws IOException{
           IUserDao userDao=new UserDaoImpl(factory);
           User user=new User();
           user.setUser_name("chenhao");
           user.setUser_pwd("654321");
           user.setUser_power(0);
           user.setUser_email("chenhao.newedu.com");
           user.setUser_idCard("210101200006061234");
           int count=userDao.insertUser(user);
           System.out.println(count);
       }
       @Test
       public void testUpdate() throws IOException{
           IUserDao userDao=new UserDaoImpl(factory);
           User user=new User();
           user.setUser_id(8);
           user.setUser_name("chenhao");
           user.setUser_pwd("123456");
           user.setUser_email("chenhao.newedu.com");
           user.setUser_idCard("210101200006061234");
           int count=userDao.updateUser(user);
           System.out.println(count);
       }
       @Test
       public void testDelete() throws IOException{
           IUserDao userDao=new UserDaoImpl(factory);
           int count=userDao.deleteUserById(9);
           System.out.println(count);
       }
    

    相关文章

      网友评论

          本文标题:05注解

          本文链接:https://www.haomeiwen.com/subject/fdnllctx.html