ssh 简单入门实现登录 curd

CustomerAction.java

package com.shiep.action;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.opensymphony.xwork2.ActionContext;
import com.shiep.pojo.Customer;
import com.shiep.pojo.Login;
import com.shiep.pojo.QueryVo;
import com.shiep.service.CustomerService;

@Controller("customerAction")
@Scope("prototype")
public class CustomerAction {
	
	private Customer customer;
	private long cust_id;
	private Login vo;
	private QueryVo queryVo;

	@Resource(name="customerService")
	private CustomerService customerService;
	public String list(){
	
     
		List<Customer> list = customerService.selectAll(this.getQueryVo());
		ActionContext.getContext().put("listAll",list);
		return "list";
		
	}
	
	public String edit(){ 
	
		Customer customer = customerService.selectCustomerById(this.getCust_id());
		ActionContext.getContext().put("customer",customer);
//		this.setCustomer(customer);
		return "edit";
				
	}
	public String update_(){
		customerService.updateCustomerById(customer);
		return "update";
	
	}
	
	public String delete(){
		customerService.deleteCustomerById(this.getCust_id());
		return "delete";
		
	}
	
	public String save(){
		customerService.saveCustomer(customer);
		return "save";
		
	}
	public String login(){
		Login login = customerService.findLogin(this.getVo());
	
		if (login!=null) {
			return "login";
			
		}
		return "error";
		
	}
	
	public QueryVo getQueryVo() {
		return queryVo;
	}
	
	public void setQueryVo(QueryVo queryVo) {
		this.queryVo = queryVo;
	}
	
	public Customer getCustomer() {
		return customer;
	}
	
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}
	public Login getVo() {
		return vo;
	}
	
	public void setVo(Login vo) {
		this.vo = vo;
	}

	public long getCust_id() {
		return cust_id;
	}

	public void setCust_id(long cust_id) {
		this.cust_id = cust_id;
	}
	

	}

CustomerDao.java

package com.shiep.dao;

import java.util.List;
import com.shiep.pojo.Customer;
import com.shiep.pojo.Login;
import com.shiep.pojo.QueryVo;
public interface CustomerDao {

	public List<Customer> customerList(QueryVo queryVo);
	public  Customer selectCustomerById(long id);
	public void updateCustomerById(Customer customer);
	public void deleteCustomerById(long id);
	public void saveCustomer(Customer customer);
	public Login find(Login vo);
	
}

CustomerDaoImpl.java

package com.shiep.dao;
import java.util.List;
import javax.annotation.Resource;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import com.shiep.pojo.Customer;
import com.shiep.pojo.Login;
import com.shiep.pojo.QueryVo;
@SuppressWarnings("all")
@Repository("customerDao")
public class CustomerDaoImpl implements CustomerDao {
	@Resource(name="sessionFactory")
	private SessionFactory sessionFactory;

	    public SessionFactory getSessionFactory() {
	        return sessionFactory;
	    }
	    void setSessionFactory(SessionFactory sessionFactory) {
	        this.sessionFactory = sessionFactory;
	    }
	    private Session getCurrentSession() {
	        return sessionFactory.getCurrentSession();
	    } 
	@Override
	public List<Customer> customerList(QueryVo queryVo) {
		Session session=null;
		List<Customer> list=null;
	try {	
	     StringBuffer str=new StringBuffer(" from Customer where 1=1 ");
        if (queryVo!=null) {
	    if (queryVo.getCustName().trim()!="" && queryVo.getCustName().trim()!=null) {
			str.append(" and cust_name like :cust_name ");
	        }
	    if (queryVo.getCustSource().trim()!="" && queryVo.getCustSource().trim()!=null) {
			str.append(" and cust_source like :cust_source ");
	        }
	    if (queryVo.getCustIndustry().trim()!="" && queryVo.getCustIndustry().trim()!=null) {
			str.append(" and cust_industry like :cust_industry ");
		}
	    if (queryVo.getCustLevel().trim()!="" && queryVo.getCustLevel().trim()!=null) {
			str.append(" and cust_level like :cust_level");
		}
	    }	
		session = this.getCurrentSession();
		Transaction tx = session.beginTransaction();
		Query query=session.createQuery(str.toString()); 
		
        if (queryVo!=null) {
	    if (queryVo.getCustName().trim()!="" && queryVo.getCustName().trim()!=null ) {
			query.setParameter("cust_name","%"+queryVo.getCustName()+"%");
	        }
	    if (queryVo.getCustSource().trim()!="" && queryVo.getCustSource().trim()!=null) {
			query.setParameter("cust_source", "%"+queryVo.getCustSource()+"%");
		}
	    if (queryVo.getCustIndustry().trim()!="" && queryVo.getCustIndustry().trim()!=null) {
		        query.setParameter("cust_industry", "%"+queryVo.getCustIndustry()+"%");
		}
	    if (queryVo.getCustLevel().trim()!="" && queryVo.getCustLevel().trim()!=null) {
		        query.setParameter("cust_level", "%"+queryVo.getCustLevel()+"%");
		}
	    }
		
		list=query.list(); 
//		tx.commit();	
		} catch (HibernateException e) {
			e.printStackTrace();
		}finally {
//			session.close();
		}
		return list;
	}

