===============
====struts接受参数。参数名不能和 字典类的 类型码 属性dictTypeCode同名。否则接收参数失败。原因不详。===注意。
====【是不是查询所有的实体类信息,查询条件 参数,都不能 和实体类属性名相同?待测。】
========================
add.jsp ajax代码。===回显字典供选择。查询某一类型字典时传参数typeCode
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<TITLE>添加客户</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<LINK href="${pageContext.request.contextPath }/css/Style.css" type=text/css rel=stylesheet>
<LINK href="${pageContext.request.contextPath }/css/Manage.css" type=text/css rel=stylesheet>
<META content="MSHTML 6.00.2900.3492" name=GENERATOR>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript">
// 页面加载函数|匿名函数
$(function(){
// 行业
$.post("${pageContext.request.contextPath }/customerAction_findBaseDictByTypeCode.action",{"typeCode":"001"},function(data){
for (var i = 0; i < data.length; i++) {
$("#custIndustry").append("<option value='"+data[i].dictId+"'>"+data[i].dictName+"</option>");
}
$("#custIndustry option[value=${customer.custIndustry.dictId}]").attr("selected","selected");
},"json");
// ${customer.custIndustry.dictId} 2
// 来源
$.post("${pageContext.request.contextPath }/customerAction_findBaseDictByTypeCode.action",{"typeCode":"002"},function(data){
for (var i = 0; i < data.length; i++) {
$("#custSource").append("<option value='"+data[i].dictId+"'>"+data[i].dictName+"</option>");
}
$("#custSource option[value=${customer.custSource.dictId}]").attr("selected","selected");
},"json");
// 等级
$.post("${pageContext.request.contextPath }/customerAction_findBaseDictByTypeCode.action",{"typeCode":"006"},function(data){
for (var i = 0; i < data.length; i++) {
$("#custLevel").append("<option value='"+data[i].dictId+"'>"+data[i].dictName+"</option>");
}
$("#custLevel option[value=${customer.custLevel.dictId}]").attr("selected","selected");
},"json");
})
</script>
</HEAD>
customerAction:
@Controller
@Scope("prototype")
@ParentPackage("struts-default")
@Namespace("/")
public class CustomerAction extends ActionSupport implements ModelDriven<Customer>{
@Autowired
private CustomerService cs;
@Action(value="customerAction_toadd",results={@Result(name="success",location="/jsp/customer/add.jsp")})
public String toadd() {
return "success";
}
String typeCode;//====struts接受参数。参数名不能和 字典类的类型码 属性dictTypeCode同名。否则接收参数失败。原因不详。===注意。
public void setTypeCode(String typeCode) {
this.typeCode = typeCode;
}
@Action(value="customerAction_findBaseDictByTypeCode")
public void findBaseDictByTypeCode() {
//System.out.println("typeCode:"+typeCode);
List<BaseDict> dicts = cs.findBaseDictByTypeCode(typeCode);
String json = JSON.toJSON(dicts).toString();
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("application/json;charset=utf-8");
//System.out.println(json);
try {
response.getWriter().write(json);
} catch (IOException e) {
e.printStackTrace();
}
}
字典类:
@Entity
@Table(name="base_dict")
public class BaseDict {
@Id
@Column(name="dict_id")
private String dictId;
@Column(name="dict_name")
private String dictName;
@Column(name="dict_type_code")
private String dictTypeCode;//=====这里