开发工具与关键技术:eclipse,
作者:胖妞妞L
撰写时间:2021年5月18日
先创建一个vo类
import java.io.Serializable;
public class SelectXLKVo{
private Integer id;
private String text;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public SelectXLKVo(Integer id, String text) {
super();
this.id = id;
this.text = text;
}
public SelectXLKVo() {
super();
}
@Override
public String toString() {
return "SelectXLKVo [id=" + id + ", text=" + text + "]";
}[id=" + id + ", text=" + text + "]"==对应的property="id"property="text"
}
<!-- 角色下拉框查询 XML-->在xml里面重写一个方法
<resultMap type="com.gx.vo.SelectXLKVo" id="UserTypeMap">
<result column="UserTypeID" jdbcType="INTEGER" property="id" />
<result column="UserTypeName" jdbcType="VARCHAR" property="text" /></resultMap>
<select id="selectUserType" resultMap="UserTypeMap">SELECT * FROM pw_usertype </select>
/* 下拉框查询 DAO*/在dao接口层写接口方法
public List<SelectXLKVo> findSelect(String ID,String NAME,String TBName);
//角色下拉框查询
List<SelectXLKVo> selectUserType();
//角色下拉框查询控制器 在控制器层写入实现方法
@ResponseBody
@RequestMapping(value = "/selectUserType", produces = "application/json; charset=utf-8")//selectUserType方法名给予页面层调用后面的是编码格式防乱码
private List<SelectXLKVo> selectUserType() {
ArrayList<SelectXLKVo> arrayList = new ArrayList<SelectXLKVo>();
SelectXLKVo vo = new SelectXLKVo(0, "---请选择---");
List<SelectXLKVo> selectvo = UserMapper.selectUserType();
arrayList.add(vo);
arrayList.addAll(selectvo);
return arrayList;
}
//页面层绑定下拉框就一句话给对id给上下拉框的查询方法就可以了如图
<selectname="usertypeid"id="IUserTypeID"></select>
createSelect("IUserTypeID","${ctx}/EmployeeMsgController/selectUserType");
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/0f00260eacd780536f2e1c09164a2db6.png)