SpringBoot——实现控制器向前端传值
注:代码来自于若依框架—RuoYi-master控制器层核心代码@GetMapping("/edit/{customerId}")public String edit(@PathVariable("customerId") Long customerId, ModelMap mmap){SysCustomer sysCustomer = sysCustomerService.selectSysCu
·
注:代码来自于若依框架—RuoYi-master
控制器层核心代码
@GetMapping("/edit/{customerId}")
public String edit(@PathVariable("customerId") Long customerId, ModelMap mmap)
{
SysCustomer sysCustomer = sysCustomerService.selectSysCustomerByCustomerId(customerId); //根据id查询返回sysCustomer
mmap.put("sysCustomer", sysCustomer);
return prefix + "/edit";
}
实体类:
public class CustomerModel
{
/**
* 客户姓名
*/
private String name;
/**
* 客户手机
*/
private String phonenumber;
/**
* 客户性别
*/
private String sex;
/**
* 客户生日
*/
private String birthday;
/**
* 客户描述
*/
private String remark;
/**
* 商品信息
*/
private List<GoodsModel> goods;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getPhonenumber()
{
return phonenumber;
}
public void setPhonenumber(String phonenumber)
{
this.phonenumber = phonenumber;
}
public String getSex()
{
return sex;
}
public void setSex(String sex)
{
this.sex = sex;
}
public String getBirthday()
{
return birthday;
}
public void setBirthday(String birthday)
{
this.birthday = birthday;
}
public String getRemark()
{
return remark;
}
public void setRemark(String remark)
{
this.remark = remark;
}
public List<GoodsModel> getGoods()
{
return goods;
}
public void setGoods(List<GoodsModel> goods)
{
this.goods = goods;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("name", getName())
.append("phonenumber", getPhonenumber())
.append("sex", getSex())
.append("birthday", getBirthday())
.append("goods", getGoods())
.append("remark", getRemark())
.toString();
}
}
视图层
<form class="form-horizontal m" id="form-customer-edit" th:object="${sysCustomer}">
<input name="customerId" th:field="*{customerId}" type="hidden">
<div class="form-group">
<label class="col-sm-3 control-label">客户姓名:</label>
<div class="col-sm-8">
<input name="customerName" th:field="*{customerName}" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">手机号码:</label>
<div class="col-sm-8">
<input name="phonenumber" th:field="*{phonenumber}" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">客户性别:</label>
<div class="col-sm-8">
<select name="sex" class="form-control m-b" th:with="type=${@dict.getType('sys_customer_sex')}">
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">客户生日:</label>
<div class="col-sm-8">
<div class="input-group date">
<input name="birthday" th:value="${#dates.format(sysCustomer.birthday, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">客户描述:</label>
<div class="col-sm-8">
<textarea name="remark" class="form-control">[[*{remark}]]</textarea>
</div>
</div>
</form>
核心:
前端标签内通过th:object="${sysCustomer}"
接收ModelMap
传来的实体类,然后再th:field="*{customerId}"
标签来获取实体类内的各个属性
更多推荐
已为社区贡献6条内容
所有评论(0)