0.

 <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd"> <struts>
<constant name="struts.enable.DynamicMethodInvocation"
value="false" />
<constant name="struts.devMode" value="false" />
<!-- 与spring集成 -->
<constant name="struts.objectFactory" value="spring" />
<!-- 改变后缀名 -->
<constant name="struts.action.extension" value="do" />
<!-- 配置国际化资源文件 -->
<constant name="struts.custom.i18n.resources"
value="globalMessages" />
<!-- 处理编码问题 -->
<constant name="struts.i18n.encoding" value="GBK" />
<!-- 当修改配置文件不需要重启服务,开发比较有用 -->
<constant name="struts.configuration.xml.reload" value="true" />
<!-- 报表 -->
<!--
<package name="lee" namespace="/" extends="jasperreports-default">
<action name="jasper" class="jasperAction">
<result name="success" type="jasper">
<param name="location">report\jasper\order.jrxml</param>
<param name="format">HTML</param>
<param name="dataSource">order</param>
</result>
</action>
</package>
-->
<!-- 用户登录 -->
<package name="san" namespace="/" extends="struts-default">
<action name="login" class="loginAction" >
<result name="success">/back_index.html</result>
<result name="input">/index.jsp</result>
</action>
</package>
<!-- 控制相关模块 -->
<package name="qing" namespace="/control" extends="struts-default">
<interceptors><!--配置拦截器 -->
<interceptor name="loginIntercepter"
class="com.sanqing.intercepter.LoginIntercepter" /><!--配置登录判断拦截器-->
<interceptor-stack name="mydefault"><!--配置拦截器栈-->
<interceptor-ref name="defaultStack" /><!--Struts 2默认拦截器 -->
<interceptor-ref name="loginIntercepter" /><!--登录判断拦截器 -->
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="mydefault" /><!--配置默认拦截器-->
<global-results>
<result name="pub_add_success">/share/pub_add_success.jsp</result>
<result name="pub_update_success">/share/pub_update_success.jsp</result>
<result name="pub_del_success">/share/pub_del_success.jsp</result>
<result name="input">/index.jsp</result>
</global-results>
<!-- 客户显示 -->
<action name="customer" class="customerAction">
<result name="success">
/customer/customer_list.jsp
</result>
</action>
<!-- 客户管理 -->
<action name="customermanage_*" class="customerManageAction" method="{1}">
<result name="add">/customer/customer_add.jsp</result>
<result name="update">/customer/customer_update.jsp</result>
<result name="query">/customer/customer_query.jsp</result>
</action>
<!-- 产品类别显示 -->
<action name="producttype" class="productTypeAction">
<result name="success">
/product/producttype_list.jsp
</result>
</action>
<!-- 产品类别管理 -->
<action name="producttypemanage_*" class="productTypeManageAction" method="{1}">
<result name="add">/product/producttype_add.jsp</result>
<result name="update">/product/producttype_update.jsp</result>
<result name="query">/product/producttype_query.jsp</result>
</action>
<!-- 产品显示 -->
<action name="product" class="productAction">
<result name="success">
/product/product_list.jsp
</result>
</action>
<!-- 产品管理 -->
<action name="productmanage_*" class="productManageAction" method="{1}">
<result name="add">/product/product_add.jsp</result>
<result name="update">/product/product_update.jsp</result>
<result name="query">/product/product_query.jsp</result>
</action>
<!-- 订单显示 -->
<action name="order" class="orderAction">
<result name="success">
/order/order_list.jsp
</result>
</action>
<!-- 订单管理 -->
<action name="ordermanage_*" class="orderManageAction" method="{1}">
<result name="add">/order/order_add.jsp</result>
<result name="update">/order/order_update.jsp</result>
<result name="query">/order/order_query.jsp</result>
</action>
<!-- 报价显示 -->
<action name="quotation" class="quotationAction">
<result name="success">
/quotation/quotation_list.jsp
</result>
</action>
<!-- 报价管理 -->
<action name="quotationmanage_*" class="quotationManageAction" method="{1}">
<result name="add">/quotation/quotation_add.jsp</result>
<result name="update">/quotation/quotation_update.jsp</result>
<result name="query">/quotation/quotation_query.jsp</result>
</action>
<!-- 用户显示 -->
<action name="user" class="userAction">
<result name="success">
/user/user_list.jsp
</result>
</action>
<!-- 用户管理 -->
<action name="usermanage_*" class="userManageAction" method="{1}">
<result name="add">/user/user_add.jsp</result>
<result name="update">/user/user_update.jsp</result>
<result name="query">/user/user_query.jsp</result>
</action>
</package>
</struts>

1.

 package com.sanqing.action;

 import com.opensymphony.xwork2.ActionSupport;
/**
* 基本的action
*/
public class BaseAction extends ActionSupport {
public Integer page; //当前页信息
public String query; //是否为条件查询
public Integer getPage() {//获得当前页信息
return page = (page==null || page<1)? 1 : page;
}
public void setPage(Integer page) {//设置当前页信息
this.page = page;
}
public String getQuery() {//获得query信息
return query;
}
public void setQuery(String query) {//设置query信息
this.query = query;
}
}

