美文网首页JavaBean专题
将整型值转为字符串

将整型值转为字符串

作者: 神坛下的我 | 来源:发表于2018-08-18 10:54 被阅读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

相关文章

网友评论

    本文标题:将整型值转为字符串

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