增加界面下拉框及增加
代码:
界面效果:
在增加界面增加一个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'
});
})
效果