2.

 package com.sanqing.action;

 import java.util.ArrayList;
import java.util.List; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller; import com.sanqing.po.Customer;
import com.sanqing.service.CustomerService;
import com.sanqing.util.PageView; /**
* 客户显示action
*/
@Controller("customerAction")
@Scope("prototype")
public class CustomerAction extends BaseAction{
@Resource
private CustomerService customerService;//注入客户业务组件
private String customerNO; //客户编号
private String customerName; //客户名称
private String phone; //客户电话
private String address; //客户地址
private String relationman; //客户联系人
private String otherInfo; //其他
@Override
public String execute() throws Exception {
PageView<Customer> pageView =
new PageView<Customer>(5, getPage());//设置分页信息,每页显示5条记录
StringBuffer jpql = new StringBuffer(""); //初始化条件查询语句
List<Object> params = new ArrayList<Object>(); //初始化查询参数列表
if("true".equals(getQuery())) { //是否为条件查询
if(customerNO!=null && !"".equals(customerNO.trim())) {//根据客户编号进行查询
if(params.size()>0) jpql.append(" and ");
jpql.append(" o.customerNO like ?").append(params.size()+1);
params.add("%"+ customerNO +"%");
}
if(customerName!=null && !"".equals(customerName.trim())) {//根据客户名称查询
if(params.size()>0) jpql.append(" and ");
jpql.append(" o.customerName like ?").append(params.size()+1);
params.add("%"+customerName+"%");
}
if(phone!=null && !"".equals(phone.trim())) {//根据电话号码查询
if(params.size()>0) jpql.append(" and ");
jpql.append(" o.phone like ?").append(params.size()+1);
params.add("%"+phone+"%");
}
if(address!=null && !"".equals(address.trim())) {//根据地址查询
if(params.size()>0) jpql.append(" and ");
jpql.append(" o.address like ?").append(params.size()+1);
params.add("%"+address+"%");
}
if(relationman!=null && !"".equals(relationman.trim())) {//根据联系人查询
if(params.size()>0) jpql.append(" and ");
jpql.append(" o.relationman like ?").append(params.size()+1);
params.add("%"+relationman+"%");
}
if(otherInfo!=null && !"".equals(otherInfo.trim())) {//根据其他信息查询
if(params.size()>0) jpql.append(" and ");
jpql.append(" o.otherInfo like ?").append(params.size()+1);
params.add("%"+otherInfo+"%");
}
pageView.setQueryResult(customerService.getScrollData(
pageView.getFirstResult(), pageView.getMaxresult(),
jpql.toString(), params.toArray()));//按条件查询
}else{
pageView.setQueryResult(customerService.getScrollData
(pageView.getFirstResult(), pageView.getMaxresult()));//查询所有记录
}
HttpServletRequest request = ServletActionContext.getRequest();//获得request对象
request.setAttribute("pageView", pageView);//保存到request范围
return this.SUCCESS;
} public String getCustomerNO() {
return customerNO;
}
public void setCustomerNO(String customerNO) {
this.customerNO = customerNO;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getRelationman() {
return relationman;
}
public void setRelationman(String relationman) {
this.relationman = relationman;
} public String getOtherInfo() {
return otherInfo;
} public void setOtherInfo(String otherInfo) {
this.otherInfo = otherInfo;
}
}

3.

 package com.sanqing.action;

 import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller; import com.sanqing.po.Customer;
import com.sanqing.service.CustomerService;
/**
* 客户管理action
*/
@Controller("customerManageAction")
@Scope("prototype")
public class CustomerManageAction extends BaseAction {
@Resource
private CustomerService customerService;//注入客户业务逻辑组件
private String customerNO; //客户编号
private String customerName; //客户名称
private String phone; //客户电话
private String address; //客户地址
private String relationman; //客户联系人
private String otherInfo; //其他信息
public String addUI() { //新增客户输入界面
return "add";
}
public String add() { //新增客户方法
Customer customer = new Customer();
customer.setAddress(address);
customer.setCustomerNO(customerNO);
customer.setCustomerName(customerName);
customer.setOtherInfo(otherInfo);
customer.setPhone(phone);
customer.setRelationman(relationman);
customerService.save(customer);
return "pub_add_success";
}
public String updateUI() { //该方法用来跳转到客户信息更新表单
Customer customer = customerService.find(customerNO);//查询该客户编号对应的客户
HttpServletRequest request = ServletActionContext.getRequest();//获得request对象
request.setAttribute("customer", customer);//将客户信息保存在request范围
return "update";//跳转到客户信息更新表单页
} public String update() {
Customer customer = new Customer();
customer.setAddress(address);
customer.setCustomerNO(customerNO);
customer.setCustomerName(customerName);
customer.setOtherInfo(otherInfo);
customer.setPhone(phone);
customer.setRelationman(relationman);
customerService.update(customer);//更新客户信息
return "pub_update_success";//跳转到更新成功页面
}
/**
* 删除客户
* @return
*/
public String del() { //删除客户信息
customerService.delete(customerNO);//根据客户编号删除客户
return "pub_del_success";//跳转到删除成功页
}
/**
* 查询客户信息
* @return
*/
public String query() {
return "query";
}
public String getCustomerNO() {
return customerNO;
}
public void setCustomerNO(String customerNO) {
this.customerNO = customerNO;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getRelationman() {
return relationman;
}
public void setRelationman(String relationman) {
this.relationman = relationman;
}
public String getOtherInfo() {
return otherInfo;
}
public void setOtherInfo(String otherInfo) {
this.otherInfo = otherInfo;
} }

4.

