短学期第一篇随笔

短学期进行了三天,感觉每天都比较轻松。

 

第一天只做了两件事:上午安装My Eclipse 配置了tomcat,下午配置了项目的Hibernate和Spring功能。可能是起步比较不容易的原因吧,导致老师的大部分时间是在帮助每一个同学解决问题,所以进度比较慢。

tomcat页面:

 

第二天:上午配置了navicat,这个软件和Sql功能相似,都是管理数据库的。下午写了一些代码:

Customer.java的代码:

package com.crm.bean;

public class Customer {
 private int ID;
 private String Custno;
 private String Cusname;
 private String Cussex;
 public int getID() {
  return ID;
 }
 public void setID(int id) {
  ID = id;
 }
 public String getCustno() {
  return Custno;
 }
 public void setCustno(String custno) {
  Custno = custno;
 }
 public String getCusname() {
  return Cusname;
 }
 public void setCusname(String cusname) {
  Cusname = cusname;
 }
 public String getCussex() {
  return Cussex;
 }
 public void setCussex(String cussex) {
  Cussex = cussex;
 }

}

 

Customer.hbm.xml的代码:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC    
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"   
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">  
         
         
<hibernate-mapping>
 <class name="com.crm.bean.Customer" table="Cust">
  <id name="ID" type="java.lang.Integer" column="ID">
   <generator class="increment"></generator>
  </id>
  <property name="Custno" type="string" column="Custno" length="20"/>
  <property name="Cusname" type="string" column="Cusname" length="80"/>
     <property name="Cussex" type="string" column="Cussexsex" length="2"/>
  <!--<property name="age" type="int" column="age"/>
  <property name="telephone" type="string" column="telephone" length="20"/>
  <property name="position" type="string" column="position" length="80"/>
  <property name="logindate" type="string" column="logindate" length="10"/>-->
 </class>
</hibernate-mapping>

 

CustomerDao.java的代码:

package com.crm.dao;
import java.util.List;
import com.crm.bean.Customer;

public interface CustomerDao {

 /**
  * 保存客户信息
  * @param cust
  */
 public void saveCustomer(Customer customer);
 /**
  * 删除客户信息
  * @param cust
  */
 public void removeCustomer(Customer customer);
 /**
  * 查询客户信息
  * @param ID
  * @return
  */
 public Customer findCustomerById(Integer ID);
 /**
  * 查询所有客户信息
  * @return
  */
 public List<Customer> findAllCustomer();

}

 

CustomerDaoImpl.java的代码:

package com.crm.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.crm.bean.Customer;
import com.crm.dao.CustomerDao;

public class CustomerDaoImpl extends HibernateDaoSupport implements CustomerDao{
 
 
 @SuppressWarnings("unchecked")
 public List<Customer> findAllCustomer() {
  // TODO Auto-generated method stub
  String hql = "from Customer cust order by cust.id desc";
  return (List<Customer>)this.getHibernateTemplate().find(hql);
 }

 public Customer findCustomerById(Integer id) {
  // TODO Auto-generated method stub
  Customer customer = (Customer)this.getHibernateTemplate().get(Customer.class,id);
  return customer;
 }

 public void removeCustomer(Customer customer) {
  // TODO Auto-generated method stub
  this.getHibernateTemplate().delete(customer);
 }

 public void saveCustomer(Customer customer) {
  // TODO Auto-generated method stub
  this.getHibernateTemplate().save(customer);
 }
}

在做的过程中,我犯了很多错误,导致编译不通过,其中有一些是打错字的问题,还有一个是将Hibernate和Spring进行连接的时候,有一个文件多余了,没有删掉。

 

第三天:

写了CustomerService.java的代码:

 

package com.crm.service;

 

import java.util.List;

 

import com.crm.bean.Customer;
import com.crm.dao.CustomerDao;

 

public interface CustomerService {
 
 
 /**
  * 保存客户信息
  * @param cust
  */
 public void saveCustomer(Customer customer);
 /**
  * 删除客户信息
  * @param cust
  */
 public void removeCustomer(Customer customer);
 /**
  * 查询客户信息
  * @param ID
  * @return
  */
 public Customer findCustomerById(Integer ID);
 /**
  * 查询所有客户信息
  * @return
  */
 public List<Customer> findAllCustomer();

 


}

 

CustomerServiceImpl.java的代码:

package com.crm.service.impl;

import java.util.List;

import com.crm.bean.Customer;
import com.crm.dao.CustomerDao;
import com.crm.service.CustomerService;

public class CustomerServiceImpl implements CustomerService {
 
 CustomerDao customerdao;
 
 public CustomerDao getCustomerDao() {
  return customerdao;
 }
 
 public void setCustomerdao(CustomerDao customerdao) {
  this.customerdao = customerdao;
 }

 public List<Customer> findAllCustomer() {
  // TODO Auto-generated method stub
  return this.customerdao.findAllCustomer();
 }

 public Customer findCustomerById(Integer ID) {
  // TODO Auto-generated method stub
  return this.findCustomerById(ID);
 }

 public void removeCustomer(Customer customer) {
  // TODO Auto-generated method stub
  this.customerdao.removeCustomer(customer);
 }

 public void saveCustomer(Customer customer) {
  // TODO Auto-generated method stub
  this.customerdao.saveCustomer(customer);
 }

}

strtus.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>
 <package name="customer" extends="struts-default">
  <!-- 保存 -->
  <action name="saveCustomer" class="saveCustomerAcion">
   <result name="success" type="redirect">/jsp/customerInfo.jsp</result>
   <result name="input">/customerAdd.jsp</result>
  </action>
  <!-- 查询 -->
  <action name="listCustomer" class="listCustomerAcion">
   <result>/jsp/customerInfo.jsp</result>
  </action>
  <!-- 删除 -->
  <action name="delectCustomer" class="removeCustomerAcion">
   <result>/jsp/customerInfo.jsp</result>
  </action>
  <!-- typeAcion下拉列表 -->
  <action name="typeAction" class="typeAction">
   <result></result>
  </action>
 </package>
</struts>

 

还写了一个jsp:

<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!-- 下拉菜单 -->
<s:action name="typeAction" id="list"></s:action>
<!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=ISO-8859-1">
<title>新增客户信息</title>
<style>
.divcss5{width:600px;height:100px;border:1px solid #000}
</style>
</head>
<body>
<center>
<s:form action="saveCustomer">
<s:textfield name="customer.Custno" label="客户编号"></s:textfield>
<s:textfield name="customer.Cusname" label="客户名称"></s:textfield>
<s:textfield name="customer.Custele" label="客户号码"></s:textfield>
<s:submit value="保存"></s:submit>
</s:form>
</center>
</body>
</html>

结果如图:

 

posted on 2017-06-28 15:04  F_Victor  阅读(115)  评论(0)    收藏  举报

导航