	@Override
	public Customer selectCustomerById(long cust_id) {
		Session session=null;
		Customer cus=null;
		try {
		String sql="from Customer c where c.cust_id = :cust_id";
		session = this.getCurrentSession();
		Transaction tx = session.beginTransaction();
		Query query = session.createQuery(sql).setParameter("cust_id", cust_id);
	    cus=(Customer) query.uniqueResult();
//		tx.commit();	
		} catch (HibernateException e) {
			e.printStackTrace();
		}finally {
//			session.close();
		}
		return  cus;
	}
	@Override
	public void updateCustomerById(Customer customer) {
		Session session=null;
		try {
			session=this.getCurrentSession();
			Transaction tx = session.beginTransaction();
			session.update(customer);
//			tx.commit();
		} catch (HibernateException e) {
			e.printStackTrace();
		}finally{
//			session.close();
		}
	}

	@Override
	public void deleteCustomerById(long cust_id) {
		Session session=null;
	try {
		session=getCurrentSession();
		Transaction tx = session.beginTransaction();
		Customer cus = (Customer)session.get(Customer.class, cust_id);
		session.delete(cus);
//		tx.commit();
		} catch (HibernateException e) {
			e.printStackTrace();
		}finally{
//			session.close();
		}
	}

	@Override
	public void saveCustomer(Customer customer) {
		Session session=null;
	try {
		session = this.getCurrentSession();
		Transaction tx = session.beginTransaction();
		session.save(customer);
//		tx.commit();
		}
		catch (HibernateException e) {
			e.printStackTrace();
		}finally {
//			session.close();
		}
		
	}
	@Override
	public Login find(Login vo) {
		
		Session session=null;
		Login login=null;
		try {
		String sql="from Login where username = :username and password = :password";
		session = this.getCurrentSession();
		Transaction tx = session.beginTransaction();
		Query query = session.createQuery(sql);
		query.setParameter("username", vo.getUsername());
		query.setParameter("password", vo.getPassword());
	    login=(Login) query.uniqueResult();
//		tx.commit();	
		} catch (HibernateException e) {
			e.printStackTrace();
		}finally {
//			session.close();
		}
		return  login;
	}	
	
}

Customer.java

