想要实现界面的一个小功能,下拉框读取数据库信息,显示在街面上,点击所选中的值,存储到数据库中。
下面看下界面效果:
首先介绍下界面jsp代码的实现:
<span style="font-family:KaiTi_GB2312;font-size:18px;"> <div class="formitem">
<div class="f_label">
<span class="red">*</span>用户名称:
</div>
<div class="f_item"></span>
<span style="font-family:KaiTi_GB2312;font-size:18px;"> <!--这里是将从数据库中读取到的数据,显示到界面上--></span>
<span style="font-family:KaiTi_GB2312;font-size:18px;"> <input type="text" id="realname" name="realname" />
<input type="hidden"name="allotuuid" id="allotuuid" />
<input type="hidden" id="userid" name="userid" />
</div>
</div></span>
javascrip实现
<span style="font-family:KaiTi_GB2312;font-size:18px;"> $(function() {
createSelect('realname', {
valueFieldID:"userid",//获取隐藏域id
textField: 'realname',//界面文本框显示的值
selectBoxHeight: 200,
valueField:'userid',url:'${path}/AssetQueryUsername/queryRealname.json',checkbox:false
});</span>
valuefield,相当于获取用户名所对应的id,将其传到后台,进行操作()
Action层
<span style="font-family:KaiTi_GB2312;font-size:18px;">/****
* 查询用户姓名
*
* @author
*
*/
@Controller
@RequestMapping(value = "/AssetQueryUsername")
public class AssetQueryUsernameAction extends BaseAction {
@Autowired
private AssetQueryUsernameService assetQueryUsernameService;
/***
* 查询资产发放人员名称
*/
@RequestMapping(value = "/queryRealname.json", method = {
RequestMethod.GET, RequestMethod.POST })
@ResponseBody
public Object queryRealname(SnUser snUser, HttpServletRequest request) {
List data = (List) assetQueryUsernameService.queryRealname(snUser,
request);
return data;
}
}</span>
Service层
<span style="font-family:KaiTi_GB2312;font-size:18px;">@Service
public class AssetQueryUsernameService extends BaseService<SnUser, String> {
/***
* 查询资产发放人员名称
*
* @param realname
* @param userid
* @param request
* @return
*/
public List queryRealname(SnUser snUser,
HttpServletRequest request) {
String hql = " from SnUser where userlevel='0'";
// 查询用户对象
List<SnUser> listUser = this.listByHql(hql);
// 返回list集合
return listUser;
}
}
</span>
这里用到了SpringMvc技术,后续文章会具体介绍,一个简单的小功能就实现了,动手试试,很简单~
版权声明:本文为hanxintong9原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。