thymeleaf输入框中内容显示在输入框外

问题

运行SpringMVC+Mybatis项目,thymeleaf输入框中文字显示在输入框外

详细问题

相关代码

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>服装信息更新</title>
</head>
<body>

<form th:action="@{/clothing_info/updated}" method="post">
    <input type="hidden" name="_method" value="put">
    <table style="margin: auto">
        <tr>
            <td>商品 ID:</td>
            <td><input type="text" name="id" th:value="${clothingInfo.getId()}" readonly></td>
        </tr>

        <tr>
            <td>名称:</td>
            <td><input type="text" name="name" th:value="${clothingInfo.getName()}" required></td>
        </tr>
        <tr>
            <td>分类:</td>
            <td><input type="text" name="classification" th:value="${clothingInfo.getClassification()}" required></td>
        </tr>
        <tr>
            <td>是否上架:</td>
            <td><input type="text" name="listing" th:value="${clothingInfo.getListing()}" required></td>
        </tr>
        <tr>
            <td>价格:</td>
            <td><input type="value" name="price" th:text="${clothingInfo.getPrice()}" required></td>
        </tr>
        <tr>
            <td>优惠内容:</td>
            <td><input type="text" name="offerContent" th:value="${clothingInfo.getOfferContent()}" required></td>
        </tr>
        <tr>
            <td>是否包邮:</td>
            <td><input type="text" name="freeShipping" th:value="${clothingInfo.getFreeShipping()}" required></td>
        </tr>
        <tr>
            <td>参数内容:</td>
            <td><input type="text" name="parameter" th:value="${clothingInfo.getParameter()}" required></td>
        </tr>
        <tr>
            <td>颜色:</td>
            <td><input type="text" name="colour" th:text="${clothingInfo.getColour()}" required></td>
        </tr>
        <tr>
            <td>尺码:</td>
            <td><input type="text" name="size" th:value="${clothingInfo.getSize()}" required></td>
        </tr>
        <tr>
            <td>评价情况:</td>
            <td><textarea name="evaluation" rows="10" cols="30" th:text="${clothingInfo.getEvaluation()}" />
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center"><input type="submit" value="修改商品信息"></td>
        </tr>
    </table>
</form>
</body>
</html>

请添加图片描述

解决方案

<tr>
    <td>价格:</td>
    <td><input type="value" name="price" th:text="${clothingInfo.getPrice()}" required></td>
</tr>

修改为

<tr>
    <td>价格:</td>
    <td><input type="value" name="price" th:value="${clothingInfo.getPrice()}" required></td>
</tr>

错误原因

在这里,使用了th:text属性来设置输入框的文本值,但是这个属性会将文本显示在输入框之外。正确的属性应该是th:value,这样文本就会显示在输入框内部了。

参考文献

chatgpt问答

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

飞滕人生TYF

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

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

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

打赏作者

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

抵扣说明:

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

余额充值