06-将整型值转换为字符串(字符串处理)

StringUtil.java

package com.lh.bean;
public class StringUtil {
	// 转换前的int值
	private int intValue = 0;
	// 转换后的字符串1值
	private String strValue1;
	// 转换后的字符串2值
	private String strValue2;
	// 转换后的字符串3值
	private String strValue3;

	// 默认构造方法
	public StringUtil() {
	}

	public String getStrValue1() {
		// 使用String类的valueOf方法转换
		return String.valueOf(intValue);
	}

	public String getStrValue2() {
		// 使用Integer类的toString方法转换
		return Integer.toString(intValue);
	}

	public String getStrValue3() {
		// 使用Integer.valueOf().toString方法
		return Integer.valueOf(intValue).toString();
	}

	public int getIntValue() {
		return intValue;
	}

	public void setIntValue(int intValue) {
		this.intValue = intValue;
	}

	public void setStrValue1(String strValue1) {
		this.strValue1 = strValue1;
	}

	public void setStrValue2(String strValue2) {
		this.strValue2 = strValue2;
	}

	public void setStrValue3(String strValue3) {
		this.strValue3 = strValue3;
	}

}


index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
</head>

<body>
	<%
		int userAge = 35;
	%>
	<!-- 使用useBean动作导入StringUtil类 -->
	<jsp:useBean id="strBean" class="com.lh.bean.StringUtil"></jsp:useBean>
	<!-- 对StringUtil类对象中的IntValue属性赋值 -->
	<jsp:setProperty property="intValue" name="strBean"
		value="<%=userAge %>" />
	<table>
		<tr bgcolor="skyblue">
			<td align="center">使用String.valueOf()方法转换int值:</td>
		</tr>
		<tr>
			<td align="center">
				<!-- 获得StringUtil类对象中的strValue1属性值 --> 年龄1:<jsp:getProperty
					property="strValue1" name="strBean" />岁</td>
		</tr>
		<tr bgcolor="skyblue">
			<td align="center">使用Integer.toString()方法转换int值:</td>
		</tr>
		<tr>
			<td align="center">
				<!-- 获得StringUtil类对象中的strValue2属性值 --> 年龄2:<jsp:getProperty
					property="strValue2" name="strBean" />岁</td>
		</tr>
		<tr bgcolor="skyBlue">
			<td align="center">使用Integer.valueOf().toString()方法转换int值:</td>
		</tr>
		<tr>
			<td align="center">
				<!-- 获得StringUtil类对象中的strValue3属性值 --> 年龄3:<jsp:getProperty
					property="strValue3" name="strBean" />岁</td>
		</tr>
	</table>
</body>
</html>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

会编程的阿强

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值