Table of Contents
1. New customers
 1. Data dictionary
  (1) The relationship between the data dictionary in the table and other tables:
(2) Mapping file configuration
2. Use ajax technology to load the dictionary drop-down selection on the page
3. Analysis Achieve new customers
 1. Three requirements for the file upload page
    //上传的文件会自动封装到File对象//在后台提供一个与前台input type=file组件 name相同的属性private File photo;//在提交键名后加上固定后缀FileName,文件名称会自动封装到属性中private String photoFileName;//在提交键名后加上固定后缀ContentType,文件MIME类型会自动封装到属性中 private String photoContentType;
Copy after login
" >
    //上传的文件会自动封装到File对象//在后台提供一个与前台input type=file组件 name相同的属性private File photo;//在提交键名后加上固定后缀FileName,文件名称会自动封装到属性中private String photoFileName;//在提交键名后加上固定后缀ContentType,文件MIME类型会自动封装到属性中 private String photoContentType;
Copy after login
 
Home Java javaTutorial JAVAEE new customers, data dictionary, file upload and modify customer explanation

JAVAEE new customers, data dictionary, file upload and modify customer explanation

Jul 22, 2017 pm 02:45 PM
javaee client New

Author: kentpeng

Please indicate the source for reprinting:

1. New customers

 1. Data dictionary

Used for enumeration A limited number of dictionary items in the project

  (1) The relationship between the data dictionary in the table and other tables:

 

 

Table creation statement:

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;
Copy after login

(2) Mapping file configuration

Reference data dictionary object in customer entity:

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

Configure the data dictionary object in the mapping file:

        <!-- 多对一 --><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>
Copy after login

2. Use ajax technology to load the dictionary drop-down selection on the page

//使用ajax加载数据字典,生成select//参数1: 数据字典类型 (dict_type_code)//参数2: 将下拉选放入的标签id//参数3: 生成下拉选时,select标签的name属性值//参数4: 需要回显时,选中哪个optionfunction loadSelect(typecode,positionId,selectname,selectedId){//1 创建select对象,将name属性指定var $select =  $("<select name="+selectname+" ></select>");//2 添加提示选项$select.append($("<option value=&#39;&#39; >---请选择---</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=&#39;"+json[&#39;dict_id&#39;]+"&#39; >"+json["dict_item_name"]+"</option>"); 
                   if(json['dict_id'] == selectedId){//判断是否需要回显 ,如果需要使其被选中$option.attr("selected","selected");
            }//并添加到select对象                $select.append($option);
               });
      },"json");        //5 将组装好的select对象放入页面指定位置$("#"+positionId).append($select);
}
Copy after login

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>
Copy after login

BaseDictAction:

public class BaseDictAction extends ActionSupport {private String dict_type_code;    private BaseDictService baseDictService;
    @Overridepublic String execute() throws Exception {//1 调用Service根据typecode获得数据字典对象listList<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;
    }
}
Copy after login

BaseDictServiceImpl:

public class BaseDictServiceImpl implements BaseDictService {    private BaseDictDao bdd;
    
    @Overridepublic List<BaseDict> getListByTypeCode(String dict_type_code) {return bdd.getListByTypeCode(dict_type_code);
    }public void setBdd(BaseDictDao bdd) {this.bdd = bdd;
    }
}
Copy after login

BaseDictDaoImpl:

public class BaseDictDaoImpl extends BaseDaoImpl<BaseDict> implements BaseDictDao {

    @Overridepublic 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;
    }
}
Copy after login

struts.xml

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

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>
Copy after login

3. Analysis Achieve new customers

 

2. Add file upload to new customers

 1. Three requirements for the file upload page

    <!-- 文件上传页面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" >
Copy after login

2. Background reception (remember to generate the getset method)

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

Use:

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

3. Customer modification

 

The above is the detailed content of JAVAEE new customers, data dictionary, file upload and modify customer explanation. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Deploy JavaEE applications using Docker Containers Deploy JavaEE applications using Docker Containers Jun 05, 2024 pm 08:29 PM

Deploy Java EE applications using Docker containers: Create a Dockerfile to define the image, build the image, run the container and map the port, and then access the application in the browser. Sample JavaEE application: REST API interacts with database, accessible on localhost after deployment via Docker.

Copilot Integration: Collaboration in SharePoint and Dynamics 365 Customer Service Copilot Integration: Collaboration in SharePoint and Dynamics 365 Customer Service Aug 03, 2023 pm 09:21 PM