 package com.sanqing.action;

 import java.util.Map;

 import javax.annotation.Resource;

 import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller; import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.sanqing.service.UserService;
/**
* 用户登录
*/
@Controller("loginAction")
@Scope("prototype")
public class LoginAction extends ActionSupport { @Resource
private UserService userService ;
private String username ;
private String password ;
@Override
public String execute() throws Exception {
if(!userService.login(username, password)) {
return this.INPUT;
}else{
Map session = ActionContext.getContext().getSession();
session.put("user", userService.find(username));
}
return this.SUCCESS;
} public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}

5.

 package com.sanqing.action;

 import java.util.ArrayList;
import java.util.Date;
import java.util.List; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller; import com.sanqing.po.Customer;
import com.sanqing.po.Order;
import com.sanqing.po.Product;
import com.sanqing.service.OrderService;
import com.sanqing.util.PageView; @Controller("orderAction")
@Scope("prototype")
public class OrderAction extends BaseAction { @Resource
private OrderService orderService;
/* 订单编码 */
private String orderNO;
/* 客户名称 */
private Customer customer;
private String customerName;
/* 产品名称 */
private Product product;
private String productname;
/* 产品数量 */
private int quantity;
/* 订单的时间 */
private Date ordetTime;
/* 其他信息*/
private String otherInfo;
@Override
public String execute() throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
PageView<Order> pageView = new PageView<Order>(5, getPage());
StringBuffer jpql = new StringBuffer("");
List<Object> params = new ArrayList<Object>();
if("true".equals(getQuery())) {
if(orderNO!=null && !"".equals(orderNO)) {
if(params.size()>0) jpql.append(" and ");
jpql.append(" o.orderNO = ?").append(params.size()+1);
params.add(orderNO);
}
if(customerName!=null && !"".equals(customerName)) {
if(params.size()>0) jpql.append(" and ");
jpql.append(" o.customer.customerName like ?").append(params.size()+1);
params.add("%"+customerName+"%");
}
if(productname!=null && !"".equals(productname)) {
if(params.size()>0) jpql.append(" and ");
jpql.append(" o.product.productname like ?").append(params.size()+1);
params.add("%"+productname+"%");
}
if(quantity>0) {
if(params.size()>0) jpql.append(" and ");
jpql.append(" o.quantity = ?").append(params.size()+1);
params.add(quantity);
}
if(otherInfo!=null && !"".equals(otherInfo)) {
if(params.size()>0) jpql.append(" and ");
jpql.append(" o.otherInfo like ?").append(params.size()+1);
params.add("%"+otherInfo+"%");
}
pageView.setQueryResult(orderService.getScrollData(pageView.getFirstResult(), pageView.getMaxresult(), jpql.toString(), params.toArray()));
}else{
pageView.setQueryResult(orderService.getScrollData(pageView.getFirstResult(), pageView.getMaxresult()));
}
request.setAttribute("pageView", pageView);
return this.SUCCESS;
}
public String getOrderNO() {
return orderNO;
}
public void setOrderNO(String orderNO) {
this.orderNO = orderNO;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public Date getOrdetTime() {
return ordetTime;
}
public void setOrdetTime(Date ordetTime) {
this.ordetTime = ordetTime;
}
public String getOtherInfo() {
return otherInfo;
}
public void setOtherInfo(String otherInfo) {
this.otherInfo = otherInfo;
}
public String getProductname() {
return productname;
}
public void setProductname(String productname) {
this.productname = productname;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
} }

6.

 package com.sanqing.action;

