struts学习遇到问题之一 action

/**
 * 文件名:ModifyCustomerById.java
 * 版本信息:Version 1.0
 * 日期:2016-8-19
 * Copyright talkweb.com.cn Corporation 2016 
 * 版权所有
 */
package com.clps.training.crm.customer.action;

import java.util.List;

import com.clps.training.crm.customer.model.Customer;
import com.clps.training.crm.customer.service.CustomerService;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;

/**
 * 类描述:
 * 
 * @version: 1.0
 * @author: zyfJava
 * @version: 2016-8-19 下午5:30:11
 */
public class CustomerAction extends ActionSupport{


    /* serialVersionUID: serialVersionUID */
    private static final long serialVersionUID = 1L;
    private static final Logger LOG = LoggerFactory
            .getLogger(CustomerAction.class);
    private CustomerService service = new CustomerService();
    private List<Customer> cusList;
    private Customer customer;
    private String customerId;
    private String customerName;
    private String customerSex;
    private String customerMobilePhone;
    private String companyAddress;
    private String weChat;
    private String qqNumer;
    private String email;



    /**
     * 类的构造方法 创建一个新的实例 ModifyCustomerById.
     * 
     * @param
     */
    public CustomerAction() {
        System.out.println("execute ----CustomerAction Construct ");
    }

    /**
     * @return customerId : return the property customerId.
     */
    public String getCustomerId() {
        return customerId;
    }

    /**
     * @param customerId
     *            : set the property customerId.
     */
    public void setCustomerId(String customerId) {
        this.customerId = customerId;
    }

    /**
     * @return customerName : return the property customerName.
     */
    public String getCustomerName() {
        return customerName;
    }

    /**
     * @param customerName
     *            : set the property customerName.
     */
    public void setCustomerName(String customerName) {
        this.customerName = customerName;
    }

    /**
     * @return customerSex : return the property customerSex.
     */
    public String getCustomerSex() {
        return customerSex;
    }

    /**
     * @param customerSex
     *            : set the property customerSex.
     */
    public void setCustomerSex(String customerSex) {
        this.customerSex = customerSex;
    }

    /**
     * @return customerMobilePhone : return the property customerMobilePhone.
     */
    public String getCustomerMobilePhone() {
        return customerMobilePhone;
    }

    /**
     * @param customerMobilePhone
     *            : set the property customerMobilePhone.
     */
    public void setCustomerMobilePhone(String customerMobilePhone) {
        this.customerMobilePhone = customerMobilePhone;
    }

    /**
     * @return companyAddress : return the property companyAddress.
     */
    public String getCompanyAddress() {
        return companyAddress;
    }

    /**
     * @param companyAddress
     *            : set the property companyAddress.
     */
    public void setCompanyAddress(String companyAddress) {
        this.companyAddress = companyAddress;
    }

    /**
     * @return weChat : return the property weChat.
     */
    public String getWeChat() {
        return weChat;
    }

    /**
     * @param weChat
     *            : set the property weChat.
     */
    public void setWeChat(String weChat) {
        this.weChat = weChat;
    }

    /**
     * @return qqNumer : return the property qqNumer.
     */
    public String getQqNumer() {
        return qqNumer;
    }

    /**
     * @param qqNumer
     *            : set the property qqNumer.
     */
    public void setQqNumer(String qqNumer) {
        this.qqNumer = qqNumer;
    }

    /**
     * @return email : return the property email.
     */
    public String getEmail() {
        return email;
    }

    /**
     * @param email
     *            : set the property email.
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * @return cusList : return the property cusList.
     */
    public List<Customer> getCusList() {
        return cusList;
    }

    /**
     * @param cusList
     *            : set the property cusList.
     */
    public void setCusList(List<Customer> cusList) {
        this.cusList = cusList;
    }

    public String modify() throws Exception {
        return null;
    }

    /**
     * @return customer : return the property customer.
     */
    public Customer getCustomer() {
        return customer;
    }

    /**
     * @param customer
     *            : set the property customer.
     */
    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public String queryById() {
        customer = service.getCustomer(this.customerId);
        System.out.println(this.customerId);
        System.out.println((customer==null)+"---"+customer.toString());
        return SUCCESS;
    }

    public String queryAllCustomer() {

        setCusList(service.getCustomerList());
        return SUCCESS;
    }

    public String update() {
        service.updateCustomer(customerId, customer);
        return SUCCESS;
    }

    public String execute() throws Exception {

        setCusList(service.getCustomerList());
        return SUCCESS;
    }
}

遇到问题是在测试类中测试service.getCustomer(“0001”);能够查询到customer但是在action中调用,已经service.getCustomer(this.customerId);注入了id但是返回的customer为空。
猜测是因为之前调用了该action中的queryAllCustomer(),其中也使用了service。但是不明白为什么?

找到答案:
原来是数据库连接仅仅打开过一次,在其他方法要调用的时候关闭之后没有开启,所以导致这样的情况出现。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值