menu ==> list.jsp
导入模板后修改
·添加菜单属性
·添加记录
function add(){
var validate = $("#add-form").form("validate");
if(!validate){
$.messager.alert("消息提醒","请检查你输入的数据!","warning");
return;
}
var data = $("#add-form").serialize();
$.ajax({
url:'../admin/menu/add',
dataType:'json',
type:'post',
data:data,
success:function(data){
if(data.type == 'success'){
$.messager.alert('信息提示','添加成功!','info');
$('#add-dialog').dialog('close');
}else{
$.messager.alert('信息提示',data.msg,'warning');
}
}
});
}
2.框架
·实体
private int id;
private int parentId; //父类id
private String name;//菜单名称
private String url;//点击后的url
private String icon;//图标
·Controller编写
@Controller
@RequestMapping("/admin/menu")
public class MenuController {
@Autowired
private MenuService menuService;
/**
* 菜单管理列表页
* @param model
* @return
*/
@RequestMapping(value = "/list",method = RequestMethod.GET)
public ModelAndView list(ModelAndView model) {
model.setViewName("menu/list");
return model;
}
/**
* 菜单添加
* @param menu
* @return
*/
@RequestMapping(value = "/add",method = RequestMethod.POST)
@ResponseBody
public Map add(Menu menu){
Map ret = new HashMap();
if(menu == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的菜单信息!");
return ret;
}
if(StringUtils.isNullOrEmpty(menu.getName())){
ret.put("type", "error");
ret.put("msg", "请填写菜单名称!");
return ret;
}
if(StringUtils.isNullOrEmpty(menu.getIcon())){
ret.put("type", "error");
ret.put("msg", "请填写菜单图标类!");
return ret;
}
if(menu.getParentId() == null){
menu.setParentId(1l);
}
if(menuService.add(menu) <= 0){
ret.put("type", "error");
ret.put("msg", "添加失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "添加成功!");
return ret;
}
·Service
@Service
public interface MenuService {
public int add(Menu menu);
}
dao
@Repository
public interface MenuDao {
public int add(Menu menu);
}
·serviceImpl
@Service
public class MenuServiceImpl implements MenuService {
@Autowired
private MenuDao menuDao;
@Override
public int add(Menu menu) {
// TODO Auto-generated method stub
return menuDao.add(menu);
}
}