 import java.util.Date;
import java.util.List; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller; import com.sanqing.po.Customer;
import com.sanqing.po.Order;
import com.sanqing.po.Product;
import com.sanqing.service.CustomerService;
import com.sanqing.service.OrderService;
import com.sanqing.service.ProductService; @Controller("orderManageAction")
@Scope("prototype")
public class OrderManageAction extends BaseAction { @Resource
private OrderService orderService;
@Resource
private CustomerService customerService;
@Resource
private ProductService productService; /* 订单编码 */
private String orderNO;
/* 客户名称 */
private Customer customer;
/* 产品名称 */
private Product product;
/* 产品数量 */
private int quantity;
/* 订单的时间 */
private Date orderTime;
/* 其他信息*/
private String otherInfo; /**
* 添加订单输入界面
* @return
*/
public String addUI() {
HttpServletRequest request = ServletActionContext.getRequest();
List<Customer> customers = customerService.getScrollData().getResultlist();
List<Product> products = productService.getScrollData().getResultlist();
request.setAttribute("customers", customers);
request.setAttribute("products", products);
return "add";
}
/**
* 添加订单
* @return
*/
public String add() {
Order order = new Order();
order.setCustomer(customer);
order.setOrderNO(orderNO);
order.setOrderTime(orderTime);
order.setOtherInfo(otherInfo);
order.setProduct(product);
order.setQuantity(quantity);
orderService.save(order);
return "pub_add_success";
}
/**
* 修改订单输入界面
* @return
*/
public String updateUI() {
HttpServletRequest request = ServletActionContext.getRequest();
List<Customer> customers = customerService.getScrollData().getResultlist();
List<Product> products = productService.getScrollData().getResultlist();
Order order = orderService.find(orderNO);
request.setAttribute("customers", customers);
request.setAttribute("products", products);
request.setAttribute("order", order);
return "update";
}
/**
* 修改订单
* @return
*/
public String update() {
Order order = new Order();
order.setCustomer(customer);
order.setOrderNO(orderNO);
order.setOrderTime(orderTime);
order.setOtherInfo(otherInfo);
order.setProduct(product);
order.setQuantity(quantity);
orderService.update(order);
return "pub_update_success";
}
/**
* 删除订单
* @return
*/
public String del() {
orderService.delete(orderNO);
return "pub_del_success";
}
/**
* 查询订单
* @return
*/
public String query() {
HttpServletRequest request = ServletActionContext.getRequest();
List<Customer> customers = customerService.getScrollData().getResultlist();
List<Product> products = productService.getScrollData().getResultlist();
request.setAttribute("customers", customers);
request.setAttribute("products", products);
return "query";
} public String getOrderNO() {
return orderNO;
}
public void setOrderNO(String orderNO) {
this.orderNO = orderNO;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public Date getOrderTime() {
return orderTime;
}
public void setOrderTime(Date orderTime) {
this.orderTime = orderTime;
}
public String getOtherInfo() {
return otherInfo;
}
public void setOtherInfo(String otherInfo) {
this.otherInfo = otherInfo;
}
}

7.

 package com.sanqing.action;

