首页 > 其他分享 >登录案例_BeanUtils基本使用与登录案例_BeanUtils介绍

登录案例_BeanUtils基本使用与登录案例_BeanUtils介绍

时间:2023-01-31 17:33:37浏览次数:40  
标签:登录 案例 User new catch import BeanUtils user

登录案例_BeanUtils基本使用 

 

    BeanUtils工具类,简化数据封装

  

 //2.获取所有请求参数
        Map<String, String[]> map = request.getParameterMap();
        //3.创建User对象
        User loginuser = new User();
        //3.2使用BeanUtils封装
        try {
            BeanUtils.populate(loginuser,map);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }

登录案例_BeanUtils介绍

    BeanUtils介绍

       1.用于封装JavaBean的  

          1.JavaBean:标准的java类

            1.要求

              1.类必须被public修饰

              2.必须提供空参的构造器

              3.成员变量必须使用private修饰

              4.提供公共settter和getter方法

              2.功能:封装数据

       2.概念:

           成员变量:

           属性:setter和getter方法截取后的产物

              例如:getUsername()-->  Username -->username

 

        3.方法:

          1.setProperty()

          2.getProperty()

          3.populate:

 

package com.example.test;

import com.example.domain.User;
import org.apache.commons.beanutils.BeanUtils;
import org.junit.Test;

import java.lang.reflect.InvocationTargetException;

public class BeanUtilsTest {

    @Test
    public void test(){


        User user = new User();

        try {
            BeanUtils.setProperty(user,"username","caixukun");
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }

        System.out.println(user);

    }
}

 

 

 

 

    

 

 

 

      

          

 

package com.example.test;


import com.example.domain.User;
import org.apache.commons.beanutils.BeanUtils;
import org.junit.Test;

import java.lang.reflect.InvocationTargetException;

public class BeanUtilsTest {

    @Test
    public void test(){

        User user = new User();

        try {
            BeanUtils.setProperty(user,"hehe","male");
            System.out.println(user);


            String gender = BeanUtils.getProperty(user, "hehe");
            System.out.println(gender);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        }


    }
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

驸马
驸马爷近前看端详
上写着秦香莲她三十二岁
状告当朝驸马郎
欺君王 瞒皇上
悔婚男儿招东床
杀妻灭子良心丧
他逼死韩琪在庙堂
将状纸压至在了某的大堂上
咬紧了牙关你为哪桩

 



package com.example.test;


import com.example.domain.User;
import org.apache.commons.beanutils.BeanUtils;
import org.junit.Test;

import java.lang.reflect.InvocationTargetException;

public class BeanUtilsTest {

@Test
public void test(){

User user = new User();

try {
BeanUtils.setProperty(user,"hehe","male");
System.out.println(user);


String gender = BeanUtils.getProperty(user, "hehe");
System.out.println(gender);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}


}
}

标签:登录,案例,User,new,catch,import,BeanUtils,user
From: https://www.cnblogs.com/x3449/p/17079561.html

相关文章

  • Oracle登录和报错:ORA-12560: TNS: 协议适配器错误
    网络上的解决办法1,查看Oracle的服务是否开启2,查看监听器是否开启3,在注册表中去查看Oracle_sid的值是否有误Oracle_sid的值查看方法::在windows平台如下操作......
  • 登录案例_代码实现1与登录案例_代码实现2
    登录案例_代码实现1开发项目:用户登录开发步骤:1.创建项目,导入html页面,配置文件,jar包2.创建数据库的环......
  • Shell脚本案例
    检查脚本 修复脚本#!/bin/bashCount_passmin=`cat/etc/profile|grep-n^PASS_MIN_DAYS|awk-F[:]'{print$1}'`if["$Count_passmin"];then Num_passmin=1......
  • 名单揭晓!OpenMLDB 获评 2022 年度中国开源社区健康案例
    2023年1月13日,2022年度OSC中国开源项目评选——「2022中国开源社区健康案例」获奖社区正式揭晓!OpenMLDB社区获评2022年度中国开源社区健康案例。OSCHINA(开源中国)......
  • 登录、支付、发布
    我的页面介绍登录-store里准备好tokentoken要放到vuex里,所以来到store/modules/user.js,里面声明一个state里的数据用来存tokenstate(){return{.........
  • Fitter-案例-过滤敏感词汇-分析 Fitter-案例-过滤敏感词汇-代码实现
    Fitter-案例-过滤敏感词汇-分析需求:1.对day17_case案例录入的数据进行敏感词汇过滤2.敏感词汇参考《敏感词汇.txt》3.如果是敏感词汇,替换为** 分......
  • vscode 插件登录 Leetcode
    尝试美区账号:用github登录的,成功;中区账号:昵称密码登录使用电话号码注册的,有密码,但是网页试过密码登录错误。还限制超过两次密码输入错误就限制24小时后才能登录。......
  • IoC和DI入门案例
    IoC思路分析1、管理什么--Service和Dao2、如何将被管理的对象告知IoC容器--配置3、被管理的对象交给IoC容器,如何获取到IoC容器--接口4、IoC容器得到后,如何从容器中......
  • 验证码案例需求分析
    1.访问带有验证码的登录页面login.jsp2.用户输入用户名,密码以及验证码*如果用户名和密码输入有误,跳转登录页面,提示:用户名或密码错误*如果验证码输入有误,跳......
  • 实战案例!1行Python代码识别车牌号码,轻松写一个停车场管理系统,YYDS
    大家好,这里是程序员晚枫。你家停车场的摄像头,是怎么识别出你的车牌的?今天我们一起来看一下~识别车牌识别车牌的代码很简单,只需要1行代码,如下所示。......