package com.shiep.pojo;
import java.util.Date;
public class Customer {
	@Override
	public String toString() {
	return "Customer [cust_id=" + cust_id + ", cust_name=" + cust_name + ", cust_user_id=" + cust_user_id
			+ ", cust_create_id=" + cust_create_id + ", cust_source=" + cust_source + ", cust_industry="
			+ cust_industry + ", cust_level=" + cust_level + ", cust_linkman=" + cust_linkman + ", cust_phone="
			+ cust_phone + ", cust_mobile=" + cust_mobile + ", cust_zipcode=" + cust_zipcode + ", cust_address="
			+ cust_address + ", cust_createtime=" + cust_createtime + "]";
	}
	private Long cust_id;
	private String cust_name;
	private Long cust_user_id;
	private Long cust_create_id;
	private String cust_source;
	private String cust_industry;
	private String cust_level;
	private String cust_linkman;
	private String cust_phone;
	private String cust_mobile;
	private String cust_zipcode;
	private String cust_address;
	private Date cust_createtime;
	public Long getCust_id() {
		return cust_id;
	}
	public void setCust_id(Long cust_id) {
		this.cust_id = cust_id;
	}
	public String getCust_name() {
		return cust_name;
	}
	public void setCust_name(String cust_name) {
		this.cust_name = cust_name;
	}
	public Long getCust_user_id() {
		return cust_user_id;
	}
	public void setCust_user_id(Long cust_user_id) {
		this.cust_user_id = cust_user_id;
	}
	public Long getCust_create_id() {
		return cust_create_id;
	}
	public void setCust_create_id(Long cust_create_id) {
		this.cust_create_id = cust_create_id;
	}
	public String getCust_source() {
		return cust_source;
	}
	public void setCust_source(String cust_source) {
		this.cust_source = cust_source;
	}
	public String getCust_industry() {
		return cust_industry;
	}
	public void setCust_industry(String cust_industry) {
		this.cust_industry = cust_industry;
	}
	public String getCust_level() {
		return cust_level;
	}
	public void setCust_level(String cust_level) {
		this.cust_level = cust_level;
	}
	public String getCust_linkman() {
		return cust_linkman;
	}
	public void setCust_linkman(String cust_linkman) {
		this.cust_linkman = cust_linkman;
	}
	public String getCust_phone() {
		return cust_phone;
	}
	public void setCust_phone(String cust_phone) {
		this.cust_phone = cust_phone;
	}
	public String getCust_mobile() {
		return cust_mobile;
	}
	public void setCust_mobile(String cust_mobile) {
		this.cust_mobile = cust_mobile;
	}
	public String getCust_zipcode() {
		return cust_zipcode;
	}
	public void setCust_zipcode(String cust_zipcode) {
		this.cust_zipcode = cust_zipcode;
	}
	public String getCust_address() {
		return cust_address;
	}
	public void setCust_address(String cust_address) {
		this.cust_address = cust_address;
	}
	public Date getCust_createtime() {
		return cust_createtime;
	}
	public void setCust_createtime(Date cust_createtime) {
		this.cust_createtime = cust_createtime;
	}


}

Login.java

package com.shiep.pojo;
public class Login {
	Integer Id;
	String username;
	String password;
	String picture;
	public Integer getId() {
		return Id;
	}
	public void setId(Integer id) {
		Id = id;
	}
	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;
	}
	@Override
	public String toString() {
		return "Login [Id=" + Id + ", username=" + username + ", password=" + password + ", picture=" + picture + "]";
	}
	public String getPicture() {
		return picture;
	}
	public void setPicture(String picture) {
		this.picture = picture;
	}
}

QueryVo.java

package com.shiep.pojo;
public class QueryVo {
	private String custName;
	private String custSource;
	private String custIndustry;
	private String custLevel;
	
	public String getCustName() {
		return custName;
	}
	public void setCustName(String custName) {
		this.custName = custName;
	}
	
	public String getCustSource() {
		return custSource;
	}
	public void setCustSource(String custSource) {
		this.custSource = custSource;
	}
	public String getCustIndustry() {
		return custIndustry;
	}
	public void setCustIndustry(String custIndustry) {
		this.custIndustry = custIndustry;
	}
	public String getCustLevel() {
		return custLevel;
	}
	public void setCustLevel(String custLevel) {
		this.custLevel = custLevel;
	}
}

Customer.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.shiep.pojo">
	<class name="Customer" table="customer">
		<id name="cust_id" column="cust_id">
			<generator class="native">
			</generator>
		</id>
		<property name="cust_name" />
		<property name="cust_user_id" />
		<property name="cust_create_id" />
		<property name="cust_source" />
		<property name="cust_industry" />
		<property name="cust_level" />
		<property name="cust_linkman" />
		<property name="cust_phone" />
		<property name="cust_mobile" />
		<property name="cust_zipcode" />
		<property name="cust_address" />
		<property name="cust_createtime" />
	</class>
	
</hibernate-mapping>