 import java.util.ArrayList;
import java.util.List; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller; import com.sanqing.po.Product;
import com.sanqing.service.ProductService;
import com.sanqing.util.PageView;
/**
* 显示产品
*/
@Controller("productAction")
@Scope("prototype")
public class ProductAction extends BaseAction {
@Resource
private ProductService productService;
/* 产品编号 */
private String productNO;
// 产品类型编号
private String producttypeNO;
//产品类型名称
private String producttypeName;
/* 产品名称 */
private String productName;
/* 产品所在区域 */
private String productArea;
/* 产品所有者 */
private String productOwner;
/* 产品单位 */
private String unit;
/* 产品价格 */
private double price;
/* 产品数量*/
private int quantity;
/* 其他信息 */
private String otherInfo; @Override
public String execute() throws Exception {
PageView<Product> pageView = new PageView<Product>(5, getPage());
StringBuffer jpql = new StringBuffer("");
List<Object> params = new ArrayList<Object>();
if("true".equals(getQuery())) {
if(productNO!=null && !"".equals(productNO.trim())) {
if(params.size()>0) jpql.append(" and ");
jpql.append(" o.productNO=?").append(params.size()+1);
params.add(productNO);
}
if(producttypeName!=null && !"".equals(producttypeName.trim())) {
if(params.size()>0)jpql.append(" and ");
jpql.append(" o.productType.producttypeName like ?").append(params.size()+1);
params.add(producttypeName);
}
if(productName!=null && !"".equals(productName.trim())) {
if(params.size()>0)jpql.append(" and ");
jpql.append(" o.productName like ?").append(params.size()+1);
params.add(productName);
}
if(productArea!=null && !"".equals(productArea.trim())) {
if(params.size()>0)jpql.append(" and ");
jpql.append(" o.productArea like ?").append(params.size()+1);
params.add(productArea);
}
if(productOwner!=null && !"".equals(productOwner.trim())) {
if(params.size()>0)jpql.append(" and ");
jpql.append(" o.productOwner like ?").append(params.size()+1);
params.add(productOwner);
}
if(unit!=null && !"".equals(unit.trim())) {
if(params.size()>0)jpql.append(" and ");
jpql.append(" o.unit like ?").append(params.size()+1);
params.add(unit);
}
if(price>0) {
if(params.size()>0)jpql.append(" and ");
jpql.append(" o.price=?").append(params.size()+1);
params.add(price);
}
if(quantity>0) {
if(params.size()>0)jpql.append(" and ");
jpql.append(" o.quantity=?").append(params.size()+1);
params.add(quantity);
}
if(otherInfo!=null && !"".equals(otherInfo.trim())) {
if(params.size()>0)jpql.append(" and ");
jpql.append(" o.otherInfo like ?").append(params.size()+1);
params.add(otherInfo);
}
pageView.setQueryResult(productService.getScrollData(pageView.getFirstResult(), pageView.getMaxresult(),jpql.toString(), params.toArray()));
}else{
pageView.setQueryResult(productService.getScrollData(pageView.getFirstResult(), pageView.getMaxresult()));
}
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("pageView", pageView);
return this.SUCCESS;
}
public String getProductNO() {
return productNO;
}
public void setProductNO(String productNO) {
this.productNO = productNO;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getProductArea() {
return productArea;
}
public void setProductArea(String productArea) {
this.productArea = productArea;
}
public String getProductOwner() {
return productOwner;
}
public void setProductOwner(String productOwner) {
this.productOwner = productOwner;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public String getOtherInfo() {
return otherInfo;
}
public void setOtherInfo(String otherInfo) {
this.otherInfo = otherInfo;
}
public String getProducttypeNO() {
return producttypeNO;
}
public void setProducttypeNO(String producttypeNO) {
this.producttypeNO = producttypeNO;
}
public String getProducttypeName() {
return producttypeName;
}
public void setProducttypeName(String producttypeName) {
this.producttypeName = producttypeName;
} }

8.

 package com.sanqing.action;

 import java.util.List;

 import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller; import com.sanqing.po.Product;
import com.sanqing.po.ProductType;
import com.sanqing.service.ProductService;
import com.sanqing.service.ProductTypeService;
/**
* 产品管理
*/
@Controller("productManageAction")
@Scope("prototype")
public class ProductManageAction extends BaseAction { @Resource
private ProductService productService;
@Resource
private ProductTypeService productTypeService; /* 产品编号 */
private String productNO;
// 产品类型编号
private String producttypeNO;
/* 产品名称 */
private String productName;
/* 产品所在区域 */
private String producingArea;
/* 产品所有者 */
private String productOwner;
/* 产品单位 */
private String unit;
/* 产品价格 */
private double price;
/* 产品数量*/
private int quantity;
/* 其他信息 */
private String otherInfo;
/**
* 添加产品输入界面
* @return
*/
public String addUI() {
HttpServletRequest request = ServletActionContext.getRequest();
List<ProductType> producttypes = productTypeService.getScrollData().getResultlist();
request.setAttribute("producttypes", producttypes);
return "add";
}
/**
* 添加产品
* @return
*/
public String add() {
Product product = new Product();
product.setProductNO(productNO);
product.setProductType(new ProductType(producttypeNO));
product.setOtherInfo(otherInfo);
product.setPrice(price);
product.setProducingArea(producingArea);
product.setProductName(productName);
product.setProductOwner(productOwner);
product.setQuantity(quantity);
product.setUnit(unit);
productService.save(product);
return "pub_add_success";
}
/**
* 修改产品输入界面
* @return
*/
public String updateUI() {
Product product = productService.find(productNO);
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("product", product);
List<ProductType> producttypes = productTypeService.getScrollData().getResultlist();
request.setAttribute("producttypes", producttypes);
return "update";
}
/**
* 修改产品
* @return
*/
public String update() {
Product product = new Product();
product.setProductNO(productNO);
product.setProductType(new ProductType(producttypeNO));
product.setOtherInfo(otherInfo);
product.setPrice(price);
product.setProducingArea(producingArea);
product.setProductName(productName);
product.setProductOwner(productOwner);
product.setQuantity(quantity);
product.setUnit(unit);
productService.update(product);
return "pub_update_success";
}
/**
* 删除产品
* @return
*/
public String del() {
productService.delete(productNO);
return "pub_del_success";
}
/**
* 产品查询
* @return
*/
public String query() {
return "query";
}
public String getProductNO() {
return productNO;
}
public void setProductNO(String productNO) {
this.productNO = productNO;
}
public String getProducttypeNO() {
return producttypeNO;
}
public void setProducttypeNO(String producttypeNO) {
this.producttypeNO = producttypeNO;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getProducingArea() {
return producingArea;
}
public void setProducingArea(String producingArea) {
this.producingArea = producingArea;
}
public String getProductOwner() {
return productOwner;
}
public void setProductOwner(String productOwner) {
this.productOwner = productOwner;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public String getOtherInfo() {
return otherInfo;
}
public void setOtherInfo(String otherInfo) {
this.otherInfo = otherInfo;
} }

9.

 package com.sanqing.action;

 import java.util.ArrayList;
import java.util.List; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller; import com.sanqing.po.ProductType;
import com.sanqing.service.ProductTypeService;
import com.sanqing.util.PageView;
/**
* 产品类别显示
*/
@Controller("productTypeAction")
@Scope("prototype")
public class ProductTypeAction extends BaseAction { @Resource
private ProductTypeService productTypeService; // 产品类型编号
private String producttypeNO;
// 产品类型名称
private String producttypeName; @Override
public String execute() throws Exception {
PageView<ProductType> pageView = new PageView<ProductType>(5, getPage());
StringBuffer jpql = new StringBuffer("");
List<Object> params = new ArrayList<Object>();
if("true".equals(getQuery())) {
if(producttypeName!=null && !"".equals(producttypeName.trim())) {
if(params.size()>0) jpql.append(" and ");
jpql.append(" o.producttypeName like ?").append(params.size()+1);
params.add("%"+producttypeName+"%");
}
if(producttypeNO!=null && !"".equals(producttypeNO.trim())) {
if(params.size()>0) jpql.append(" and ");
jpql.append(" o.producttypeNO like ?").append(params.size()+1);
params.add("%"+producttypeNO+"%");
}
pageView.setQueryResult(productTypeService.getScrollData(pageView.getFirstResult(), pageView.getMaxresult(), jpql.toString(), params.toArray()));
}else{
pageView.setQueryResult(productTypeService.getScrollData(pageView.getFirstResult(), pageView.getMaxresult()));
}
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("pageView", pageView);
return this.SUCCESS;
}
public String getProducttypeNO() {
return producttypeNO;
}
public void setProducttypeNO(String producttypeNO) {
this.producttypeNO = producttypeNO;
}
public String getProducttypeName() {
return producttypeName;
}
public void setProducttypeName(String producttypeName) {
this.producttypeName = producttypeName;
}
}

10.

 package com.sanqing.action;

 import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller; import com.sanqing.po.ProductType;
import com.sanqing.service.ProductTypeService; @Controller("productTypeManageAction")
@Scope("prototype")
public class ProductTypeManageAction extends BaseAction { @Resource
private ProductTypeService productTypeService ;
// 产品类型编号
private String producttypeNO;
// 产品类型名称
private String producttypeName;
/**
* 添加产品类别输入界面
* @return
*/
public String addUI() {
return "add";
}
/**
* 添加产品类别
* @return
*/
public String add() {
ProductType productType = new ProductType();
productType.setProducttypeNO(producttypeNO);
productType.setProducttypeName(producttypeName);
productTypeService.save(productType);
return "pub_add_success";
}
/**
* 修改产品类别输入界面
* @return
*/
public String updateUI() {
ProductType productType = productTypeService.find(producttypeNO);
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("productType", productType);
return "update";
}
/**
* 修改产品类别
* @return
*/
public String update() {
ProductType productType = new ProductType();
productType.setProducttypeNO(producttypeNO);
productType.setProducttypeName(producttypeName);
productTypeService.update(productType);
return "pub_update_success";
}
/**
* 删除产品类别
* @return
*/
public String del() {
productTypeService.delete(producttypeNO);
return "pub_del_success";
}
/**
* 产品类别查询
* @return
*/
public String query() {
return "query";
}
public String getProducttypeNO() {
return producttypeNO;
}
public void setProducttypeNO(String producttypeNO) {
this.producttypeNO = producttypeNO;
}
public String getProducttypeName() {
return producttypeName;
}
public void setProducttypeName(String producttypeName) {
this.producttypeName = producttypeName;
}
}

11.

 package com.sanqing.action;

 import java.util.ArrayList;
import java.util.Date;
import java.util.List; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller; import com.sanqing.po.Customer;
import com.sanqing.po.Product;
import com.sanqing.po.Quotation;
import com.sanqing.service.QuotationService;
import com.sanqing.util.PageView; @Controller("quotationAction")
@Scope("prototype")
public class QuotationAction extends BaseAction {
@Resource
private QuotationService quotationService; //报价业务逻辑组件
// 报价编号
private String quotationNO;
// 报价人
private String quotationMan;
// 报价时间
private Date quotationtime;
// 其他
private String otherInfo;
//产品
private Product product ;
private String productName;
//客户
private Customer customer;
private String customerName; @Override
public String execute() throws Exception {
PageView<Quotation> pageView =
new PageView<Quotation>(5, getPage());//设置分页信息
StringBuffer jpql = new StringBuffer("");//初始化条件查询语句
List<Object> params = new ArrayList<Object>();//初始化查询参数
if("true".equals(getQuery())) { //按条件查询
if(quotationNO!=null && !"".equals(quotationNO)) {//根据报价编号进行查询
if(params.size()>0) jpql.append(" and ");
jpql.append(" o.quotationNO = ?").append(params.size()+1);
params.add(quotationNO);
}
if(quotationMan!=null && !"".equals(quotationMan)) {//根据报价人进行查询
if(params.size()>0) jpql.append(" and ");
jpql.append(" o.quotationMan like ?").append(params.size()+1);
params.add(quotationMan);
}
if(otherInfo!=null && !"".equals(otherInfo)) {//根据其他信息进行查询
if(params.size()>0) jpql.append(" and ");
jpql.append(" o.otherInfo like ?").append(params.size()+1);
params.add(otherInfo);
}
if(productName!=null && !"".equals(productName)) {//根据产品名称进行查询
if(params.size()>0) jpql.append(" and ");
jpql.append(" o.product.productName like ?").append(params.size()+1);
params.add(productName);
}
if(customerName!=null && !"".equals(customerName)) {//根据客户名称进行查询
if(params.size()>0) jpql.append(" and ");
jpql.append(" o.customer.customerName = ?").append(params.size()+1);
params.add(customerName);
}
pageView.setQueryResult(quotationService.getScrollData(pageView.getFirstResult(),
pageView.getMaxresult(),jpql.toString(),params.toArray()));//按条件进行查询
}else{
pageView.setQueryResult(quotationService.getScrollData(
pageView.getFirstResult(), pageView.getMaxresult()));//查询所有记录
}
HttpServletRequest request = ServletActionContext.getRequest();//获得request对象
request.setAttribute("pageView", pageView);//保存到request范围
return this.SUCCESS;
}
public String getQuotationNO() {
return quotationNO;
}
public void setQuotationNO(String quotationNO) {
this.quotationNO = quotationNO;
}
public String getQuotationMan() {
return quotationMan;
}
public void setQuotationMan(String quotationMan) {
this.quotationMan = quotationMan;
}
public Date getQuotationtime() {
return quotationtime;
}
public void setQuotationtime(Date quotationtime) {
this.quotationtime = quotationtime;
}
public String getOtherInfo() {
return otherInfo;
}
public void setOtherInfo(String otherInfo) {
this.otherInfo = otherInfo;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
}

12.

 package com.sanqing.action;

 import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller; import com.sanqing.po.Customer;
import com.sanqing.po.Product;
import com.sanqing.po.Quotation;
import com.sanqing.service.CustomerService;
import com.sanqing.service.ProductService;
import com.sanqing.service.QuotationService;
@Controller("quotationManageAction")
@Scope("prototype")
public class QuotationManageAction extends BaseAction {
@Resource
private QuotationService quotationService; //报价业务逻辑组件
@Resource
private ProductService productService ; //产品业务逻辑组件
@Resource
private CustomerService customerService; //客户业务逻辑组件
private String quotationNO; // 报价编号
private String quotationMan; // 报价人
private String otherInfo; // 其他信息
private Product product ; //产品信息
private Customer customer; //客户信息
public String addUI() { //跳转到报价信息输入页面
HttpServletRequest request =
ServletActionContext.getRequest();//获得request对象
request.setAttribute("products",
productService.getScrollData().getResultlist());//保存产品信息列表
request.setAttribute("customers",
customerService.getScrollData().getResultlist());//保存客户信息列表
return "add";
}
public String add() { //完成报价信息的录入
Quotation quotation = new Quotation();//实例化一个Quotation对象
quotation.setCustomer(customer);//设置客户信息
quotation.setOtherInfo(otherInfo);//设置其他信息
quotation.setProduct(product);//设置产品信息
quotation.setQuotationNO(quotationNO);//设置报价编号
quotation.setQuotationMan(quotationMan);//设置报价人
quotationService.save(quotation);//保存报价信息
return "pub_add_success";//跳转到录入成功页面
}
public String updateUI() { //跳转到报价信息修改页面
HttpServletRequest
request = ServletActionContext.getRequest();//获得request对象
request.setAttribute("products",
productService.getScrollData().getResultlist());//获得产品信息并保存
request.setAttribute("customers",
customerService.getScrollData().getResultlist());//获得客户信息并保存
request.setAttribute("quotation",
quotationService.find(quotationNO));//获得报价信息并保存
return "update";
}
public String update() {
Quotation quotation = new Quotation();//实例化一个Quotation对象
quotation.setCustomer(customer);//设置客户信息
quotation.setOtherInfo(otherInfo);//设置其他信息
quotation.setProduct(product);//设置产品信息
quotation.setQuotationNO(quotationNO);//设置报价编号
quotation.setQuotationMan(quotationMan);//设置报价人
quotationService.update(quotation);//更新报价信息
return "pub_update_success";//跳转到更新成功页面
}
public String del() {//删除报价信息
quotationService.delete(quotationNO);//调用业务逻辑组件完成删除
return "pub_del_success";//跳转到删除成功页面
}
/**
* 查询报价
* @return
*/
public String query() {
return "query";
}
public String getQuotationNO() {
return quotationNO;
}
public void setQuotationNO(String quotationNO) {
this.quotationNO = quotationNO;
}
public String getQuotationMan() {
return quotationMan;
}
public void setQuotationMan(String quotationMan) {
this.quotationMan = quotationMan;
}
public String getOtherInfo() {
return otherInfo;
}
public void setOtherInfo(String otherInfo) {
this.otherInfo = otherInfo;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
} }

13.

 package com.sanqing.action;

 import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller; import com.sanqing.po.User;
import com.sanqing.service.UserService;
import com.sanqing.util.PageView; @Controller("userAction")
@Scope("prototype")
public class UserAction extends BaseAction { @Resource
private UserService userService;
/* 用户名 */
private String username;
/* 密码 */
private String password;
/* 级别 */
private int grade;
@Override
public String execute() throws Exception {
PageView<User> pageView = new PageView<User>(5, getPage());
if("true".equals(getQuery())) {
if(username!=null && !"".equals(username)) {
pageView.setQueryResult(userService.getScrollData(pageView.getFirstResult(), pageView.getMaxresult(), " o.username like ?1", new Object[]{username}));
}
}else {
pageView.setQueryResult(userService.getScrollData(pageView.getFirstResult(), pageView.getMaxresult()));
}
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("pageView", pageView);
return this.SUCCESS;
} public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getGrade() {
return grade;
}
public void setGrade(int grade) {
this.grade = grade;
}
}

14.

 package com.sanqing.action;

 import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller; import com.sanqing.po.User;
import com.sanqing.service.UserService; @Controller("userManageAction")
@Scope("prototype")
public class UserManageAction extends BaseAction { @Resource
private UserService userService;
/* 用户名 */
private String username;
/* 密码 */
private String password;
/* 级别 */
private int grade;
/**
* 添加用户输入界面
* @return
*/
public String addUI() {
return "add";
}
/**
* 添加用户
* @return
*/
public String add() {
User user = new User();
user.setGrade(grade);
user.setPassword(password);
user.setUsername(username);
userService.save(user);
return "pub_add_success";
}
/**
* 修改界面
* @return
*/
public String updateUI() {
User user = userService.find(username);
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("user", user);
return "update";
}
/**
* 修改界面
* @return
*/
public String update() {
User user = new User();
user.setGrade(grade);
user.setUsername(username);
user.setPassword(password);
userService.update(user);
return "pub_update_success";
}
/**
* 删除
* @return
*/
public String del() {
userService.delete(username);
return "pub_del_success";
}
/**
* 查询用户
* @return
*/
public String query() {
return "query";
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getGrade() {
return grade;
}
public void setGrade(int grade) {
this.grade = grade;
} }

JavaWeb项目开发案例精粹-第6章报价管理系统-05Action层的更多相关文章

  1. JavaWeb项目开发案例精粹-第6章报价管理系统-07View层

    1. 2.back_index.html <HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT= ...

  2. JavaWeb项目开发案例精粹-第6章报价管理系统-06po层

    1. <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www ...

  3. JavaWeb项目开发案例精粹-第6章报价管理系统-04Service层

    1. package com.sanqing.service; import com.sanqing.dao.DAO; import com.sanqing.po.Customer; /** * 客户 ...

  4. JavaWeb项目开发案例精粹-第6章报价管理系统-03Dao层

    1. package com.sanqing.dao; import java.io.Serializable; import java.util.LinkedHashMap; import com. ...

  5. JavaWeb项目开发案例精粹-第6章报价管理系统-002辅助类及配置文件

    1. <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www ...

  6. JavaWeb项目开发案例精粹-第6章报价管理系统-001需求分析及设计

    1. 2. 3. 4. 5. 6.

  7. JavaWeb项目开发案例精粹-第2章投票系统-006view层

    1.index.jsp <%@ page language="java" import="java.util.*" pageEncoding=" ...

  8. JavaWeb项目开发案例精粹-第2章投票系统-004action层

    1. package com.sanqing.action; import java.util.UUID; import com.opensymphony.xwork2.ActionSupport; ...

  9. JavaWeb项目开发案例精粹-第2章投票系统-003Dao层

    1. package com.sanqing.dao; import java.util.List; import com.sanqing.bean.Vote; import com.sanqing. ...

随机推荐

  1. objective-c自学总结(一)---面向对象

    本人大二本科在读,利用一个月多一点的时间对OC语言基础进行了自学,在下一阶段UI学习开始之前, 对这一阶段的自学进行一些总结.在此特别感谢刘晓斌学长和无线互联3G学院 首先说一下对OC的整体感觉,这是 ...

  2. 远航1617团队alpha版本分数分配与人员调动

    一.根据项目开始初期的分数分配要求及项目发布后大家的讨论,我们对组内成员的分数分配如下: 刘昊岩 20.5 周  萱 20.0 林谋武 19.0 杨  帆 18.5 高小洲 21.0 谢勤政 21.5 ...

  3. 每日会议<第二天>

    昨天:看android编程教学视频 今天:看了老师给的学姐.学长软件的代码,找到他们的优缺点,取长补短 困难:创新意识少,提不出建设性意见,缺少自己的思想

  4. Hibernate 检索查询的几种方式(HQL,QBC,本地SQL,集成Spring等)

    1.非集成Spring hibernate的检索方式,主要有以下五种. 1.导航对象图检索方式.(根据已经加载的对象,导航到其他对象.) 2.OID检索方式.(按照对象的OID来检索对象.) 3.HQ ...

  5. The code of method _jspService(HttpServletRequest, HttpServletResponse) is exceeding the 65535 bytes limit

    如果你是通过搜索来到本文的,相信你应该是遇到了如下的错误 The code of method _jspService(HttpServletRequest, HttpServletResponse) ...

  6. 在Eclipse新建菜单中添加JSP

    在开发的时候,大家可能选择不同的透视图,下面以Java EE透视图为例. 在项目上右键,选择new命令,出来的菜单中并没有新建JSP的选项. 这样一来,如果想新建JSP,只能选择Other命令,在里面 ...

  7. cookie和session的代码实现

    cookie和session的代码实现 1.设置cookie 今天笔试题考的是cookie的设置,我竟然选了request也可以设置cookie,我的天呀. 我们来看如何在response设置吧 pu ...

  8. 【转】EXT VTYPE自定义举例

    原文地址:http://www.blogjava.net/xiaohuzi2008/archive/2012/12/08/392676.html 近日来对Ext特别感兴趣,也许是它那种OO的设计思想吸 ...

  9. Android ADT中增大AVD内存后无法启动:emulator failed to allocate memory 8 (转)

    Android ADT中增大AVD内存后无法启动:emulator failed to allocate memory 8http://www.crifan.com/android_emulator_ ...

  10. 【bzoj1005】[HNOI2008]明明的烦恼

    1005: [HNOI2008]明明的烦恼 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 4175  Solved: 1660[Submit][Stat ...