标签:lods let next phone 注意 字段 admin ffffff lock
实体类
public class Supplier {
private int id;
private String supplierid;
private String suppliernane;
private String description;
private String phone;
private String address;
private Date starttine;
private String company;
private int remark;
getset方法
}
数据库
dao
public interface SupplierDao {
//查询,供应商列表只显示正在合作的供应商
public List<Supplier> list();
//添加,添加时,不允许显现的添加供应商编号(不允许手动添加)
/*
* Remark字段:用于表示该供应商是否正在合作
* 0:表示暂时中止合作
* 1:表示正在合作
* 注意:添加供应商时,默认remark值为1,即正在合作,
* 对remark的处理方式:
* 1》在dao类里赋值时,写死值为1
* 2》在数据库表中,将remark列设置一下默认值为1
* */
public void supAdd(Supplier supplier);
/*删除时,进行逻辑删除(根据主键将该条数据不再显示在列表)
物理删除:真正从数据库表中删除掉数据,即表中不存在这条数据了
逻辑删除:并不真正从数据库表删掉数据,而是换一种方式显示
执行逻辑删除之后,即暂时中止和某供应商合作,那么供应商列表不再显示该条数据,
执行逻辑删除就是将remark的值由1变为0,其实就是修改remark字段的功能
*/
public Supplier supdelete(int id);
//修改回显
//修改时,不允许修改供应商编号
public Supplier suptoupdate(Supplier supplier);
//修改
public void supddupdate(Supplier supplier);
//重新合作查询
public List<Supplier> newlist();
//重新合作
public Supplier newsupplier(Supplier supplier);
//物理删除彻底删除
public Supplier newdelete(int id);
//正在合作供应商模糊查询
public List<Supplier> supplierslike(Supplier supplier);
//解除合作供应商模糊查询
public List<Supplier> lodsupplierslike(Supplier supplier);
}
daoImpl
public class SupplieDaoImpl implements SupplierDao {
private Connection connection=null;
private PreparedStatement p = null;
private ResultSet set = null;
public Connection getConnection() {
return connection;
}
public void setConnection(Connection connection) {
this.connection = connection;
}
public PreparedStatement getP() {
return p;
}
public void setP(PreparedStatement p) {
this.p = p;
}
public ResultSet getSet() {
return set;
}
public void setSet(ResultSet set) {
this.set = set;
}
/* 供应商列表只显示正在合作的供应商
即查询列表时,执行的是select * from t_supplier where remark=1
*/
@Override
public List<Supplier> list() {
// TODO Auto-generated method stub
try {
connection = DBUtil.getConnection();
String sqlString = "select starttine,address,company,description,id,phone,remark,supplierid,suppliernane from T_SUPPLIER where remark = 1";
p = connection.prepareStatement(sqlString);
set = p.executeQuery();
List<Supplier> list = new ArrayList<Supplier>();
while(set.next()){
Supplier s = new Supplier();
s.setStarttine(set.getDate("starttine"));
s.setAddress(set.getString("address"));
s.setCompany(set.getString("company"));
s.setDescription(set.getString("description"));
s.setId(set.getInt("id"));
s.setPhone(set.getString("phone"));
s.setRemark(set.getInt("remark"));
s.setSupplierid(set.getString("supplierid"));
s.setSuppliernane(set.getString("suppliernane"));
list.add(s);
}
return list;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
public void supAdd(Supplier supplier) {
// TODO Auto-generated method stub
try {
connection = DBUtil.getConnection();
String sql = "insert into t_supplier(id,supplierid,suppliernane,description,phone,address,starttine,company,remark) values(t_supplier_id.nextval,?,?,?,?,?,sysdate,?,1)";
p = connection.prepareStatement(sql);
p.setString(1, UUIDUtil.getUUID());
p.setString(2, supplier.getSuppliernane());
p.setString(3, supplier.getDescription());
p.setString(4, supplier.getPhone());
p.setString(5, supplier.getAddress());
p.setString(6, supplier.getCompany());
p.execute();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public Supplier supdelete(int id) {
// TODO Auto-generated method stub
try {
connection = DBUtil.getConnection();
String sql = "update t_supplier set remark=0 where id=?";
p = connection.prepareStatement(sql);
p.setInt(1, id);
p.execute();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
public Supplier suptoupdate(Supplier supplier) {
// TODO Auto-generated method stub
try {
connection = DBUtil.getConnection();
String sql = "select * from T_SUPPLIER where id=?";
p = connection.prepareStatement(sql);
p.setInt(1, supplier.getId());
set = p.executeQuery();
Supplier su = new Supplier();//实体
while(set.next()){
su.setStarttine(set.getDate("starttine"));
su.setAddress(set.getString("address"));
su.setCompany(set.getString("company"));
su.setDescription(set.getString("description"));
su.setId(set.getInt("id"));
su.setPhone(set.getString("phone"));
su.setRemark(set.getInt("remark"));
su.setSupplierid(set.getString("supplierid"));
su.setSuppliernane(set.getString("suppliernane"));
}
return su;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
public void supddupdate(Supplier supplier) {
// TODO Auto-generated method stub
try {
connection = DBUtil.getConnection();
String sql = "update t_supplier set suppliernane=?,description=?,phone=?,address=?,company=? where id=?";
p = connection.prepareStatement(sql);
p.setString(1, supplier.getSuppliernane());
p.setString(2, supplier.getDescription());
p.setString(3, supplier.getPhone());
p.setString(4, supplier.getAddress());
p.setString(5, supplier.getCompany());
p.setInt(6, supplier.getId());
System.out.println("-----p:"+p.toString());
p.execute();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public List<Supplier> newlist() {
// TODO Auto-generated method stub
try {
connection = DBUtil.getConnection();
String sql = "select starttine,address,company,description,id,phone,remark,supplierid,suppliernane from T_SUPPLIER where remark = 0";
p = connection.prepareStatement(sql);
set = p.executeQuery();
List<Supplier> newlist = new ArrayList<Supplier>();
while(set.next()){
Supplier supplier = new Supplier();
supplier.setStarttine(set.getDate("starttine"));
supplier.setAddress(set.getString("address"));
supplier.setCompany(set.getString("company"));
supplier.setDescription(set.getString("description"));
supplier.setId(set.getInt("id"));
supplier.setPhone(set.getString("phone"));
supplier.setRemark(set.getInt("remark"));
supplier.setSupplierid(set.getString("supplierid"));
supplier.setSuppliernane(set.getString("suppliernane"));
newlist.add(supplier);
}
return newlist;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
public Supplier newsupplier(Supplier supplier) {
// TODO Auto-generated method stub
try {
connection = DBUtil.getConnection();
String sql = "update t_supplier set remark=1 where id=?";
p = connection.prepareStatement(sql);
p.setInt(1, supplier.getId());
p.execute();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
public Supplier newdelete(int id) {
// TODO Auto-generated method stub
try {
connection = DBUtil.getConnection();
String sql = "delete from t_supplier where id=?";
p = connection.prepareStatement(sql);
p.setInt(1, id);
p.execute();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
//正在合作供应商模糊查询
@Override
public List<Supplier> supplierslike(Supplier supplier) {
// TODO Auto-generated method stub
try {
connection = DBUtil.getConnection();
String sql = "select * from T_SUPPLIER where SUPPLIERNANE like ‘%"+supplier.getSuppliernane()+"%‘"
+ "and DESCRIPTION like ‘%"+supplier.getDescription()+"%‘ and REMARK = 1";
p = connection.prepareStatement(sql);
List<Supplier> list = new ArrayList<>();
set = p.executeQuery();
while(set.next()){
Supplier supplie1 = new Supplier();
supplie1.setStarttine(set.getDate("starttine"));
supplie1.setAddress(set.getString("address"));
supplie1.setCompany(set.getString("company"));
supplie1.setDescription(set.getString("description"));
supplie1.setId(set.getInt("id"));
supplie1.setPhone(set.getString("phone"));
supplie1.setRemark(set.getInt("remark"));
supplie1.setSupplierid(set.getString("supplierid"));
supplie1.setSuppliernane(set.getString("suppliernane"));
list.add(supplie1);
}
return list;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
//解除合作供应商模糊查询
@Override
public List<Supplier> lodsupplierslike(Supplier supplier) {
// TODO Auto-generated method stub
try {
connection = DBUtil.getConnection();
String sql = "select * from T_SUPPLIER where SUPPLIERNANE like ‘%"+supplier.getSuppliernane()+"%‘"
+ "and DESCRIPTION like ‘%"+supplier.getDescription()+"%‘ and REMARK = 0";
p = connection.prepareStatement(sql);
List<Supplier> list = new ArrayList<>();
set = p.executeQuery();
while(set.next()){
Supplier supplie1 = new Supplier();
supplie1.setStarttine(set.getDate("starttine"));
supplie1.setAddress(set.getString("address"));
supplie1.setCompany(set.getString("company"));
supplie1.setDescription(set.getString("description"));
supplie1.setId(set.getInt("id"));
supplie1.setPhone(set.getString("phone"));
supplie1.setRemark(set.getInt("remark"));
supplie1.setSupplierid(set.getString("supplierid"));
supplie1.setSuppliernane(set.getString("suppliernane"));
list.add(supplie1);
}
return list;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
service
public interface SupplierServlice {
public List<Supplier> list();
public void supAdd(Supplier supplier);
public Supplier supdelete(int id);
//修改页面
public Supplier supplier(Supplier supplier);
public void supddupdate(Supplier supplier);
//重新合作查询
public List<Supplier> newlist();
//重新合作
public Supplier newsupplier(Supplier supplier);
//彻底结束合作
public Supplier newdelete(int id);
//正在合作供应商模糊查询
public List<Supplier> supplierslike(Supplier supplier);
//解除合作供应商模糊查询
public List<Supplier> lodsupplierslike(Supplier supplier);
}
serviceImpl
public class SupplierServiceImpl implements SupplierServlice {
private SupplierDao s = new SupplieDaoImpl();
@Override
public List<Supplier> list() {
// TODO Auto-generated method stub
return s.list();
}
public SupplierDao getS() {
return s;
}
public void setS(SupplierDao s) {
this.s = s;
}
@Override
public void supAdd(Supplier supplier) {
// TODO Auto-generated method stub
s.supAdd(supplier);
}
@Override
public Supplier supdelete(int id) {
// TODO Auto-generated method stub
return s.supdelete(id);
}
@Override
public Supplier supplier(Supplier supplier) {
// TODO Auto-generated method stub
return s.suptoupdate(supplier);
}
@Override
public void supddupdate(Supplier supplier) {
// TODO Auto-generated method stub
s.supddupdate(supplier);
}
@Override
public List<Supplier> newlist() {
// TODO Auto-generated method stub
return s.newlist();
}
@Override
public Supplier newsupplier(Supplier supplier) {
// TODO Auto-generated method stub
return s.newsupplier(supplier);
}
@Override
public Supplier newdelete(int id) {
// TODO Auto-generated method stub
return s.newdelete(id);
}
//正在合作供应商模糊查询
@Override
public List<Supplier> supplierslike(Supplier supplier) {
// TODO Auto-generated method stub
return s.supplierslike(supplier);
}
//解除合作供应商模糊查询
@Override
public List<Supplier> lodsupplierslike(Supplier supplier) {
// TODO Auto-generated method stub
return s.lodsupplierslike(supplier);
}
}
action
public class SupplierAction extends ActionSupport {
private List<Supplier> supplierlist;
private List<Supplier> newsuppList;
private Supplier supplier;
private SupplierServlice supServlice = new SupplierServiceImpl();
public List<Supplier> getSupplierlist() {
return supplierlist;
}
public void setSupplierlist(List<Supplier> supplierlist) {
this.supplierlist = supplierlist;
}
public SupplierServlice getSupServlice() {
return supServlice;
}
public void setSupServlice(SupplierServlice supServlice) {
this.supServlice = supServlice;
}
//重新合作查询
public String newsuppList(){
supplierlist = supServlice.newlist();
return SUCCESS;
}
//重新合作
public String newsupplier(){
supServlice.newsupplier(supplier);
return SUCCESS;
}
//解除合作
public String newdelete(){
supServlice.newdelete(supplier.getId());
return SUCCESS;
}
public String suplist(){
supplierlist = supServlice.list();
return SUCCESS;
}
public String supAdd(){
supServlice.supAdd(supplier);
/*System.out.println("lalala啦啦......");*/
return SUCCESS;
}
public String supdelete(){
supServlice.supdelete(supplier.getId());
return SUCCESS;
}
public String supupdate(){
supplier = supServlice.supplier(supplier);
return SUCCESS;
}
public String supddupdate(){
supServlice.supddupdate(supplier);
System.out.println("supplier-----:"+supplier);
return SUCCESS;
}
//正在合作供应商模糊查询
public String supplierslike(){
ActionContext ac = ActionContext.getContext();
Map<String, Object> session = ac.getSession();
session.put("name", supplier.getSuppliernane());
session.put("desc", supplier.getDescription());
supplierlist = supServlice.supplierslike(supplier);
return SUCCESS;
}
//解除合作供应商模糊查询
public String lodsupplierslike(){
ActionContext ac = ActionContext.getContext();
Map<String, Object> session = ac.getSession();
session.put("name", supplier.getSuppliernane());
session.put("desc", supplier.getDescription());
supplierlist = supServlice.lodsupplierslike(supplier);
return SUCCESS;
}
public Supplier getSupplier() {
return supplier;
}
public void setSupplier(Supplier supplier) {
this.supplier = supplier;
}
public List<Supplier> getNewsuppList() {
return newsuppList;
}
public void setNewsuppList(List<Supplier> newsuppList) {
this.newsuppList = newsuppList;
}
}
struts.xml
<action name="sup_list" class="com.oak.action.SupplierAction" method="suplist">
<result name="success">
/providerAdmin.jsp
</result>
</action>
<action name="supadd" class="com.oak.action.SupplierAction" method="supAdd">
<result name="success" type="redirectAction">
sup_list
</result>
</action>
<action name="supdelete" class="com.oak.action.SupplierAction" method="supdelete">
<result name="success" type="redirectAction">
sup_list
</result>
</action>
<action name="supupdate" class="com.oak.action.SupplierAction" method="supupdate">
<result name="success">
/providerupdate.jsp
</result>
</action>
<action name="supddupdate" class="com.oak.action.SupplierAction" method="supddupdate">
<result name="success" type="redirectAction">
sup_list
</result>
</action>
<!-- 重新合作查询 -->
<action name="newproviderAdd" class="com.oak.action.SupplierAction" method="newsuppList">
<result name="success">
/newproviderAdmin.jsp
</result>
</action>
<!-- 正在合作供应商模糊查询 -->
<action name="supplierslike" class="com.oak.action.SupplierAction" method="supplierslike">
<result name="success">
/providerAdmin.jsp
</result>
</action>
<!-- 解除合作供应商模糊查询 -->
<action name="lodsupplierslike" class="com.oak.action.SupplierAction" method="lodsupplierslike">
<result name="success">
/newproviderAdmin.jsp
</result>
</action>
<!-- 重新合作 -->
<action name="newsupupdate" class="com.oak.action.SupplierAction" method="newsupplier" >
<result name="success" type="redirectAction">
sup_list
</result>
</action>
<action name="newsupdelete" class="com.oak.action.SupplierAction" method="newdelete">
<result name="success" type="redirectAction">
newproviderAdd
</result>
</action>
标签:lods let next phone 注意 字段 admin ffffff lock
原文地址:http://www.cnblogs.com/love1/p/7804415.html