作者: kent鹏

转载请注明出处: http://www.cnblogs.com/xieyupeng/p/7145599.html

一、新增客户

  1.数据字典

   用于枚举项目中有限个数的字典项

   (1)表中数据字典与其他表的关系:

   

   

   建表语句:

CREATE TABLE `base_dict` (
`dict_id` varchar(32) NOT NULL COMMENT '数据字典id(主键)',
`dict_type_code` varchar(10) NOT NULL COMMENT '数据字典类别代码',
`dict_type_name` varchar(64) NOT NULL COMMENT '数据字典类别名称',
`dict_item_name` varchar(64) NOT NULL COMMENT '数据字典项目名称',
`dict_item_code` varchar(10) DEFAULT NULL COMMENT '数据字典项目(可为空)',
`dict_sort` int(10) DEFAULT NULL COMMENT '排序字段',
`dict_enable` char(1) NOT NULL COMMENT '1:使用 0:停用',
`dict_memo` varchar(64) DEFAULT NULL COMMENT '备注',
PRIMARY KEY (`dict_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

   (2)映射文件配置

   客户实体中引用数据字典对象:

    //引用关联的数据字典对象
private BaseDict cust_source; //客户来源 cust_source.dict_id
private BaseDict cust_industry; //客户行业
private BaseDict cust_level; //客户级别

   将数据字典对象在映射文件中配置:

        <!-- 多对一 -->
<many-to-one name="cust_source" column="cust_source" class="BaseDict" ></many-to-one>
<many-to-one name="cust_industry" column="cust_industry" class="BaseDict" ></many-to-one>
<many-to-one name="cust_level" column="cust_level" class="BaseDict" ></many-to-one>

  2.使用ajax技术在页面加载字典下拉选

//使用ajax加载数据字典,生成select
//参数1: 数据字典类型 (dict_type_code)
//参数2: 将下拉选放入的标签id
//参数3: 生成下拉选时,select标签的name属性值
//参数4: 需要回显时,选中哪个option
function loadSelect(typecode,positionId,selectname,selectedId){
//1 创建select对象,将name属性指定
var $select = $("<select name="+selectname+" ></select>");
//2 添加提示选项
$select.append($("<option value='' >---请选择---</option>"));
//3 使用jquery 的ajax 方法,访问后台Action
$.post("${pageContext.request.contextPath}/BaseDictAction", { dict_type_code:typecode},
function(data){
//遍历
//4 返回json数组对象,对其遍历
$.each( data, function(i, json){
// 每次遍历创建一个option对象
var $option = $("<option value='"+json['dict_id']+"' >"+json["dict_item_name"]+"</option>"); if(json['dict_id'] == selectedId){
//判断是否需要回显 ,如果需要使其被选中
$option.attr("selected","selected");
}
//并添加到select对象
$select.append($option);
});
},"json"); //5 将组装好的select对象放入页面指定位置
$("#"+positionId).append($select);
}

   add.jsp

$(document).ready(function(){
loadSelect("006","level","cust_level.dict_id");
loadSelect("001","industry","cust_industry.dict_id");
loadSelect("009","source","cust_source.dict_id");
});
</script>

   BaseDictAction:

public class BaseDictAction extends ActionSupport {

    private String dict_type_code;

    private BaseDictService baseDictService;
@Override
public String execute() throws Exception {
//1 调用Service根据typecode获得数据字典对象list
List<BaseDict> list = baseDictService.getListByTypeCode(dict_type_code);
//2 将list转换为 json格式
String json = JSONArray.fromObject(list).toString();
//3 将json发送给浏览器
ServletActionContext.getResponse().setContentType("application/json;charset=utf-8");
ServletActionContext.getResponse().getWriter().write(json);
return null;//告诉struts2不需要进行结果处理
} public String getDict_type_code() {
return dict_type_code;
}
public void setDict_type_code(String dict_type_code) {
this.dict_type_code = dict_type_code;
} public void setBaseDictService(BaseDictService baseDictService) {
this.baseDictService = baseDictService;
}
}

   BaseDictServiceImpl:

public class BaseDictServiceImpl implements BaseDictService {

    private BaseDictDao bdd;

    @Override
public List<BaseDict> getListByTypeCode(String dict_type_code) {
return bdd.getListByTypeCode(dict_type_code);
} public void setBdd(BaseDictDao bdd) {
this.bdd = bdd;
}
}

   BaseDictDaoImpl:

public class BaseDictDaoImpl extends BaseDaoImpl<BaseDict> implements BaseDictDao {

    @Override
public List<BaseDict> getListByTypeCode(String dict_type_code) {
//Criteria //创建离线查询对象
DetachedCriteria dc = DetachedCriteria.forClass(BaseDict.class);
//封装条件
dc.add(Restrictions.eq("dict_type_code", dict_type_code));
//执行查询
List<BaseDict> list = (List<BaseDict>) getHibernateTemplate().findByCriteria(dc); return list;
}
}

  struts.xml

        <!-- 数据字典Action -->
<action name="BaseDictAction" class="baseDictAction" method="execute" ></action>

   applicationContext.xml

    <bean name="baseDictAction" class="cn.xyp.web.action.BaseDictAction" scope="prototype" >
<property name="baseDictService" ref="baseDictService" ></property>
</bean> <bean name="baseDictService" class="cn.xyp.service.impl.BaseDictServiceImpl" >
<property name="bdd" ref="baseDictDao" ></property>
</bean> </bean>
<bean name="baseDictDao" class="cn.xyp.dao.impl.BaseDictDaoImpl" >
<!-- 注入sessionFactory -->
<property name="sessionFactory" ref="sessionFactory" ></property>
</bean>

  3.分析实现新增客户

   

二、在新增客户中加入文件上传

  1.文件上传页面3个要求

    <!-- 文件上传页面3个要求:
1.表单必须post提交
2.表单提交类型enctype.必须多段式.
3.文件上传使用<input type="file" /> 组件
-->
<FORM id=form1 name=form1
action="${pageContext.request.contextPath }/CustomerAction_add"
method="post" enctype="multipart/form-data" >

  2.后台接收(记得生成getset方法)

    //上传的文件会自动封装到File对象
//在后台提供一个与前台input type=file组件 name相同的属性
private File photo;
//在提交键名后加上固定后缀FileName,文件名称会自动封装到属性中
private String photoFileName;
//在提交键名后加上固定后缀ContentType,文件MIME类型会自动封装到属性中
private String photoContentType;

   使用:

    public String add() throws Exception {
if(photo!=null){
System.out.println("文件名称:"+photoFileName);
System.out.println("文件类型:"+photoContentType);
//将上传文件保存到指定位置
photo.renameTo(new File("E:/upload/haha.jpg"));
}

三、客户修改

   

JAVAEE——SSH项目实战03:新增客户、数据字典、文件上传和修改客户的更多相关文章

  1. 【SSH网上商城项目实战13】Struts2实现文件上传功能

    转自:https://blog.csdn.net/eson_15/article/details/51366384 上一节我们做完了添加和更新商品的功能,这两个部分里有涉及到商品图片的上传,并没有详细 ...

  2. .net core 3.0web_razor page项目_使用中间件接受大文件上传报错_httpRequest.Form threw an exception of type Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException_Request body too large

    前言:在web项目的.net framework时文件上传时,自己常用一般处理程序接受上传文件,上传文件的大小限制是可以项目的webconfig里配置.   到core项目使用一般处理程序变成了中间件 ...

  3. 【PHP项目】产品新增的多图上传

    产品新增:多图上传 1:html的更改 在 type=file的input框中添加multiple="multiple" name属性中必须添加[] ,否则$_FILES只能接收最 ...

  4. JavaEE系列之(二)commons-fileupload实现文件上传、下载

    一.文件上传概述     实现Web开发中的文件上传功能,需要两步操作:     1.在Web页面中添加上传输入项 <form action="#" method=" ...

  5. SpringMVC案例3----spring3.0项目拦截器、ajax、文件上传应用

    依然是项目结构图和所需jar包图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYmVuamFtaW5fd2h4/font/5a6L5L2T/fontsi ...

  6. 在 .NET Core项目中使用UEditor图片、文件上传服务

    在.NET Framework中使用UEditor时,只需要将UEditor提供的后端服务,部署为一个子程序,即可直接使用文件上传相关的服务,但是UEditor官方并未提供.Net Core的项目,并 ...

  7. 在express项目中使用formidable & multiparty实现文件上传

    安装 formidable,multiparty 模块 npm install formidable,multiparty –save -d 表单上传 <form id="addFor ...

  8. 讲解开源项目:功能强大的 JS 文件上传库

    本文作者:HelloGitHub-kalifun HelloGitHub 的<讲解开源项目>系列,项目地址:https://github.com/HelloGitHub-Team/Arti ...

  9. 测试开发实战[提测平台]17-Flask&Vue文件上传实现

    微信搜索[大奇测试开],关注这个坚持分享测试开发干货的家伙. 先回顾下在此系列第8次分享给出的预期实现的产品原型和需求说明,如下图整体上和前两节实现很相似,只不过一般测试报告要写的内容可能比较多,就多 ...

随机推荐

  1. Nginx配置location及rewrite规则

    Nginx配置location及rewrite规则 示例: location  = / {   # 精确匹配 / ,主机名后面不能带任何字符串   [ configuration A ] } loca ...

  2. 13、Math类简介

    Math类概述 在java.lang包下,有个Math类,这个类包含用于执行基本数学运算的方法,如四舍五入,开方等等. package com.sutaoyu.usually_class; publi ...

  3. 树形dp(B - Computer HDU - 2196 )

    题目链接:https://cn.vjudge.net/contest/277955#problem/B 题目大意:首先输入n代表有n个电脑,然后再输入n-1行,每一行输入两个数,t1,t2.代表第(i ...

  4. VC++ 编译libcurl 支持SSL,GZIP

    由于网上下载的 libcurl 不支持 gzip,只好自己动手编译,期间走了很多弯路,下面是最终成功的记录. 我所使用的环境 Visual Studio 2010 . Windows 7 64 bit ...

  5. Django BoundField

    一.BoundField from django.forms.boundfield import BoundField BoundField是一个将字段添加数据的一个类,给对应的form字段封装上数据 ...

  6. orcale数据库分配用户

    account lock:创建用户的时候锁定用户 account unlock:创建用户的时候解锁用户,默认该选项 create user zhou8–用户名 identified by zhou88 ...

  7. springboot配置fastjson后端往前端传输格式化

    import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.Spri ...

  8. 用sklearn计算卡方检验P值

    情形: 1. 对于一批分类变量,我们通常要评价两两之间的相关程度. 2. 因变量是分类变量,衡量其他分类变量和因变量的相关性高低. 来源:https://blog.csdn.net/snowdropt ...

  9. vue项目中,Iview打包到生产环境时, woff 字体引用问题

    出现这问题的原因是文件路径不对,与webpack有关,解决的办法为: 一.修改webpack.prod.conf.js module: { rules: utils.styleLoaders({ so ...

  10. html5拖拽初窥

    说到拖动,大概有两种方式,一种是js实现,之前已经介绍过,今天来讲解另外一种方式,那就是使用html5实现拖动. css样式 .box { width: 200px; height: 200px; b ...