springboot 设置model.addAttribute(dto);HTML页面无法获取值

conttroller code

@Controller
@RequestMapping("/web/member")
public class MerchantWebController {

    @RequestMapping(value = "/update")
    public String update(Model model, Integer id) {
        Merchant merchant = new Merchant();
        merchant.setId(1);
        merchant.setMerchantAccount("2222");
        model.addAttribute(merchant); //直接设置dto
        model.addAttribute("id",id);  //设置单个值
        return "web/member/update";
    }
}

dto code

public class Merchant implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
	@TableId(value="id", type= IdType.AUTO)
	private Integer id;
	
    /**
     * 商家姓名
     */
    @TableField("merchant_name")
	private String merchantName;
	
    /**
     * 商家账号
     */
	@TableField("merchant_account")

	private String merchantAccount;
	
    /**
     * 商家密码
     */
	@TableField("merchant_password")

	private String merchantPassword;
	
    /**
     * 商家经营范围
     */
	@TableField("merchant_scope")

	private String merchantScope;
	
    /**
     * 商家的店铺名称
     */
	@TableField("merchant_shop_name")

	private String merchantshopname;
	


	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getMerchantName() {
		return merchantName;
	}

	public void setMerchantName(String merchantName) {
		this.merchantName = merchantName;
	}

	public String getMerchantAccount() {
		return merchantAccount;
	}

	public void setMerchantAccount(String merchantAccount) {
		this.merchantAccount = merchantAccount;
	}

	public String getMerchantPassword() {
		return merchantPassword;
	}

	public void setMerchantPassword(String merchantPassword) {
		this.merchantPassword = merchantPassword;
	}

	public String getMerchantScope() {
		return merchantScope;
	}

	public void setMerchantScope(String merchantScope) {
		this.merchantScope = merchantScope;
	}

	public String getMerchantshopname() {
		return merchantshopname;
	}

	public void setMerchantshopname(String merchantshopname) {
		this.merchantshopname = merchantshopname;
	}

	@Override
	public String toString() {
		return "Merchant{" +
			", id=" + id +
			", merchantName=" + merchantName +
			", merchantAccount=" + merchantAccount +
			", merchantPassword=" + merchantPassword +
			", merchantScope=" + merchantScope +
			", merchantshopname=" + merchantshopname +
			"}";
	}
}

html 接收例子

dto接收方式 注意加上merchant

         <input type="商家账号" class="form-control" id="merchantAccount"  name="merchantAccount" th:value="${merchant.merchantAccount}">

普通字段

<div class="form-group">
    <label >name</label>
    <input th:value="${id}">
</div>

附 html 循环语句

<h2>用户列表</h2>
<!--说明: th:each="obj,stat:${objects}" 分别代表单个实例,状态(可省略),待遍历对象-->
<div th:each="user:${userList}">
  <input type="hidden" name="userId" th:value="${user.userId}"/>
  用户姓名:<input type="text" name="password" th:value="${user.username}"/>
  登录密码:<input type="text" name="username" th:value="${user.password}"/>
</div>
  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值