Microsoft today announced an early preview of SharePoint integration with Copilot in Dynamics 365 Customer Service. This integration will give customer service agents access to a wider range of knowledge sources, resulting in increased productivity and improved customer interactions. Currently, Copilot in Dynamics365 Customer Service leverages an internal knowledge base to provide guidance to customer service agents. By suggesting chat and draft email content, Copilot has become a key tool for increasing the productivity of your customer service team. However, customer feedback indicates that the tool needs to leverage knowledge from external sources such as SharePoint. SharePoint Collaborative Driving Integration In response to this feedback,

New static method of DateTime class in PHP8.1 New static method of DateTime class in PHP8.1 Jul 08, 2023 pm 12:42 PM

New static methods of DateTime class in PHP8.1 PHP8.1 version introduces some powerful features and functions, one of the eye-catching updates is the static method of DateTime class. The DateTime class is an important tool for processing dates and times in PHP. It provides many practical methods to operate and process date and time data. Let's take a look at some of the new static methods of the DateTime class in PHP8.1 and their usage examples. DateTime::cr

The difference between java and javaee The difference between java and javaee Nov 02, 2023 am 10:50 AM

Java and Javaee are defined and used, components and functions, platforms and environments, application scope and development models, etc. Detailed introduction: 1. Definition and purpose, Java is an object-oriented programming language, launched by Sun Microsystems in 1995. Java has the characteristics of cross-platform, portability, security and simplicity, and is widely used to develop various Applications, and Java EE is an enterprise-level extension of the Java platform, designed to develop and deploy large-scale, scalable, reliable enterprise-level applications, etc.

Linux User Management: Revealing New User Operations Linux User Management: Revealing New User Operations Feb 24, 2024 pm 11:03 PM

In Linux systems, adding new users is an important part of managing system permissions and security. This article will reveal the specific methods of adding users in the Linux operating system, including specific code examples and step instructions, to help readers quickly master the skills of adding users. 1. Use the adduser command to add users. The adduser command is the preferred tool for adding users in Debian and Ubuntu. This command calls the useradd command and sets some default values, simplifying the user addition process. To add a

Compatibility issues between JavaEE and container technology Compatibility issues between JavaEE and container technology Jun 03, 2024 pm 05:11 PM

When using Java EE containerized applications, you may encounter compatibility issues such as session state management, dependency injection, resource pooling, and security. Solutions to these problems include using external session storage, configuring JNDI, managing resource pools, and configuring security to ensure that Java EE applications are seamlessly integrated with container technology and gain the advantages of containerization.

iPhone 16 Pro renderings exposed: new camera button iPhone 16 Pro renderings exposed: new camera button Mar 12, 2024 pm 12:40 PM

Overseas media recently exposed CAD rendering images of the iPhone 16 Pro, showing the design details and size specifications of the new model. According to the leaked design drawings, the iPhone 16 Pro continues to use the smart island design of the previous generation and retains the integration scheme of the rear camera module. At the same time, the middle frame is still made of high-quality titanium material. It is worth noting that this phone has brought two significant upgrades: First, in terms of screen display, the iPhone 16 Pro has further reduced the bezel width, thus increasing the screen-to-body ratio. The screen size has increased from the original 6.1 inches of the iPhone 15 Pro to 6.3 inches. inch. Secondly, below the power button on the right side of the fuselage, Apple has equipped it with a new physical camera button, which users can

Does Douyin e-commerce need to receive customers during the Chinese New Year? Customer service rules for small stores during the Chinese New Year Does Douyin e-commerce need to receive customers during the Chinese New Year? Customer service rules for small stores during the Chinese New Year Mar 07, 2024 pm 06:50 PM

With the booming development of social media platforms, Douyin e-commerce has become a favored choice for many merchants. However, there has been some controversy and discussion surrounding the issue of whether Douyin e-commerce companies need to provide customer service during the Chinese New Year. 1. Does Douyin e-commerce need to receive customers during the Chinese New Year? An important traditional Chinese festival is the New Year. At this time, people usually go home to reunite with their families and enjoy a happy and relaxing time. For Douyin e-commerce practitioners, whether they need to receive customers during the Chinese New Year is an issue that needs to be carefully considered. On the one hand, the Chinese New Year is the best time for merchants to promote sales, because many people will have more consumption needs during this period. Therefore, whether you need to receive customers during the Chinese New Year is something that needs to be carefully weighed. On the one hand, receiving customers can bring sales to the company

See all articles