JavaBean专题

将整型值转为字符串

2018-08-18  本文已影响0人  神坛下的我

StringUtil6.java

public class StringUtil6 {
    private int intValue=0;
    private String strValue1;
    private String strValue2;
    private String strValue3;
    public StringUtil6(){}
    public int getIntValue() {
        return intValue;
    }
    public void setIntValue(int intValue) {
        this.intValue = intValue;
    }
    public String getStrValue1() {
        return String.valueOf(intValue);
    }
    public void setStrValue1(String strValue1) {
        this.strValue1 = strValue1;
    }
    public String getStrValue2() {
        return Integer.toString(intValue);
    }
    public void setStrValue2(String strValue2) {
        this.strValue2 = strValue2;
    }
    public String getStrValue3() {
        return Integer.valueOf(intValue).toString();
    }
    public void setStrValue3(String strValue3) {
        this.strValue3 = strValue3;
    }
    
}

index.jsp

<body>
    <%
        int userAge=35;
    %>
    <jsp:useBean id="strBean" class="com.count.StringUtil6"></jsp:useBean>
    <jsp:setProperty property="intValue" name="strBean" value="<%=userAge %>"/>
    <table>
        <tr bgcolor="skyblue">
            <td align="center">String.valueOf():</td>
        </tr>
        <tr>
            <td align="center">Age:<jsp:getProperty property="strValue1" name="strBean"/>岁</td>
        </tr>
        <tr bgcolor="skyblue">
            <td align="center">Integer.toString():</td>
        </tr>
        <tr>
            <td align="center">Age:<jsp:getProperty property="strValue2" name="strBean"/>岁</td>
        </tr>
        <tr bgcolor="skyblue">
            <td align="center">Integer.valueOf().toString():</td>
        </tr>
        <tr>
            <td align="center">Age:<jsp:getProperty property="strValue3" name="strBean"/>岁</td>
        </tr>
    </table>
</body>
7.PNG 8.PNG
上一篇下一篇

猜你喜欢

热点阅读