下拉框加载

增加界面下拉框及增加

代码:
界面效果:

在增加界面增加一个combobox组件,形成动态的下拉框加载

代码

package com.lwm.entity;
public class Category {
    private long id;
    private String name;
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Override
	public String toString() {
		return "Category [id=" + id + ", name=" + name + "]";
	}
	public Category(long id, String name) {
		super();
		this.id = id;
		this.name = name;
	}
	public Category() {
		super();
	}
    
}

dao类

package com.lwm.dao;

import java.util.List;

import com.lwm.entity.Category;
import com.lwm.utils.BaseDao;
import com.lwm.utils.PageBean;


public class CategoryDao extends BaseDao<Category> {
//    查询书籍分类
    public List<Category> list(Category category, PageBean pageBean) throws Exception {
        String sql = "select * from t_easyui_category where true ";
        return super.executeQuery(sql,pageBean,Category.class);
    }
}

Action

package com.lwm.web;

import java.sql.SQLException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lwm.dao.CategoryDao;
import com.lwm.entity.Category;
import com.lwm.util.ResponseUtil;
import com.lwm.framework.ActionSupport;
import com.lwm.framework.ModelDriven;

public class CategoryAction extends ActionSupport implements ModelDriven<Category> {
  private CategoryDao categoryDao =new CategoryDao();
  private Category category =new Category();
@Override
public Category getModel() {
	return category;
}
  


public String combobox(HttpServletRequest req,HttpServletResponse resp) {
	try {
		List<Category> list = this.categoryDao.list(null, null);
		ResponseUtil.writeJson(resp, list);
	} catch (InstantiationException e) {
		e.printStackTrace();
	} catch (IllegalAccessException e) {
		e.printStackTrace();
	} catch (SQLException e) {
		e.printStackTrace();
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
}


js

$(function(){
	var ctx = $("#ctx").val();
	debugger;
	$('#cid').combobox({    
	    url:ctx+'/category.action?methodName=combobox',    
	    valueField:'id',    
	    textField:'name'   
	});  
})

效果
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值