Login.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.shiep.pojo">
	<class name="Login" table="login">
		<id name="Id" column="Id">
			<generator class="native">
			</generator>
		</id>
		<property name="username" />
		<property name="password" />
		<property name="picture" />
	</class>	
</hibernate-mapping>

CustomerService .java

package com.shiep.service;
import java.util.List;
import com.shiep.pojo.Customer;
import com.shiep.pojo.Login;
import com.shiep.pojo.QueryVo;
public interface CustomerService {
	public List<Customer> selectAll(QueryVo queryVo);
	public  Customer selectCustomerById(long cust_id);
	public void updateCustomerById(Customer customer);
	public void deleteCustomerById(long cust_id);
	public void saveCustomer(Customer customer);
	public Login findLogin(Login vo);		
}

CustomerServiceImpl.java

package com.shiep.service;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.shiep.dao.CustomerDao;
import com.shiep.pojo.Customer;
import com.shiep.pojo.Login;
import com.shiep.pojo.QueryVo;
@Service("customerService")
@Transactional
public class CustomerServiceImpl implements CustomerService {
	@Resource(name="customerDao")
	private CustomerDao customerDao;

		@Override
		public Customer selectCustomerById(long cust_id) {
			return customerDao.selectCustomerById(cust_id);
		}

		@Override
		public void updateCustomerById(Customer customer) {
			customerDao.updateCustomerById(customer);
		}

		@Override
		public void deleteCustomerById(long cust_id) {
			customerDao.deleteCustomerById(cust_id);
			
		}
		@Override
		public void saveCustomer(Customer customer) {
			customerDao.saveCustomer(customer);
			
		}
		@Override
		public List<Customer> selectAll(QueryVo queryVo) {
			
			return customerDao.customerList(queryVo);
		}

		@Override
		public Login findLogin(Login vo) {
			return customerDao.find(vo);
			
			
		}
}
	

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
	http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
	
	<!-- 配置扫描 -->
	<context:component-scan base-package="com.shiep.dao" />
	<context:component-scan base-package="com.shiep.service" />
	<context:component-scan base-package="com.shiep.action" />
	<context:component-scan base-package="com.shiep.common" />
    

	<!-- 配置 读取properties文件 jdbc.properties -->
	<context:property-placeholder location="classpath:jdbc.properties" ignore-unresolvable="true" /> 
	
	<!-- 配置 数据源 -->
	<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
		<property name="driverClassName" value="${jdbc.driver}" />
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
	</bean>

	 <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource">
        </property>
        <property name="mappingResources">
            <list>                 
                <value>com/shiep/pojo/Customer.hbm.xml</value>                    
                <value>com/shiep/pojo/Login.hbm.xml</value>                    
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop> 
 				<prop key="hibernate.format_sql">true</prop>  
  			    <prop key="hibernate.use_sql_comments">false</prop> 
  			    <prop key="current_session_context_class">thread</prop>
            </props>
        </property>
    </bean>
		<!-- 核心事务管理器 -->
	<bean name="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager" >
		<property name="sessionFactory" ref="sessionFactory" ></property>
	</bean>
	
	<tx:annotation-driven transaction-manager="transactionManager" />
	 
</beans>

jdbc.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/curd?characterEncoding=utf-8
jdbc.username=root
jdbc.password=admin

struts.xml

<?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.devMode" value="true" />
  <constant name="struts.i18n.encoding" value="UTF-8"></constant>
  
  <constant name="struts.objectFactory" value="spring"/>

  
  <package name="basicstruts" extends="struts-default">
  
  <action name="CustomerAction_login" class="customerAction" method="login">
  	<result name="login">main.jsp</result>
  	<result name="error">error.jsp</result>
  </action>
  <action name="CustomerAction_save" class="customerAction" method="save">
  	<result name="save" type="redirect">CustomerAction_list</result>
  </action>
  <action name="CustomerAction_delete" class="customerAction" method="delete">
  	<result name="delete" type="redirect">CustomerAction_list</result>
  </action>
  <action name="CustomerAction_update" class="customerAction" method="update_">
  	<result name="update" type="redirect">CustomerAction_list</result>
  </action>
  <action name="CustomerAction_edit" class="customerAction" method="edit">
  	<result name="edit" >update.jsp</result>
  </action>
  <action name="CustomerAction_list" class="customerAction" method="list">
    <result name="list" >list.jsp</result>
  </action>
</package>
</struts>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <display-name>ssh_curd</display-name>
  
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  	<!-- 配置spring -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext.xml</param-value>
	</context-param>

	<!-- 配置监听器加载spring -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<!-- 配置过滤器,解决post的乱码问题 -->
	<filter>
		<filter-name>encoding</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>encoding</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	<filter>
	   <filter-name>SpringOpenSessionInViewFilter</filter-name>
	   <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
	 </filter>
  <filter-mapping>
    <filter-name>SpringOpenSessionInViewFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录页面</title>
</head>
<body>
<form action="<%=basePath %>CustomerAction_login.action" method="post">
    	<table>
    		<tr>
    			<td>用户名</td>
    			<td><input type="text" name="vo.username"></td>
    		</tr>
    		<tr>
    			<td>密码</td>
    			<td><input type="password" name="vo.password"></td>
    		</tr>
    		<tr>
    			<td><input type="submit" value="登陆"></td>
    		</tr>
    	</table>
    </form>
</body>
</html>

list.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>显示客户信息</title>
</head>
<body>
	<h1>客户管理系统 </h1>
<form action="<%=basePath %>CustomerAction_list.action" method="post">
客户名称:<input type="text"   name="queryVo.custName" ><br/>
客户来源:
<select name="queryVo.custSource" >
<option value="">--请选择--</option>
<option value="6">电话营销</option>
<option value="7">网络营销</option>
</select><br/>
所属行业:
<select  name="queryVo.custIndustry">
<option value="">--请选择--</option>
<option value="1">教育培训</option>
<option value="2">电子商务</option>
<option value="3">对外贸易</option>
<option value="4">酒店旅游</option>
<option value="5">房地产</option>
</select><br/>
客户级别:
<select  name="queryVo.custLevel">
<option value="">--请选择--</option>
<option value="22">普通客户</option>
<option value="23">VIP客户</option>
</select><br/>
<button type="submit"  onclick="window.location.href='<%=basePath %>CustomerAction_list.action'">查询</button>
</form>
	<h3>客户信息</h3>
	<table border='1'>
		<tr>
			<td>ID</td><td>客户名称</td><td>客户来源</td><td>客户所属行业</td><td>客户级别</td><td>固定电话</td><td>手机</td><td>操作</td>
		</tr>
			<s:iterator value="#listAll" id="c" >
				<tr>
					<td><s:property value="#c.cust_id"/></td>
					<td><s:property value="#c.cust_name"/></td>
					<td><s:property value="#c.cust_source"/></td>
					<td><s:property value="#c.cust_industry"/></td>
					<td><s:property value="#c.cust_level"/></td>
					<td><s:property value="#c.cust_phone"/></td>
					<td><s:property value="#c.cust_mobile"/></td>
					
					<td>
						<a href="<s:url action="CustomerAction_delete"><s:param name="cust_id"><s:property value="#c.cust_id"/></s:param>
						</s:url>">删除</a>
					</td>
					<td>
						<a href="<s:url action="CustomerAction_edit"><s:param name="cust_id"><s:property value="#c.cust_id"/></s:param>
						</s:url>">修改</a>
					</td>
				</tr>
			</s:iterator>
	</table>
	<a href="main.jsp">返回主页面</a>
	<s:debug></s:debug>
</body>
</html>

main.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>主页</title>
  </head>
  <body>
    <h1><font color="red">欢迎</font></h1>
    <s:a href="save.jsp">保存客户</s:a><br/>
    <s:a href="CustomerAction_list.action">客户列表</s:a>
  </body>
</html>

save.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>

    <title>保存客户</title>

  </head>
  <body>
    <h1><font color="red">保存客户</font></h1>
     <form action="CustomerAction_save" method="post" enctype = "multipart/form-data">
        <input type="hidden" name="method:save">
        cust_name:<input type="text" name="customer.cust_name"> <br/>
        cust_source:<input type="text" name="customer.cust_source"> <br/>
        cust_industry:<input type="text" name="customer.cust_industry"> <br/>
        cust_level:<input type="text" name="customer.cust_level"> <br/>
        cust_phone:<input type="text" name="customer.cust_phone"> <br/>
        cust_mobile:<input type="text" name="customer.cust_mobile"> <br/>
        <input type="submit" name="submit" value="提交">
     </form> <br/>
  </body>
</html>

update.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改客户信息</title>
</head>
<body>
     <s:form action="CustomerAction_update" method="post" >
		<h4><s:text name="修改客户信息"></s:text></h4>
		<s:actionerror/>
		<s:textfield  name="customer.cust_id" value ="%{#customer.cust_id}" label="cust_id" readonly="true"></s:textfield>
		<s:textfield  name="customer.cust_name" value ="%{#customer.cust_name}" label="cust_name"></s:textfield>
		<s:textfield  name="customer.cust_source" value ="%{#customer.cust_source}" label="cust_source"></s:textfield>
		<s:textfield  name="customer.cust_industry" value ="%{#customer.cust_industry}" label="cust_industry"></s:textfield>
		<s:textfield  name="customer.cust_level" value ="%{#customer.cust_level}" label="cust_level"></s:textfield>
		<s:textfield  name="customer.cust_phone" value ="%{#customer.cust_phone}" label="cust_phone"></s:textfield>
		<s:textfield  name="customer.cust_mobile" value ="%{#customer.cust_mobile}"  label="cust_mobile"></s:textfield>
		<s:submit value="提交"/>
	</s:form>
</body>
</html>

customer表

# Host: 127.0.0.1  (Version: 5.5.15)
# Date: 2018-05-15 18:11:59
# Generator: MySQL-Front 5.3  (Build 4.269)

/*!40101 SET NAMES utf8 */;

#
# Structure for table "customer"
#

DROP TABLE IF EXISTS `customer`;
CREATE TABLE `customer` (
  `cust_id` bigint(32) NOT NULL AUTO_INCREMENT COMMENT '客户编号(主键)',
  `cust_name` varchar(32) DEFAULT NULL COMMENT '客户名称(公司名称)',
  `cust_user_id` bigint(32) DEFAULT NULL COMMENT '负责人id',
  `cust_create_id` bigint(32) DEFAULT NULL COMMENT '创建人id',
  `cust_source` varchar(32) DEFAULT NULL COMMENT '客户信息来源',
  `cust_industry` varchar(32) DEFAULT NULL COMMENT '客户所属行业',
  `cust_level` varchar(32) DEFAULT NULL COMMENT '客户级别',
  `cust_linkman` varchar(64) DEFAULT NULL COMMENT '联系人',
  `cust_phone` varchar(64) DEFAULT NULL COMMENT '固定电话',
  `cust_mobile` varchar(16) DEFAULT NULL COMMENT '移动电话',
  `cust_zipcode` varchar(10) DEFAULT NULL,
  `cust_address` varchar(100) DEFAULT NULL,
  `cust_createtime` datetime DEFAULT NULL COMMENT '创建时间',
  PRIMARY KEY (`cust_id`),
  KEY `FK_cst_customer_create_id` (`cust_create_id`),
  KEY `FK_cst_customer_industry` (`cust_industry`),
  KEY `FK_cst_customer_level` (`cust_level`),
  KEY `FK_cst_customer_source` (`cust_source`),
  KEY `FK_cst_customer_user_id` (`cust_user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=184 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;

#
# Data for table "customer"
INSERT INTO `customer` VALUES (36,'令狐冲',NULL,NULL,'6','5','23',NULL,'0108888887','13888888888',NULL,NULL,NULL)

login表

# Host: 127.0.0.1  (Version: 5.5.15)
# Date: 2018-05-15 18:12:15
# Generator: MySQL-Front 5.3  (Build 4.269)

/*!40101 SET NAMES gb2312 */;

#
# Structure for table "login"
#

DROP TABLE IF EXISTS `login`;
CREATE TABLE `login` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) DEFAULT NULL,
  `password` varchar(255) DEFAULT NULL,
  `picture` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`Id`),
  KEY `Id` (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT;

#
# Data for table "login"
#

INSERT INTO `login` VALUES (1,'1','1','1'),(2,'admin','admin',NULL);

 


                                    



                                    

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值