diff --git a/README.md b/README.md deleted file mode 100644 index 6077a77..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# watermonitor_Git - diff --git a/model/水质展示第一次迭代uml顺序图.png b/model/水质展示第一次迭代uml顺序图.png new file mode 100644 index 0000000..9c89407 Binary files /dev/null and b/model/水质展示第一次迭代uml顺序图.png differ diff --git a/model/水质展示第二次迭代uml顺序图.png b/model/水质展示第二次迭代uml顺序图.png new file mode 100644 index 0000000..0c0b015 Binary files /dev/null and b/model/水质展示第二次迭代uml顺序图.png differ diff --git a/model/水质预警第一次迭代uml顺序图.png b/model/水质预警第一次迭代uml顺序图.png new file mode 100644 index 0000000..9624fcb Binary files /dev/null and b/model/水质预警第一次迭代uml顺序图.png differ diff --git a/model/水质预警第二次迭代uml顺序图.png b/model/水质预警第二次迭代uml顺序图.png new file mode 100644 index 0000000..ab0c36d Binary files /dev/null and b/model/水质预警第二次迭代uml顺序图.png differ diff --git a/other/200340034 杨世豪 实践总结报告.docx b/other/200340034 杨世豪 实践总结报告.docx new file mode 100644 index 0000000..e6d5ad6 Binary files /dev/null and b/other/200340034 杨世豪 实践总结报告.docx differ diff --git a/other/200340036 易俊弛-实践总结报告.docx b/other/200340036 易俊弛-实践总结报告.docx new file mode 100644 index 0000000..212d994 Binary files /dev/null and b/other/200340036 易俊弛-实践总结报告.docx differ diff --git a/other/软件工程课程设计汇报.pptx b/other/软件工程课程设计汇报.pptx new file mode 100644 index 0000000..d523386 Binary files /dev/null and b/other/软件工程课程设计汇报.pptx differ diff --git a/src/src_houduan/dao/UserDao.java b/src/src_houduan/dao/UserDao.java new file mode 100644 index 0000000..fd33b73 --- /dev/null +++ b/src/src_houduan/dao/UserDao.java @@ -0,0 +1,47 @@ +package dao; + + + +import domain.User; + +import java.util.List; +import java.util.Map; + +/** + * 用户操作的DAO + */ +public interface UserDao { + + + public List findAll(); + + User findUserByUsernameAndPassword(String username, String password); + + void add(User user); + void register(User user); + void updatePassword(User user); + + void delete(int id); + + User findById(int i); + + void update(User user); + + /** + * 查询总记录数 + * @return + * @param condition + */ + int findTotalCount(Map condition); + + /** + * 分页查询每页记录 + * @param start + * @param rows + * @param condition + * @return + */ + List findByPage(int start, int rows, Map condition); + + boolean updateUserInfo(User user); +} diff --git a/src/src_houduan/dao/WaterQualityStationDao.java b/src/src_houduan/dao/WaterQualityStationDao.java new file mode 100644 index 0000000..d0a7d65 --- /dev/null +++ b/src/src_houduan/dao/WaterQualityStationDao.java @@ -0,0 +1,29 @@ +package dao; + + +import domain.StationAndQuality; +import domain.WaterQualityStation; + +import java.util.List; +import java.util.Map; + +public interface WaterQualityStationDao +{ + public abstract List findAll(); + public abstract WaterQualityStation findByName(String stationName); + public abstract WaterQualityStation findIntroByName(String name); + public abstract boolean addWaterQualityStation(WaterQualityStation station); + public abstract List findByPage(int start,int pageSize); + public abstract int findTotalCount(); + public abstract WaterQualityStation findIntroById(int id); + public abstract List conditonalQueryByPage(int start, int pageSize, Map condition); + public abstract int conditionalFindAllCount(Map condition); + public abstract boolean update(WaterQualityStation station); + public abstract boolean delete(int id); + public abstract List findPollutedSite(); + public abstract WaterQualityStation findIntro(double longitude,double latitude); + + public abstract StationAndQuality findStationAndQuality(double longitude,double latitude); + + public abstract List indexing(); +} diff --git a/src/src_houduan/dao/impl/UserDaoImpl.java b/src/src_houduan/dao/impl/UserDaoImpl.java new file mode 100644 index 0000000..7eef482 --- /dev/null +++ b/src/src_houduan/dao/impl/UserDaoImpl.java @@ -0,0 +1,180 @@ +package dao.impl; + + +import domain.User; +import org.springframework.dao.DataAccessException; +import util.JDBCUtils; +import dao.UserDao; +import org.springframework.jdbc.core.BeanPropertyRowMapper; +import org.springframework.jdbc.core.JdbcTemplate; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import domain.User; + +public class UserDaoImpl implements UserDao { + + private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource()); + + @Override + public List findAll() { + //使用JDBC操作数据库... + //1.定义sql + String sql = "select * from user"; + List users = template.query(sql, new BeanPropertyRowMapper(User.class)); + + return users; + } + + @Override + public User findUserByUsernameAndPassword(String username, String password) { + try { + String sql = "select * from user where username = ? and password = ?"; + User user = template.queryForObject(sql, new BeanPropertyRowMapper(User.class), username, password); + return user; + } catch (Exception e) { + System.out.println(e); + return null; + } + + } + + @Override + public void add(User user) { + //1.定义sql + String sql = "insert into user values(null,?,?,?,?,?,?,null,null)"; + //2.执行sql + template.update(sql, user.getName(), user.getGender(), user.getAge(), user.getAddress(), user.getQq(), user.getEmail()); + } + + @Override + public void register(User user)//用户注册 + { + String sql="insert into user (id,age,username,password) values(null,?,?,?)"; + template.update(sql,18,user.getUsername(),user.getPassword()); + + } + + @Override + public void updatePassword(User user)//修改当前用户密码 + { + String sql="update user set password=? where username=?"; + template.update(sql,user.getPassword(),user.getUsername()); + } + + @Override + public void delete(int id) { + //1.定义sql + String sql = "delete from user where id = ?"; + //2.执行sql + template.update(sql, id); + } + + @Override + public User findById(int id) { + String sql = "select * from user where id = ?"; + return template.queryForObject(sql, new BeanPropertyRowMapper(User.class), id); + } + + @Override + public void update(User user) { + String sql = "update user set name = ?,gender = ? ,age = ? , address = ? , qq = ?, email = ? where id = ?"; + template.update(sql, user.getName(), user.getGender(), user.getAge(), user.getAddress(), user.getQq(), user.getEmail(), user.getId()); + } + + @Override + public int findTotalCount(Map condition) { + //1.定义模板初始化sql + String sql = "select count(*) from user where 1 = 1 "; + StringBuilder sb = new StringBuilder(sql); + //2.遍历map + Set keySet = condition.keySet(); + //定义参数的集合 + List params = new ArrayList(); + for (String key : keySet) { + + //排除分页条件参数 + if("currentPage".equals(key) || "rows".equals(key)){ + continue; + } + + //获取value + String value = condition.get(key)[0]; + //判断value是否有值 + if(value != null && !"".equals(value)){ + //有值 + sb.append(" and "+key+" like ? "); + params.add("%"+value+"%");//?条件的值 + } + } + System.out.println(sb.toString()); + System.out.println(params); + + return template.queryForObject(sb.toString(),Integer.class,params.toArray()); + } + + @Override + public List findByPage(int start, int rows, Map condition) { + String sql = "select * from user where 1 = 1 "; + + StringBuilder sb = new StringBuilder(sql); + //2.遍历map + Set keySet = condition.keySet(); + //定义参数的集合 + List params = new ArrayList(); + for (String key : keySet) + { + + //排除分页条件参数 + if("currentPage".equals(key) || "rows".equals(key)) + { + continue; + } + + //获取value + String value = condition.get(key)[0]; + //判断value是否有值 + if(value != null && !"".equals(value)) + { + //有值 + sb.append(" and "+key+" like ? "); + params.add("%"+value+"%");//?条件的值 + } + } + + //添加分页查询 + sb.append(" limit ?,? "); + //添加分页查询参数值 + params.add(start); + params.add(rows); + sql = sb.toString(); + System.out.println(sql); + System.out.println(params); + + return template.query(sql,new BeanPropertyRowMapper(User.class),params.toArray()); + } + + @Override + public boolean updateUserInfo(User user) + { + int update=0; + try { + String sql="update user set name = ?,gender = ? ,age = ? , address = ? , qq = ?, email = ? where id = ?"; + update = template.update(sql, user.getName(), user.getGender(), user.getAge(), + user.getAddress(), user.getQq(), user.getEmail(), user.getId()); + } catch (Exception e) + { + System.out.println(e); + } + if(update!=0) + { + return true; + } + else + { + return false; + } + } +} diff --git a/src/src_houduan/dao/impl/WaterQualityStationDaoImpl.java b/src/src_houduan/dao/impl/WaterQualityStationDaoImpl.java new file mode 100644 index 0000000..9f707d7 --- /dev/null +++ b/src/src_houduan/dao/impl/WaterQualityStationDaoImpl.java @@ -0,0 +1,352 @@ +package dao.impl; + +import dao.WaterQualityStationDao; +import domain.StationAndQuality; +import domain.WaterQuality; +import domain.WaterQualityStation; +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.BeanPropertyRowMapper; +import org.springframework.jdbc.core.JdbcTemplate; +import util.JDBCUtils; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +public class WaterQualityStationDaoImpl implements WaterQualityStationDao +{ + private JdbcTemplate template=new JdbcTemplate(JDBCUtils.getDataSource()); + + @Override + public List findAll() + { + //定义sql + String sql="select * from water_quality_station"; + //执行sql + List station = template.query(sql, new BeanPropertyRowMapper(WaterQualityStation.class)); + return station; + } + + @Override + public WaterQualityStation findByName(String stationName) + { + WaterQualityStation station = null; + try + { + String sql="select * from water_quality_station where stationName=?"; + station = template.queryForObject(sql, new BeanPropertyRowMapper(WaterQualityStation.class), stationName); + } catch (DataAccessException e) + { + System.out.println(e); + } + return station; + } + + @Override + public WaterQualityStation findIntroByName(String name) { + String sql="select * from water_quality_station where stationName=?"; + WaterQualityStation waterQualityStation = template.queryForObject(sql, new BeanPropertyRowMapper(WaterQualityStation.class),name); + return waterQualityStation; + } + + @Override + public boolean addWaterQualityStation(WaterQualityStation station) + { + int update = 0; + try { + String sql="insert into water_quality_station values(null,?,?,?,?,?)"; + update = template.update(sql,station.getStationName(),station.getLongitude(),station.getLatitude(),station.getSection(),station.getIntroduction()); + } catch (DataAccessException e) { + System.out.println(e);; + } + System.out.println(update); + if(update!=0) + { + return true; + } + else + { + return false; + } + + + } + + @Override + public List findByPage(int start, int pageSize) + { + List list=null; + try { + String sql="select * from water_quality_station limit ?,?"; + list = template.query(sql, + new BeanPropertyRowMapper(WaterQualityStation.class), start, pageSize); + } catch (DataAccessException e) { + System.out.println(e); + } + + return list; + } + + @Override + public int findTotalCount() + { + String sql="select count(*) from water_quality_station"; + Integer integer = template.queryForObject(sql, Integer.class); + return integer; + } + + @Override + public WaterQualityStation findIntroById(int id) + { + WaterQualityStation station = null; + try { + String sql="select * from water_quality_station where id=?"; + station = template.queryForObject(sql, new BeanPropertyRowMapper(WaterQualityStation.class), id); + } catch (DataAccessException e) { + System.out.println(e); + } + return station; + } + + @Override + public List conditonalQueryByPage(int start, int pageSize, Map condition) + { + StringBuilder builder=new StringBuilder();//代表整个sql语句 + String starStr="select * from water_quality_station where 1=1 "; + builder.append(starStr); + + List valueList=new ArrayList<>(); + + //遍历map集合 + for(String key:condition.keySet()) + { + + //排除分页条件参数 + if("currentPage".equals(key) || "pageSize".equals(key)) + { + continue; + } + + + String value = condition.get(key)[0]; + if(value!=null&&!"".equals(value)) + { + builder.append(" and "+key+" like ? "); + valueList.add("%"+value+"%"); + + } + } + + + builder.append(" limit ?,? "); + valueList.add(start); + valueList.add(pageSize); + String sql = builder.toString(); + + System.out.println(sql); + System.out.println(valueList); + + //执行sql + List objList = null; + try { + objList = template.query(sql, new BeanPropertyRowMapper(WaterQualityStation.class), valueList.toArray()); + } catch (DataAccessException e) { + System.out.println(e); + } + + return objList; + } + + @Override + public int conditionalFindAllCount(Map condition) + { + StringBuilder builder=new StringBuilder();//代表整个sql语句 + String starStr="select count(*) from water_quality_station where 1=1 "; + builder.append(starStr); + + List valueList=new ArrayList<>(); + + //遍历map集合 + for(String key:condition.keySet()) + { + + //排除分页条件参数 + if("currentPage".equals(key) || "pageSize".equals(key)) + { + continue; + } + + + String value = condition.get(key)[0]; + if(value!=null&&!"".equals(value)) + { + builder.append(" and "+key+" like ? "); + valueList.add("%"+value+"%"); + + } + } + String sql = builder.toString(); + System.out.println(sql); + System.out.println(valueList); + + int integer = 0; + try { + integer = template.queryForObject(sql, Integer.class, valueList.toArray()); + } catch (DataAccessException e) + { + System.out.println(e); + } + + + return integer; + } + + @Override + public boolean update(WaterQualityStation station) + { + int update=0; + try { + String sql="update water_quality_station set stationName=?,longitude=?,latitude=?,section=?,introduction=? where id=?"; + update = template.update(sql, + station.getStationName(), + station.getLongitude(), + station.getLatitude(), + station.getSection(), + station.getIntroduction(), + station.getId()); + } catch (DataAccessException e) { + System.out.println(e); + } + if(update!=0) + { + return true; + } + else + { + return false; + } + } + + @Override + public boolean delete(int id) + { + int update=0; + try { + String sql="delete from water_quality_station where id=?"; + update = template.update(sql, id); + } catch (DataAccessException e) + { + System.out.println(e); + } + if(update!=0) + { + return true; + } + else + { + return false; + } + + } + + @Override + public List findPollutedSite() + { + List list=null; + try + { + String sql="SELECT * FROM water_quality_station WHERE stationName IN\n" + + "(SELECT DISTINCT belongStation FROM water_quality WHERE (LEVEL='Ⅳ' OR LEVEL='Ⅴ' OR LEVEL='劣Ⅴ') \n" + + "AND TO_DAYS(NOW())-TO_DAYS(DATETIME)<=1)"; + list = template.query(sql, new BeanPropertyRowMapper(WaterQualityStation.class)); + } catch (Exception e) + { + System.out.println(e); + } + return list; + } + + @Override + public WaterQualityStation findIntro(double longitude, double latitude) + { + WaterQualityStation station= null; + try { + String sql="SELECT * FROM water_quality_station WHERE ABS(longitude-?)<0.1 AND ABS(latitude-?)<0.1;"; + List list = template.query(sql, new BeanPropertyRowMapper(WaterQualityStation.class), longitude, latitude); + if(list!=null) + {station = list.get(0);} + } catch (Exception e) { + System.out.println(e); + } + return station; + } + + @Override + public StationAndQuality findStationAndQuality(double longitude, double latitude) + { + StationAndQuality stationAndQuality= null; + try { + String sql1="SELECT * FROM water_quality_station WHERE ABS(longitude-?)<0.1 AND ABS(latitude-?)<0.1"; + String sql2="SELECT * FROM water_quality WHERE belongStation IN\n" + + " (SELECT stationName FROM water_quality_station WHERE ABS(longitude-?)<0.1 AND ABS(latitude-?)<0.1)\n" + + " ORDER BY DATETIME DESC LIMIT 1;"; + List list = template.query(sql1, new BeanPropertyRowMapper(WaterQualityStation.class),longitude,latitude); + + WaterQualityStation station=null; + if(list.size()!=0&&list!=null) + { + station=list.get(0); + } + + List list2 = template.query(sql2, new BeanPropertyRowMapper(WaterQuality.class), longitude, latitude); + + WaterQuality waterQuality=null; + if(list2!=null&&list2.size()!=0) + { + waterQuality=list2.get(0); + } + + stationAndQuality = new StationAndQuality(); + if(list!=null&&list2!=null) + { + stationAndQuality.setStation(station); + stationAndQuality.setQuality(waterQuality); + } + + } catch (Exception e) { + System.out.println(e); + } + return stationAndQuality; + } + + @Override + public List indexing() + { + List result=new LinkedList<>(); + String sql="select * from water_quality_station"; + List stationList = template.query(sql, new BeanPropertyRowMapper(WaterQualityStation.class)); + for (WaterQualityStation station : stationList) + { + String stationName = station.getStationName(); + String sql2="SELECT * FROM water_quality WHERE belongStation=? ORDER BY DATETIME DESC LIMIT 1"; + List qualityList = null; + try { + qualityList = template.query(sql2, new BeanPropertyRowMapper(WaterQuality.class),stationName); + } catch (Exception e) + { + System.out.println(e); + } + + WaterQuality waterQuality=null; + if(qualityList!=null&&qualityList.size()!=0) + {waterQuality = qualityList.get(0);} + + StationAndQuality stationAndQuality=new StationAndQuality(); + stationAndQuality.setStation(station); + stationAndQuality.setQuality(waterQuality); + result.add(stationAndQuality); + } + return result; + } +} diff --git a/src/src_houduan/domain/ResultInfo.java b/src/src_houduan/domain/ResultInfo.java new file mode 100644 index 0000000..fbdd2f9 --- /dev/null +++ b/src/src_houduan/domain/ResultInfo.java @@ -0,0 +1,22 @@ +package domain; + +public class ResultInfo +{ + + private String msg; + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + @Override + public String toString() { + return "ResultInfo{" + + "msg='" + msg + '\'' + + '}'; + } +} diff --git a/src/src_houduan/domain/StationAndQuality.java b/src/src_houduan/domain/StationAndQuality.java new file mode 100644 index 0000000..c2f4e0b --- /dev/null +++ b/src/src_houduan/domain/StationAndQuality.java @@ -0,0 +1,35 @@ +package domain; + +/** + * @author laoyingyong + * @date: 2020-02-03 16:55 + */ +public class StationAndQuality +{ + private WaterQualityStation station; + private WaterQuality quality; + + public WaterQualityStation getStation() { + return station; + } + + public void setStation(WaterQualityStation station) { + this.station = station; + } + + public WaterQuality getQuality() { + return quality; + } + + public void setQuality(WaterQuality quality) { + this.quality = quality; + } + + @Override + public String toString() { + return "StationAndQuality{" + + "station=" + station + + ", quality=" + quality + + '}'; + } +} diff --git a/src/src_houduan/domain/Statistics.java b/src/src_houduan/domain/Statistics.java new file mode 100644 index 0000000..e2de67a --- /dev/null +++ b/src/src_houduan/domain/Statistics.java @@ -0,0 +1,85 @@ +package domain; + +/** + * @author laoyingyong + * @date: 2020-01-30 12:47 + */ +public class Statistics +{ + private int a;//I类水质的数量 + private int b;//II类水质的数量 + private int c;//III类水质的数量 + private int d;//IV类水质的数量 + private int e;//V类水质的数量 + private int f;//劣V类水质的数量 + private int g;//其他 + + public int getA() { + return a; + } + + public void setA(int a) { + this.a = a; + } + + public int getB() { + return b; + } + + public void setB(int b) { + this.b = b; + } + + public int getC() { + return c; + } + + public void setC(int c) { + this.c = c; + } + + public int getD() { + return d; + } + + public void setD(int d) { + this.d = d; + } + + public int getE() { + return e; + } + + public void setE(int e) { + this.e = e; + } + + public int getF() { + return f; + } + + public void setF(int f) { + this.f = f; + } + + public int getG() { + return g; + } + + public void setG(int g) { + this.g = g; + } + + @Override + public String toString() { + return "Statistics{" + + "a=" + a + + ", b=" + b + + ", c=" + c + + ", d=" + d + + ", e=" + e + + ", f=" + f + + ", g=" + g + + '}'; + } +} diff --git a/src/src_houduan/domain/User.java b/src/src_houduan/domain/User.java new file mode 100644 index 0000000..7fea672 --- /dev/null +++ b/src/src_houduan/domain/User.java @@ -0,0 +1,102 @@ +package domain; + +public class User +{ + private int id; + private String name; + private String gender; + private int age; + private String address; + private String qq; + private String email; + + private String username; + private String password; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getGender() { + return gender; + } + + public void setGender(String gender) { + this.gender = gender; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getQq() { + return qq; + } + + public void setQq(String qq) { + this.qq = qq; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + 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 "User{" + + "id=" + id + + ", name='" + name + '\'' + + ", gender='" + gender + '\'' + + ", age=" + age + + ", address='" + address + '\'' + + ", qq='" + qq + '\'' + + ", email='" + email + '\'' + + ", username='" + username + '\'' + + ", password='" + password + '\'' + + '}'; + } +} diff --git a/src/src_houduan/domain/WaterLevel.java b/src/src_houduan/domain/WaterLevel.java new file mode 100644 index 0000000..0c49966 --- /dev/null +++ b/src/src_houduan/domain/WaterLevel.java @@ -0,0 +1,84 @@ +package domain; + +import java.sql.Timestamp; + +public class WaterLevel +{ + private Integer id; + private String riverName; + private String siteName; + private Timestamp collectionDate; + private Double waterLevel; + private Double flow; + private Double over; + + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getRiverName() { + return riverName; + } + + public void setRiverName(String riverName) { + this.riverName = riverName; + } + + public String getSiteName() { + return siteName; + } + + public void setSiteName(String siteName) { + this.siteName = siteName; + } + + public Timestamp getCollectionDate() { + return collectionDate; + } + + public void setCollectionDate(Timestamp collectionDate) { + this.collectionDate = collectionDate; + } + + public Double getWaterLevel() { + return waterLevel; + } + + public void setWaterLevel(Double waterLevel) { + this.waterLevel = waterLevel; + } + + public Double getFlow() { + return flow; + } + + public void setFlow(Double flow) { + this.flow = flow; + } + + public Double getOver() { + return over; + } + + public void setOver(Double over) { + this.over = over; + } + + @Override + public String toString() { + return "WaterLevel{" + + "id=" + id + + ", riverName='" + riverName + '\'' + + ", siteName='" + siteName + '\'' + + ", collectionDate=" + collectionDate + + ", waterLevel=" + waterLevel + + ", flow=" + flow + + ", over=" + over + + '}'; + } +} diff --git a/src/src_houduan/domain/WaterQuality.java b/src/src_houduan/domain/WaterQuality.java new file mode 100644 index 0000000..d7db0df --- /dev/null +++ b/src/src_houduan/domain/WaterQuality.java @@ -0,0 +1,107 @@ +package domain; + +import java.sql.Timestamp; + +/** + * @author laoyingyong + * @date: 2020-01-19 15:24 + */ +public class WaterQuality +{ + private Integer id; + private String belongStation; + private Timestamp dateTime; + private Double pH; + private Double dO; + private Double nH4; + private Double cODMn; + private Double tOC; + private String level; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getBelongStation() { + return belongStation; + } + + public void setBelongStation(String belongStation) { + this.belongStation = belongStation; + } + + public Timestamp getDateTime() { + return dateTime; + } + + public void setDateTime(Timestamp dateTime) { + this.dateTime = dateTime; + } + + public Double getpH() { + return pH; + } + + public void setpH(Double pH) { + this.pH = pH; + } + + public Double getdO() { + return dO; + } + + public void setdO(Double dO) { + this.dO = dO; + } + + public Double getnH4() { + return nH4; + } + + public void setnH4(Double nH4) { + this.nH4 = nH4; + } + + public Double getcODMn() { + return cODMn; + } + + public void setcODMn(Double cODMn) { + this.cODMn = cODMn; + } + + public Double gettOC() { + return tOC; + } + + public void settOC(Double tOC) { + this.tOC = tOC; + } + + public String getLevel() { + return level; + } + + public void setLevel(String level) { + this.level = level; + } + + @Override + public String toString() { + return "WaterQuality{" + + "id=" + id + + ", belongStation='" + belongStation + '\'' + + ", dateTime=" + dateTime + + ", pH=" + pH + + ", dO=" + dO + + ", nH4=" + nH4 + + ", cODMn=" + cODMn + + ", tOC=" + tOC + + ", level='" + level + '\'' + + '}'; + } +} diff --git a/src/src_houduan/domain/WaterQualityStation.java b/src/src_houduan/domain/WaterQualityStation.java new file mode 100644 index 0000000..ce5d3d5 --- /dev/null +++ b/src/src_houduan/domain/WaterQualityStation.java @@ -0,0 +1,72 @@ +package domain; + +public class WaterQualityStation +{ + private int id; + private String stationName; + private Double longitude; + private Double latitude; + private String section; + private String introduction; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getStationName() { + return stationName; + } + + public void setStationName(String stationName) { + this.stationName = stationName; + } + + public String getIntroduction() { + return introduction; + } + + public void setIntroduction(String introduction) { + this.introduction = introduction; + } + + public String getSection() { + return section; + } + + public void setSection(String section) { + this.section = section; + } + + public Double getLongitude() { + return longitude; + } + + public void setLongitude(Double longitude) { + this.longitude = longitude; + } + + public Double getLatitude() { + return latitude; + } + + public void setLatitude(Double latitude) { + this.latitude = latitude; + } + + + @Override + public String toString() { + return "WaterQualityStation{" + + "id=" + id + + ", stationName='" + stationName + '\'' + + ", longitude=" + longitude + + ", latitude=" + latitude + + ", section='" + section + '\'' + + ", introduction='" + introduction + '\'' + + '}'; + } +} diff --git a/src/src_houduan/druid.properties b/src/src_houduan/druid.properties new file mode 100644 index 0000000..0b46ccf --- /dev/null +++ b/src/src_houduan/druid.properties @@ -0,0 +1,10 @@ +driverClassName=com.mysql.jdbc.Driver +url=jdbc:mysql://127.0.0.1:3306/river?characterEncoding=utf8 +username=root +password=root +# ʼ +initialSize=5 +# +maxActive=10 +# ȴʱ +maxWait=3000 \ No newline at end of file diff --git a/src/src_houduan/mysql-connector-java-5.1.18-bin.jar b/src/src_houduan/mysql-connector-java-5.1.18-bin.jar new file mode 100644 index 0000000..cdee6a1 Binary files /dev/null and b/src/src_houduan/mysql-connector-java-5.1.18-bin.jar differ diff --git a/src/src_houduan/service/UserService.java b/src/src_houduan/service/UserService.java new file mode 100644 index 0000000..0a7634e --- /dev/null +++ b/src/src_houduan/service/UserService.java @@ -0,0 +1,76 @@ +package service; + + +import domain.User; +import domain.PageBean; + +import java.util.List; +import java.util.Map; + +/** + * 用户管理的业务接口 + */ +public interface UserService { + + /** + * 查询所有用户信息 + * @return + */ + public List findAll(); + + /** + * 登录方法 + * @param user + * @return + */ + User login(User user); + + /** + * 保存User + * @param user + */ + void addUser(User user); + + + void userRegister(User user);//用户注册 + + void updateUserPassword(User user); + + + /** + * 根据id删除User + * @param id + */ + void deleteUser(String id); + + /** + * 根据id查询 + * @param id + * @return + */ + User findUserById(String id); + + /** + * 修改用户信息 + * @param user + */ + void updateUser(User user); + + /** + * 批量删除用户 + * @param ids + */ + void delSelectedUser(String[] ids); + + /** + * 分页条件查询 + * @param currentPage + * @param rows + * @param condition + * @return + */ + PageBean findUserByPage(String currentPage, String rows, Map condition); + + + boolean updateUserInfo(User user); +} diff --git a/src/src_houduan/service/WaterQualityStationService.java b/src/src_houduan/service/WaterQualityStationService.java new file mode 100644 index 0000000..137f4cb --- /dev/null +++ b/src/src_houduan/service/WaterQualityStationService.java @@ -0,0 +1,27 @@ +package service; + +import domain.PageBean; +import domain.StationAndQuality; +import domain.WaterQualityStation; + +import java.util.List; +import java.util.Map; + +public interface WaterQualityStationService +{ + public abstract List findAll(); + public abstract WaterQualityStation findByName(String stationName); + public abstract int findTotalCount(); + public abstract WaterQualityStation findIntroByName(String name); + public abstract boolean addWaterQualityStation(WaterQualityStation station); + public abstract PageBean getPageBean(int currentPage,int pageSize); + public abstract WaterQualityStation findIntroById(int id); + public abstract PageBean conditonalQueryByPage(int currentPage, int pageSize, Map condition); + public abstract int conditionalFindAllCount(Map condition); + public abstract boolean update(WaterQualityStation station); + public abstract boolean delete(int id); + public abstract List findPollutedSite(); + public abstract WaterQualityStation findIntro(double longitude,double latitude); + public abstract StationAndQuality findStationAndQuality(double longitude, double latitude); + public abstract List indexing(); +} diff --git a/src/src_houduan/service/impl/UserServiceImpl.java b/src/src_houduan/service/impl/UserServiceImpl.java new file mode 100644 index 0000000..2e52c74 --- /dev/null +++ b/src/src_houduan/service/impl/UserServiceImpl.java @@ -0,0 +1,110 @@ +package service.impl; + + + +import domain.User; +import dao.UserDao; +import dao.impl.UserDaoImpl; +import domain.PageBean; +import service.UserService; + +import java.util.List; +import java.util.Map; + +public class UserServiceImpl implements UserService { + private UserDao dao = new UserDaoImpl(); + + @Override + public List findAll() { + //调用Dao完成查询 + return dao.findAll(); + } + + @Override + public User login(User user) { + return dao.findUserByUsernameAndPassword(user.getUsername(),user.getPassword()); + } + + @Override + public void addUser(User user) { + dao.add(user); + } + + @Override + public void userRegister(User user) { + dao.register(user); + } + + @Override + public void updateUserPassword(User user)//修改当前用户密码 + { + dao.updatePassword(user); + + } + + @Override + public void deleteUser(String id) { + dao.delete(Integer.parseInt(id)); + } + + @Override + public User findUserById(String id) { + return dao.findById(Integer.parseInt(id)); + } + + @Override + public void updateUser(User user) { + dao.update(user); + } + + @Override + public void delSelectedUser(String[] ids) { + if(ids != null && ids.length > 0){ + //1.遍历数组 + for (String id : ids) { + //2.调用dao删除 + dao.delete(Integer.parseInt(id)); + } + } + + } + + @Override + public PageBean findUserByPage(String _currentPage, String _rows, Map condition) { + + int currentPage = Integer.parseInt(_currentPage); + int rows = Integer.parseInt(_rows); + + if(currentPage <=0) { + currentPage = 1; + } + //1.创建空的PageBean对象 + PageBean pb = new PageBean(); + //2.设置参数 + pb.setCurrentPage(currentPage); + pb.setRows(rows); + + //3.调用dao查询总记录数 + int totalCount = dao.findTotalCount(condition); + pb.setTotalCount(totalCount); + //4.调用dao查询List集合 + //计算开始的记录索引 + int start = (currentPage - 1) * rows; + List list = dao.findByPage(start,rows,condition); + pb.setList(list); + + //5.计算总页码 + int totalPage = (totalCount % rows) == 0 ? totalCount/rows : (totalCount/rows) + 1; + pb.setTotalPage(totalPage); + + + return pb; + } + + @Override + public boolean updateUserInfo(User user) + { + boolean b = dao.updateUserInfo(user); + return b; + } +} diff --git a/src/src_houduan/service/impl/WaterQualityStationServiceImpl.java b/src/src_houduan/service/impl/WaterQualityStationServiceImpl.java new file mode 100644 index 0000000..43fe6d6 --- /dev/null +++ b/src/src_houduan/service/impl/WaterQualityStationServiceImpl.java @@ -0,0 +1,132 @@ +package service.impl; + +import dao.WaterQualityStationDao; +import dao.impl.WaterQualityStationDaoImpl; +import domain.PageBean; +import domain.StationAndQuality; +import domain.WaterQualityStation; +import service.WaterQualityStationService; + +import java.util.List; +import java.util.Map; + +public class WaterQualityStationServiceImpl implements WaterQualityStationService +{ + WaterQualityStationDao dao=new WaterQualityStationDaoImpl(); + + @Override + public List findAll() + { + return dao.findAll(); + } + + @Override + public WaterQualityStation findByName(String stationName) + { + return dao.findByName(stationName); + } + + /** + * 查询所有水质监测站 + * @return + */ + @Override + public int findTotalCount() + { + int totalCount = dao.findTotalCount(); + return totalCount; + } + + @Override + public WaterQualityStation findIntroByName(String name) { + return dao.findIntroByName(name); + } + + @Override + public boolean addWaterQualityStation(WaterQualityStation station) + { + return dao.addWaterQualityStation(station); + + } + + @Override + public PageBean getPageBean(int currentPage, int pageSize) + { + PageBean pageBean=new PageBean<>(); + int totalCount=dao.findTotalCount(); + pageBean.setTotalCount(totalCount); + int totalPage=totalCount%pageSize==0?totalCount/pageSize:(totalCount/pageSize+1); + pageBean.setTotalPage(totalPage); + pageBean.setCurrentPage(currentPage); + pageBean.setRows(pageSize); + int start=(currentPage-1)*pageSize; + List list = dao.findByPage(start, pageSize); + pageBean.setList(list); + return pageBean; + } + + @Override + public WaterQualityStation findIntroById(int id) + { + WaterQualityStation introById = dao.findIntroById(id); + return introById; + } + + @Override + public PageBean conditonalQueryByPage(int currentPage, int pageSize, Map condition) + { + PageBean pageBean=new PageBean<>(); + int totalCount= dao.conditionalFindAllCount(condition); + pageBean.setTotalCount(totalCount); + int totalPage=totalCount%pageSize==0?totalCount/pageSize:(totalCount/pageSize+1); + pageBean.setTotalPage(totalPage); + pageBean.setCurrentPage(currentPage); + pageBean.setRows(pageSize); + List list = dao.conditonalQueryByPage((currentPage - 1) * pageSize, pageSize, condition); + pageBean.setList(list); + return pageBean; + } + + @Override + public int conditionalFindAllCount(Map condition) + { + int i = dao.conditionalFindAllCount(condition); + return i; + } + + @Override + public boolean update(WaterQualityStation station) + { + boolean b = dao.update(station); + return b; + } + + @Override + public boolean delete(int id) + { + boolean b = dao.delete(id); + return b; + } + + @Override + public List findPollutedSite() + { + return dao.findPollutedSite(); + } + + @Override + public WaterQualityStation findIntro(double longitude, double latitude) { + return dao.findIntro(longitude,latitude); + } + + @Override + public StationAndQuality findStationAndQuality(double longitude, double latitude) { + return dao.findStationAndQuality(longitude,latitude); + } + + @Override + public List indexing() + { + return dao.indexing(); + } +} diff --git a/src/src_houduan/spring-jdbc-4.2.4.RELEASE.jar b/src/src_houduan/spring-jdbc-4.2.4.RELEASE.jar new file mode 100644 index 0000000..4f0abf1 Binary files /dev/null and b/src/src_houduan/spring-jdbc-4.2.4.RELEASE.jar differ diff --git a/src/src_houduan/util/JDBCUtils.java b/src/src_houduan/util/JDBCUtils.java new file mode 100644 index 0000000..60db26b --- /dev/null +++ b/src/src_houduan/util/JDBCUtils.java @@ -0,0 +1,52 @@ +package util; + +import com.alibaba.druid.pool.DruidDataSourceFactory; + +import javax.sql.DataSource; +import java.io.IOException; +import java.io.InputStream; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.Properties; + +/** + * JDBC工具类 使用Durid连接池 + */ +public class JDBCUtils { + + private static DataSource ds ; + + static { + + try { + //1.加载配置文件 + Properties pro = new Properties(); + //使用ClassLoader加载配置文件,获取字节输入流 + InputStream is = JDBCUtils.class.getClassLoader().getResourceAsStream("druid.properties"); + pro.load(is); + + //2.初始化连接池对象 + ds = DruidDataSourceFactory.createDataSource(pro); + + } catch (IOException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 获取连接池对象 + */ + public static DataSource getDataSource(){ + return ds; + } + + + /** + * 获取连接Connection对象 + */ + public static Connection getConnection() throws SQLException { + return ds.getConnection(); + } +} diff --git a/src/src_houduan/web/sevlet/example/EmergencyDecisionServlet.java b/src/src_houduan/web/servlet/example/EmergencyDecisionServlet.java similarity index 100% rename from src/src_houduan/web/sevlet/example/EmergencyDecisionServlet.java rename to src/src_houduan/web/servlet/example/EmergencyDecisionServlet.java diff --git a/src/src_houduan/web/servlet/others/CheckCodeServlet.java b/src/src_houduan/web/servlet/others/CheckCodeServlet.java new file mode 100644 index 0000000..41be1ca --- /dev/null +++ b/src/src_houduan/web/servlet/others/CheckCodeServlet.java @@ -0,0 +1,99 @@ +package web.servlet.others; + +import javax.imageio.ImageIO; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.util.Random; + +/** + * 验证码 + */ +@WebServlet("/checkCodeServlet") +public class CheckCodeServlet extends HttpServlet { + public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException { + + //服务器通知浏览器不要缓存 + response.setHeader("pragma","no-cache"); + response.setHeader("cache-control","no-cache"); + response.setHeader("expires","0"); + + //在内存中创建一个长80,宽30的图片,默认黑色背景 + //参数一:长 + //参数二:宽 + //参数三:颜色 + int width = 80; + int height = 30; + BufferedImage image = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB); + + //获取画笔 + Graphics g = image.getGraphics(); + //设置画笔颜色为灰色 + g.setColor(Color.GRAY); + //填充图片 + g.fillRect(0,0, width,height); + + //产生4个随机验证码,12Ey + String checkCode = getCheckCode(); + //将验证码放入HttpSession中 + request.getSession().setAttribute("CHECKCODE_SERVER",checkCode); + + //设置画笔颜色为黄色 + g.setColor(Color.YELLOW); + //设置字体的小大 + g.setFont(new Font("黑体",Font.BOLD,24)); + //向图片上写入验证码 + g.drawString(checkCode,15,25); + + //2.4画干扰线 + g.setColor(Color.GREEN); + //随机生成坐标点 + Random ran=new Random(); + for (int i = 0; i < 10; i++) + { + int x1 = ran.nextInt(width); + int x2 = ran.nextInt(width); + + int y1 = ran.nextInt(height); + int y2 = ran.nextInt(height); + g.drawLine(x1,y1,x2,y2); + } + + //将内存中的图片输出到浏览器 + //参数一:图片对象 + //参数二:图片的格式,如PNG,JPG,GIF + //参数三:图片输出到哪里去 + ImageIO.write(image,"PNG",response.getOutputStream()); + } + /** + * 产生4位随机字符串 + */ + private String getCheckCode() + { + String base = "0123456789ABCDEFGHIJKLMNOPQUVWXYZabcdefghijklmnopquvwxyz"; + int size = base.length(); + Random r = new Random(); + StringBuffer sb = new StringBuffer(); + for(int i=1;i<=4;i++) + { + //产生0到size-1的随机值 + int index = r.nextInt(size); + //在base字符串中获取下标为index的字符 + char c = base.charAt(index); + //将c放入到StringBuffer中去 + sb.append(c); + } + return sb.toString(); + } + public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + this.doGet(request,response); + } +} + + + diff --git a/src/src_houduan/web/servlet/others/DownloadFileServlet.java b/src/src_houduan/web/servlet/others/DownloadFileServlet.java new file mode 100644 index 0000000..7b55c87 --- /dev/null +++ b/src/src_houduan/web/servlet/others/DownloadFileServlet.java @@ -0,0 +1,76 @@ +package web.servlet.others; + +import domain.WaterLevel; +import service.WaterLevelService; +import service.impl.WaterLevelServiceImpl; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URLEncoder; +import java.sql.Timestamp; +import java.text.SimpleDateFormat; +import java.util.List; + +/** + * @author laoyingyong + * @date: 2020-02-05 10:27 + */ +@WebServlet("/DownloadFileServlet") +public class DownloadFileServlet extends HttpServlet +{ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + ServletOutputStream outputStream = response.getOutputStream();//网络字节输出流 + WaterLevelService service=new WaterLevelServiceImpl(); + List weekData = service.findWeekData(); + + outputStream.write(("河流"+"\t"+"测站名"+"\t"+"时间"+"\t"+"水位"+"\t"+"流量"+"\t"+"超警戒(汛限)水位"+"\n").getBytes()); + outputStream.write("-----------------------------------------最近七天的水位数据-------------------------------------------\n".getBytes()); + for (WaterLevel item : weekData) + { + String riverName = item.getRiverName(); + String siteName = item.getSiteName(); + Timestamp collectionDate = item.getCollectionDate(); + SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm"); + String format = simpleDateFormat.format(collectionDate); + Double waterLevel = item.getWaterLevel(); + Double flow = item.getFlow(); + Double over = item.getOver(); + + outputStream.write((riverName+"\t"+siteName+"\t"+format+"\t"+waterLevel+"\t"+flow+"\t"+over+"\n").getBytes()); + + + } + + + String filename = request.getParameter("filename"); + + + ServletContext servletContext = request.getServletContext(); + + //设置响应的mime类型 + String mimeType = servletContext.getMimeType(filename); + response.setContentType(mimeType); + + + String encodeFileName = URLEncoder.encode(filename, "utf-8");//编码,解决文件中文乱码问题 + response.setHeader("content-disposition","attachment;filename="+encodeFileName); + + + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + this.doPost(request, response); + + } +} diff --git a/src/src_houduan/web/servlet/others/DownloadFileServlet2.java b/src/src_houduan/web/servlet/others/DownloadFileServlet2.java new file mode 100644 index 0000000..2e5a99b --- /dev/null +++ b/src/src_houduan/web/servlet/others/DownloadFileServlet2.java @@ -0,0 +1,80 @@ +package web.servlet.others; + +import domain.WaterLevel; +import domain.WaterQuality; +import service.WaterLevelService; +import service.WaterQualityService; +import service.impl.WaterLevelServiceImpl; +import service.impl.WaterQualityServiceImpl; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.net.URLEncoder; +import java.sql.Timestamp; +import java.text.SimpleDateFormat; +import java.util.List; + +/** + * @author laoyingyong + * @date: 2020-02-05 10:27 + */ +@WebServlet("/DownloadFileServlet2") +public class DownloadFileServlet2 extends HttpServlet +{ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + ServletOutputStream outputStream = response.getOutputStream();//网络字节输出流 + WaterQualityService service=new WaterQualityServiceImpl(); + List weekData = service.findWeekData(); + + outputStream.write(("测站名"+"\t"+"时间"+"\t"+"PH"+"\t"+"溶解氧"+"\t"+"氨氮"+"\t"+"高猛酸钾盐指数"+"\t"+"总有机碳"+"\t"+"水质类别"+"\n").getBytes()); + outputStream.write("---------------------------------------------------------------最近七天的水质数据--\n".getBytes()); + for (WaterQuality item : weekData) + { + String belongStation = item.getBelongStation(); + + Timestamp dateTime = item.getDateTime(); + SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm"); + String format = simpleDateFormat.format(dateTime); + Double aDouble = item.getpH(); + Double aDouble1 = item.getdO(); + Double aDouble2 = item.getnH4(); + Double aDouble3 = item.getcODMn(); + Double aDouble4 = item.gettOC(); + String level = item.getLevel(); + + outputStream.write((belongStation+"\t"+format+"\t"+aDouble+"\t"+aDouble1+"\t"+aDouble2+"\t"+aDouble3+"\t"+aDouble4+"\t"+level+"\n").getBytes()); + + + } + + + String filename = request.getParameter("filename"); + + + ServletContext servletContext = request.getServletContext(); + + //设置响应的mime类型 + String mimeType = servletContext.getMimeType(filename); + response.setContentType(mimeType); + + + String encodeFileName = URLEncoder.encode(filename, "utf-8");//编码,解决文件中文乱码问题 + response.setHeader("content-disposition","attachment;filename="+encodeFileName); + + + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + this.doPost(request, response); + + } +} diff --git a/src/src_houduan/web/servlet/others/UploadServlet.java b/src/src_houduan/web/servlet/others/UploadServlet.java new file mode 100644 index 0000000..04f52f9 --- /dev/null +++ b/src/src_houduan/web/servlet/others/UploadServlet.java @@ -0,0 +1,130 @@ +package web.servlet.others; + +import domain.WaterQuality; +import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.FileUploadException; +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.apache.commons.fileupload.servlet.ServletFileUpload; +import service.WaterQualityService; +import service.impl.WaterQualityServiceImpl; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.sql.Timestamp; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Date; +import java.util.List; + +/** + * @author laoyingyong + * @date: 2020-02-11 12:12 + */ +@WebServlet("/UploadServlet") +public class UploadServlet extends HttpServlet +{ + + + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + int count=0; + WaterQualityService service=new WaterQualityServiceImpl(); + + + request.setCharacterEncoding("UTF-8"); + //String type=request.getParameter("type"); + + try { + // 配置上传参数 + DiskFileItemFactory factory = new DiskFileItemFactory(); + ServletFileUpload upload = new ServletFileUpload(factory); + // 解析请求的内容提取文件数据 + @SuppressWarnings("unchecked") + List formItems = upload.parseRequest(request); + + + // 迭代表单数据 + for (FileItem item : formItems) + { + // 处理不在表单中的字段 + if (!item.isFormField()) + { + String fileName = item.getName(); //获取上传的文件名 + String fileType=fileName.substring(fileName.lastIndexOf(".")+1); + //定义上传文件的存放路径 + String path = request.getServletContext().getRealPath("/upload"); + //定义上传文件的完整路径 + fileName= new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()).toString(); + fileName+="."+fileType; //将文件名字改为时间,避免重名文件 + String filePath = String.format("%s\\%s",path,fileName); + File storeFile = new File(filePath); + // 在控制台输出文件的上传路径 + System.out.println(path); + System.out.println(filePath); + + // 保存文件到硬盘 + item.write(storeFile); + + BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(new FileInputStream(filePath),"utf-8"));//缓冲字符输入流、转换流 + String line=null; + + while((line=bufferedReader.readLine())!=null) + { + //System.out.println(line); + String[] split = line.split("\t"); + System.out.println(Arrays.toString(split)); + WaterQuality waterQuality=new WaterQuality(); + try + { + waterQuality.setBelongStation(split[0]); + waterQuality.setDateTime(Timestamp.valueOf(split[1]+":00")); + if(!split[2].equals("null")) + {waterQuality.setpH(Double.parseDouble(split[2]));} + if(!split[3].equals("null")) + {waterQuality.setdO(Double.parseDouble(split[3]));} + if(!split[4].equals("null")) + {waterQuality.setnH4(Double.parseDouble(split[4]));} + if(!split[5].equals("null")) + {waterQuality.setcODMn(Double.parseDouble(split[5]));} + if(!split[6].equals("null")) + {waterQuality.settOC(Double.parseDouble(split[6]));} + if(!split[7].equals("null")) + {waterQuality.setLevel(split[7]);} + } catch (Exception e) + { + System.out.println(e); + } + boolean b = service.addOne(waterQuality); + if(b) + { + count++; + } + } + } + } + } catch (FileUploadException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + + + request.setAttribute("message",count); + // 跳转到 message.jsp + getServletContext().getRequestDispatcher("/message.jsp").forward( + request, response); + + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + this.doPost(request, response); + + } +} diff --git a/src/src_houduan/web/servlet/others/UploadServlet2.java b/src/src_houduan/web/servlet/others/UploadServlet2.java new file mode 100644 index 0000000..3d972d9 --- /dev/null +++ b/src/src_houduan/web/servlet/others/UploadServlet2.java @@ -0,0 +1,128 @@ +package web.servlet.others; + +import domain.WaterLevel; +import domain.WaterQuality; +import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.FileUploadException; +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.apache.commons.fileupload.servlet.ServletFileUpload; +import service.WaterLevelService; +import service.WaterQualityService; +import service.impl.WaterLevelServiceImpl; +import service.impl.WaterQualityServiceImpl; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.sql.Timestamp; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Date; +import java.util.List; + +/** + * @author laoyingyong + * @date: 2020-02-11 12:12 + */ +@WebServlet("/UploadServlet2") +public class UploadServlet2 extends HttpServlet +{ + + + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + int count=0; + WaterLevelService service=new WaterLevelServiceImpl(); + + + request.setCharacterEncoding("UTF-8"); + //String type=request.getParameter("type"); + + try { + // 配置上传参数 + DiskFileItemFactory factory = new DiskFileItemFactory(); + ServletFileUpload upload = new ServletFileUpload(factory); + // 解析请求的内容提取文件数据 + @SuppressWarnings("unchecked") + List formItems = upload.parseRequest(request); + + + // 迭代表单数据 + for (FileItem item : formItems) + { + // 处理不在表单中的字段 + if (!item.isFormField()) + { + String fileName = item.getName(); //获取上传的文件名 + String fileType=fileName.substring(fileName.lastIndexOf(".")+1); + //定义上传文件的存放路径 + String path = request.getServletContext().getRealPath("/upload"); + //定义上传文件的完整路径 + fileName= new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()).toString(); + fileName+="."+fileType; //将文件名字改为时间,避免重名文件 + String filePath = String.format("%s\\%s",path,fileName); + File storeFile = new File(filePath); + // 在控制台输出文件的上传路径 + System.out.println(path); + System.out.println(filePath); + + // 保存文件到硬盘 + item.write(storeFile); + + BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(new FileInputStream(filePath),"utf-8"));//缓冲字符输入流、转换流 + String line=null; + + while((line=bufferedReader.readLine())!=null) + { + //System.out.println(line); + String[] split = line.split("\t"); + System.out.println(Arrays.toString(split)); + WaterLevel waterLevel=new WaterLevel(); + try + { + waterLevel.setRiverName(split[0]); + waterLevel.setSiteName(split[1]); + waterLevel.setCollectionDate(Timestamp.valueOf(split[2]+":00")); + if(!split[3].equals("null")) + {waterLevel.setWaterLevel(Double.parseDouble(split[3]));} + if(!split[4].equals("null")) + {waterLevel.setFlow(Double.parseDouble(split[4]));} + if(!split[5].equals("null")) + {waterLevel.setOver(Double.parseDouble(split[5]));} + } catch (Exception e) + { + System.out.println(e); + } + boolean b = service.addWaterLevelInfo(waterLevel); + if(b) + { + count++; + } + } + } + } + } catch (FileUploadException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + + + request.setAttribute("message",count); + // 跳转到 message.jsp + getServletContext().getRequestDispatcher("/otherPage/message2.jsp").forward( + request, response); + + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + this.doPost(request, response); + + } +} diff --git a/src/src_houduan/web/servlet/user/AddUserServlet.java b/src/src_houduan/web/servlet/user/AddUserServlet.java new file mode 100644 index 0000000..0f03862 --- /dev/null +++ b/src/src_houduan/web/servlet/user/AddUserServlet.java @@ -0,0 +1,46 @@ +package web.servlet.user; + + +import domain.User; +import org.apache.commons.beanutils.BeanUtils; +import service.UserService; +import service.impl.UserServiceImpl; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.util.Map; + +@WebServlet("/addUserServlet") +public class AddUserServlet extends HttpServlet { + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + //1.设置编码 + request.setCharacterEncoding("utf-8"); + //2.获取参数 + Map map = request.getParameterMap(); + //3.封装对象 + User user = new User(); + try { + BeanUtils.populate(user,map); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + + //4.调用Service保存 + UserService service = new UserServiceImpl(); + service.addUser(user); + + //5.跳转到userListServlet + response.sendRedirect(request.getContextPath()+"/userListServlet"); + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + this.doPost(request, response); + } +} diff --git a/src/src_houduan/web/servlet/user/DelSelectedServlet.java b/src/src_houduan/web/servlet/user/DelSelectedServlet.java new file mode 100644 index 0000000..de44997 --- /dev/null +++ b/src/src_houduan/web/servlet/user/DelSelectedServlet.java @@ -0,0 +1,31 @@ +package web.servlet.user; + + + +import service.UserService; +import service.impl.UserServiceImpl; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@WebServlet("/delSelectedServlet") +public class DelSelectedServlet extends HttpServlet { + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + //1.获取所有id + String[] ids = request.getParameterValues("uid"); + //2.调用service删除 + UserService service = new UserServiceImpl(); + service.delSelectedUser(ids); + + //3.跳转查询所有Servlet + response.sendRedirect(request.getContextPath()+"/userListServlet"); + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + this.doPost(request, response); + } +} diff --git a/src/src_houduan/web/servlet/user/DelUserServlet.java b/src/src_houduan/web/servlet/user/DelUserServlet.java new file mode 100644 index 0000000..792356b --- /dev/null +++ b/src/src_houduan/web/servlet/user/DelUserServlet.java @@ -0,0 +1,31 @@ +package web.servlet.user; + + + +import service.UserService; +import service.impl.UserServiceImpl; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@WebServlet("/delUserServlet") +public class DelUserServlet extends HttpServlet { + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + //1.获取id + String id = request.getParameter("id"); + //2.调用service删除 + UserService service = new UserServiceImpl(); + service.deleteUser(id); + + //3.跳转到查询所有Servlet + response.sendRedirect(request.getContextPath()+"/userListServlet"); + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + this.doPost(request, response); + } +} diff --git a/src/src_houduan/web/servlet/user/FindUserByPageServlet.java b/src/src_houduan/web/servlet/user/FindUserByPageServlet.java new file mode 100644 index 0000000..f0d3862 --- /dev/null +++ b/src/src_houduan/web/servlet/user/FindUserByPageServlet.java @@ -0,0 +1,56 @@ +package web.servlet.user; + + + +import domain.User; +import domain.PageBean; +import service.UserService; +import service.impl.UserServiceImpl; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.Map; + +@WebServlet("/findUserByPageServlet") +public class FindUserByPageServlet extends HttpServlet { + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + request.setCharacterEncoding("utf-8"); + + //1.获取参数 + String currentPage = request.getParameter("currentPage");//当前页码 + String rows = request.getParameter("rows");//每页显示条数 + + if(currentPage == null || "".equals(currentPage)){ + + currentPage = "1"; + } + + if(rows == null || "".equals(rows)){ + rows = "5"; + } + + //获取条件查询参数 + Map condition = request.getParameterMap(); + + + //2.调用service查询 + UserService service = new UserServiceImpl(); + PageBean pb = service.findUserByPage(currentPage,rows,condition); + + System.out.println(pb); + + //3.将PageBean存入request + request.setAttribute("pb",pb); + request.setAttribute("condition",condition);//将查询条件存入request + //4.转发到list.jsp + request.getRequestDispatcher("/list.jsp").forward(request,response); + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + this.doPost(request, response); + } +} diff --git a/src/src_houduan/web/servlet/user/FindUserServlet.java b/src/src_houduan/web/servlet/user/FindUserServlet.java new file mode 100644 index 0000000..336fa3e --- /dev/null +++ b/src/src_houduan/web/servlet/user/FindUserServlet.java @@ -0,0 +1,34 @@ +package web.servlet.user; + + + +import domain.User; +import service.UserService; +import service.impl.UserServiceImpl; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@WebServlet("/findUserServlet") +public class FindUserServlet extends HttpServlet { + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + //1.获取id + String id = request.getParameter("id"); + //2.调用Service查询 + UserService service = new UserServiceImpl(); + User user = service.findUserById(id); + + //3.将user存入request + request.setAttribute("user",user); + //4.转发到update.jsp + request.getRequestDispatcher("/update.jsp").forward(request,response); + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + this.doPost(request, response); + } +} diff --git a/src/src_houduan/web/servlet/user/LoginServlet.java b/src/src_houduan/web/servlet/user/LoginServlet.java new file mode 100644 index 0000000..04a37a6 --- /dev/null +++ b/src/src_houduan/web/servlet/user/LoginServlet.java @@ -0,0 +1,82 @@ +package web.servlet.user; + + +import domain.User; +import org.apache.commons.beanutils.BeanUtils; +import service.UserService; +import service.impl.UserServiceImpl; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.util.Map; + +@WebServlet("/loginServlet") +public class LoginServlet extends HttpServlet { + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + //1.设置编码 + request.setCharacterEncoding("utf-8"); + + //2.获取数据 + //2.1获取用户填写验证码 + String verifycode = request.getParameter("verifycode"); + + //3.验证码校验 + HttpSession session = request.getSession(); + String checkcode_server = (String) session.getAttribute("CHECKCODE_SERVER"); + session.removeAttribute("CHECKCODE_SERVER");//确保验证码一次性 + if(!checkcode_server.equalsIgnoreCase(verifycode)){ + //验证码不正确 + //提示信息 + request.setAttribute("login_msg","验证码错误!"); + //跳转登录页面 + request.getRequestDispatcher("/login.jsp").forward(request,response); + + return; + } + + Map map = request.getParameterMap(); + //4.封装User对象 + User user = new User(); + try { + BeanUtils.populate(user,map); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + + + //5.调用Service查询 + UserService service = new UserServiceImpl(); + User loginUser = service.login(user); + //6.判断是否登录成功 + if(loginUser != null){ + //登录成功 + //将用户存入session + session.setAttribute("user",loginUser); + //跳转页面 + response.sendRedirect(request.getContextPath()+"/index.jsp"); + }else{ + //登录失败 + //提示信息 + request.setAttribute("login_msg","用户名或密码错误!"); + //跳转登录页面 + request.getRequestDispatcher("/login.jsp").forward(request,response); + + } + + + + + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + this.doPost(request, response); + } +} diff --git a/src/src_houduan/web/servlet/user/LogoutServlet.java b/src/src_houduan/web/servlet/user/LogoutServlet.java new file mode 100644 index 0000000..8eef145 --- /dev/null +++ b/src/src_houduan/web/servlet/user/LogoutServlet.java @@ -0,0 +1,27 @@ +package web.servlet.user; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.io.IOException; + +@WebServlet("/LogoutServlet") +public class LogoutServlet extends HttpServlet +{ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + HttpSession session = request.getSession(); + session.removeAttribute("user"); + response.sendRedirect(request.getContextPath()+"/login.jsp"); + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + this.doPost(request, response); + + } +} diff --git a/src/src_houduan/web/servlet/user/RegisterServlet.java b/src/src_houduan/web/servlet/user/RegisterServlet.java new file mode 100644 index 0000000..59854ea --- /dev/null +++ b/src/src_houduan/web/servlet/user/RegisterServlet.java @@ -0,0 +1,39 @@ +package web.servlet.user; + +import domain.User; +import service.impl.UserServiceImpl; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@WebServlet("/RegisterServlet") +public class RegisterServlet extends HttpServlet +{ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + request.setCharacterEncoding("utf-8"); + String username = request.getParameter("username"); + String password = request.getParameter("password"); + User registerUser=new User(); + registerUser.setUsername(username); + registerUser.setPassword(password); + + + UserServiceImpl service=new UserServiceImpl(); + service.userRegister(registerUser); + + request.setAttribute("register_msg","注册成功!"); + request.getRequestDispatcher("/register.jsp").forward(request,response); + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + this.doPost(request, response); + + } +} diff --git a/src/src_houduan/web/servlet/user/UpdatePasswordServlet.java b/src/src_houduan/web/servlet/user/UpdatePasswordServlet.java new file mode 100644 index 0000000..111a904 --- /dev/null +++ b/src/src_houduan/web/servlet/user/UpdatePasswordServlet.java @@ -0,0 +1,50 @@ +package web.servlet.user; + +import com.fasterxml.jackson.databind.ObjectMapper; +import domain.ResultInfo; +import domain.User; +import service.impl.UserServiceImpl; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.io.IOException; + +@WebServlet("/UpdatePasswordServlet") +public class UpdatePasswordServlet extends HttpServlet +{ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + String username = request.getParameter("username"); + String newPassword = request.getParameter("newPassword"); + + User user=new User(); + user.setUsername(username); + user.setPassword(newPassword); + + UserServiceImpl service=new UserServiceImpl(); + service.updateUserPassword(user); + + HttpSession session = request.getSession(); + session.removeAttribute("user"); + + ResultInfo info=new ResultInfo(); + info.setMsg("密码修改成功!"); + + ObjectMapper mapper=new ObjectMapper(); + response.setContentType("application/json;charset=utf-8"); + mapper.writeValue(response.getOutputStream(),info); + + + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + this.doPost(request, response); + + } +} diff --git a/src/src_houduan/web/servlet/user/UpdateUserInfoServlet.java b/src/src_houduan/web/servlet/user/UpdateUserInfoServlet.java new file mode 100644 index 0000000..3705749 --- /dev/null +++ b/src/src_houduan/web/servlet/user/UpdateUserInfoServlet.java @@ -0,0 +1,74 @@ +package web.servlet.user; + +import com.fasterxml.jackson.databind.ObjectMapper; +import domain.ResultInfo; +import domain.User; +import service.UserService; +import service.impl.UserServiceImpl; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * @author laoyingyong + * @date: 2020-01-22 19:01 + */ +@WebServlet("/UpdateUserInfoServlet") +public class UpdateUserInfoServlet extends HttpServlet +{ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + String id = request.getParameter("id"); + String name = request.getParameter("name"); + String gender = request.getParameter("gender"); + String age = request.getParameter("age"); + String address = request.getParameter("address"); + String qq = request.getParameter("qq"); + String email = request.getParameter("email"); + + + User user=new User(); + try + { + user.setId(Integer.parseInt(id)); + user.setName(name); + user.setGender(gender); + user.setAge(Integer.parseInt(age)); + user.setAddress(address); + user.setQq(qq); + user.setEmail(email); + } catch (Exception e) + { + System.out.println(e); + } + + + UserService service=new UserServiceImpl(); + boolean b = service.updateUserInfo(user); + ResultInfo info=new ResultInfo(); + if(b) + { + info.setMsg("修改成功,下次登录后即可查看更新!"); + } + else + { + info.setMsg("修改失败!"); + } + + ObjectMapper mapper=new ObjectMapper(); + response.setContentType("application/json;charset=utf8"); + mapper.writeValue(response.getOutputStream(),info); + + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + this.doPost(request, response); + + } +} diff --git a/src/src_houduan/web/servlet/user/UpdateUserServlet.java b/src/src_houduan/web/servlet/user/UpdateUserServlet.java new file mode 100644 index 0000000..ac1a0c1 --- /dev/null +++ b/src/src_houduan/web/servlet/user/UpdateUserServlet.java @@ -0,0 +1,47 @@ +package web.servlet.user; + +import domain.User; +import org.apache.commons.beanutils.BeanUtils; +import service.UserService; +import service.impl.UserServiceImpl; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.util.Map; + +@WebServlet("/updateUserServlet") +public class UpdateUserServlet extends HttpServlet { + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + //1.设置编码 + request.setCharacterEncoding("utf-8"); + //2.获取map + Map map = request.getParameterMap(); + //3.封装对象 + User user = new User(); + try { + BeanUtils.populate(user,map); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + + //4.调用Service修改 + UserService service = new UserServiceImpl(); + service.updateUser(user); + + //5.跳转到查询所有Servlet + response.sendRedirect(request.getContextPath()+"/userListServlet"); + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + this.doPost(request, response); + } +} diff --git a/src/src_houduan/web/servlet/user/UserListServlet.java b/src/src_houduan/web/servlet/user/UserListServlet.java new file mode 100644 index 0000000..6a50891 --- /dev/null +++ b/src/src_houduan/web/servlet/user/UserListServlet.java @@ -0,0 +1,31 @@ +package web.servlet.user; + + +import domain.User; +import service.UserService; +import service.impl.UserServiceImpl; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.List; + +@WebServlet("/userListServlet") +public class UserListServlet extends HttpServlet { + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + //1.调用UserService完成查询 + UserService service = new UserServiceImpl(); + List users = service.findAll(); + //2.将list存入request域 + request.setAttribute("users",users); + //3.转发到list.jsp + request.getRequestDispatcher("/list.jsp").forward(request,response); + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + this.doPost(request, response); + } +} diff --git a/src/src_houduan/web/servlet/waterQualityStation/AddWaterQualityDataServlet.java b/src/src_houduan/web/servlet/waterQualityStation/AddWaterQualityDataServlet.java new file mode 100644 index 0000000..4c83c55 --- /dev/null +++ b/src/src_houduan/web/servlet/waterQualityStation/AddWaterQualityDataServlet.java @@ -0,0 +1,67 @@ +package web.servlet.waterQualityStation; + +import com.fasterxml.jackson.databind.ObjectMapper; +import domain.ResultInfo; +import domain.WaterQualityStation; +import service.WaterQualityStationService; +import service.impl.WaterQualityStationServiceImpl; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@WebServlet("/AddWaterQualityDataServlet") +public class AddWaterQualityDataServlet extends HttpServlet +{ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + request.setCharacterEncoding("utf-8"); + String stationName = request.getParameter("stationName"); + String longitude = request.getParameter("longitude"); + String latitude = request.getParameter("latitude"); + String section = request.getParameter("section"); + String introduction = request.getParameter("introduction"); + WaterQualityStation station=new WaterQualityStation(); + //封装对象 + try + { + station.setStationName(stationName); + station.setLongitude(Double.parseDouble(longitude)); + station.setLatitude(Double.parseDouble(latitude)); + station.setSection(section); + station.setIntroduction(introduction); + } catch (NumberFormatException e) + { + System.out.println(e); + } + + WaterQualityStationService service=new WaterQualityStationServiceImpl(); + boolean flag = service.addWaterQualityStation(station); + + ResultInfo info=new ResultInfo(); + if(flag) + { + info.setMsg("添加成功!"); + } + else + { + info.setMsg("添加失败,监测站点名已存在!"); + } + + ObjectMapper mapper=new ObjectMapper(); + response.setContentType("application/json;charset=utf-8"); + System.out.println(info); + String string = mapper.writeValueAsString(info); + response.getWriter().write(string); + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + this.doPost(request, response); + + } +} diff --git a/src/src_houduan/web/servlet/waterQualityStation/ConditionalQueryStationByPageServlet.java b/src/src_houduan/web/servlet/waterQualityStation/ConditionalQueryStationByPageServlet.java new file mode 100644 index 0000000..d6102e9 --- /dev/null +++ b/src/src_houduan/web/servlet/waterQualityStation/ConditionalQueryStationByPageServlet.java @@ -0,0 +1,63 @@ +package web.servlet.waterQualityStation; + +import com.fasterxml.jackson.databind.ObjectMapper; +import domain.PageBean; +import domain.WaterQualityStation; +import service.WaterQualityStationService; +import service.impl.WaterQualityStationServiceImpl; + + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.Map; + +@WebServlet("/ConditionalQueryStationByPageServlet") +public class ConditionalQueryStationByPageServlet extends HttpServlet +{ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + request.setCharacterEncoding("utf-8"); + WaterQualityStationService service=new WaterQualityStationServiceImpl(); + Map parameterMap = request.getParameterMap(); + int totalCount = service.conditionalFindAllCount(parameterMap); //总的记录数 + + String currentPage = request.getParameter("currentPage"); + String pageSize = request.getParameter("pageSize"); + int intCurrentPage = 1; + int intPageSize = 5; + try { + intCurrentPage = Integer.parseInt(currentPage); + intPageSize = Integer.parseInt(pageSize); + } catch (NumberFormatException e) { + System.out.println(e); + } + int totalPage=totalCount%intPageSize==0?totalCount/intPageSize:(totalCount/intPageSize+1); + if(intCurrentPage<=0) + { + intCurrentPage=1; + } + if(intCurrentPage>totalPage) + { + intCurrentPage=totalPage; + + } + + PageBean bean = service.conditonalQueryByPage(intCurrentPage, intPageSize, parameterMap); + ObjectMapper mapper=new ObjectMapper(); + response.setContentType("application/json;chartset=utf-8"); + System.out.println(bean); + mapper.writeValue(response.getOutputStream(),bean); + + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + this.doPost(request, response); + + } +} diff --git a/src/src_houduan/web/servlet/waterQualityStation/DeleteStationServlet.java b/src/src_houduan/web/servlet/waterQualityStation/DeleteStationServlet.java new file mode 100644 index 0000000..1055d7c --- /dev/null +++ b/src/src_houduan/web/servlet/waterQualityStation/DeleteStationServlet.java @@ -0,0 +1,55 @@ +package web.servlet.waterQualityStation; + +import com.fasterxml.jackson.databind.ObjectMapper; +import domain.ResultInfo; +import domain.WaterQualityStation; +import service.WaterQualityStationService; +import service.impl.WaterQualityStationServiceImpl; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@WebServlet("/DeleteStationServlet") +public class DeleteStationServlet extends HttpServlet +{ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + String id = request.getParameter("id"); + + int i=0; + try + { + i = Integer.parseInt(id); + } catch (NumberFormatException e) + { + System.out.println(e); + } + + WaterQualityStationService service=new WaterQualityStationServiceImpl(); + boolean flag = service.delete(i); + ResultInfo info=new ResultInfo(); + if(flag) + { + info.setMsg("删除成功!"); + } + else + { + info.setMsg("删除失败!"); + } + ObjectMapper mapper=new ObjectMapper(); + response.setContentType("application/json;charset=utf-8"); + mapper.writeValue(response.getOutputStream(),info); + + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + this.doPost(request, response); + + } +} diff --git a/src/src_houduan/web/servlet/waterQualityStation/FindAlllStationServlet.java b/src/src_houduan/web/servlet/waterQualityStation/FindAlllStationServlet.java new file mode 100644 index 0000000..6c60b51 --- /dev/null +++ b/src/src_houduan/web/servlet/waterQualityStation/FindAlllStationServlet.java @@ -0,0 +1,35 @@ +package web.servlet.waterQualityStation; + +import com.fasterxml.jackson.databind.ObjectMapper; +import domain.WaterQualityStation; +import service.WaterQualityStationService; +import service.impl.WaterQualityStationServiceImpl; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.List; + +@WebServlet("/FindAlllStationServlet") +public class FindAlllStationServlet extends HttpServlet +{ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + WaterQualityStationService service=new WaterQualityStationServiceImpl(); + List list = service.findAll(); + ObjectMapper mapper=new ObjectMapper(); + response.setContentType("application/json;charset=utf-8"); + mapper.writeValue(response.getOutputStream(),list); + + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + this.doPost(request, response); + + } +} diff --git a/src/src_houduan/web/servlet/waterQualityStation/FindByNameAndTimeServlet.java b/src/src_houduan/web/servlet/waterQualityStation/FindByNameAndTimeServlet.java new file mode 100644 index 0000000..97ee060 --- /dev/null +++ b/src/src_houduan/web/servlet/waterQualityStation/FindByNameAndTimeServlet.java @@ -0,0 +1,60 @@ +package web.servlet.waterQualityStation; + +import com.fasterxml.jackson.databind.ObjectMapper; +import domain.WaterQuality; +import service.WaterQualityService; +import service.impl.WaterQualityServiceImpl; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.List; + +/** + * @author laoyingyong + * @date: 2020-02-03 23:11 + */ +@WebServlet("/FindByNameAndTimeServlet") +public class FindByNameAndTimeServlet extends HttpServlet +{ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + String name = request.getParameter("cezhanName"); + System.out.println(name); + String star = request.getParameter("startTime"); + String startTime=null; + if(star!=null) + { + startTime=star.replace("T"," ")+":00"; + System.out.println("开始时间"+startTime); + } + String end = request.getParameter("endTime"); + String endTime=null; + if(end!=null) + { + endTime=end.replace("T"," ")+":00"; + System.out.println("结束时间"+endTime); + } + String water_level = request.getParameter("water_level"); + System.out.println("level:"+water_level); + + + WaterQualityService service=new WaterQualityServiceImpl(); + List byNameAndTime = service.findByNameAndTime(name, startTime, endTime,water_level); + System.out.println(byNameAndTime); + ObjectMapper mapper=new ObjectMapper(); + response.setContentType("application/json;chartset=utf-8"); + mapper.writeValue(response.getOutputStream(),byNameAndTime); + + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + this.doPost(request, response); + + } +} diff --git a/src/src_houduan/web/servlet/waterQualityStation/FindByPageServlet.java b/src/src_houduan/web/servlet/waterQualityStation/FindByPageServlet.java new file mode 100644 index 0000000..01fadd9 --- /dev/null +++ b/src/src_houduan/web/servlet/waterQualityStation/FindByPageServlet.java @@ -0,0 +1,65 @@ +package web.servlet.waterQualityStation; + +import com.fasterxml.jackson.databind.ObjectMapper; +import domain.PageBean; +import domain.WaterQualityStation; +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.BeanPropertyRowMapper; +import org.springframework.jdbc.core.JdbcTemplate; +import service.WaterQualityStationService; +import service.impl.WaterQualityStationServiceImpl; +import util.JDBCUtils; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.io.IOException; +import java.util.List; + +@WebServlet("/FindByPageServlet") +public class FindByPageServlet extends HttpServlet +{ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + WaterQualityStationService service=new WaterQualityStationServiceImpl(); + int totalCount = service.findTotalCount();//总记录数 + + String currentPage = request.getParameter("currentPage"); + String pageSize = request.getParameter("pageSize"); + int intCurrentPage=1; + int intPageSize=10; + try { + intCurrentPage = Integer.parseInt(currentPage); + intPageSize = Integer.parseInt(pageSize); + } catch (NumberFormatException e) { + System.out.println(e); + } + if(intCurrentPage==0) + { + intCurrentPage=1; + } + int totalPage=totalCount%intPageSize==0?totalCount/intPageSize:(totalCount/intPageSize+1); + if (intCurrentPage>totalPage) + { + intCurrentPage=totalPage; + } + PageBean pageBean = service.getPageBean(intCurrentPage, intPageSize); + System.out.println(pageBean); + + ObjectMapper mapper=new ObjectMapper(); + response.setContentType("application/json;charset=utf-8"); + mapper.writeValue(response.getOutputStream(),pageBean); + + + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + this.doPost(request, response); + + } +} diff --git a/src/src_houduan/web/servlet/waterQualityStation/FindIntroServlet.java b/src/src_houduan/web/servlet/waterQualityStation/FindIntroServlet.java new file mode 100644 index 0000000..d3cffc1 --- /dev/null +++ b/src/src_houduan/web/servlet/waterQualityStation/FindIntroServlet.java @@ -0,0 +1,38 @@ +package web.servlet.waterQualityStation; + +import com.fasterxml.jackson.databind.ObjectMapper; +import domain.WaterQualityStation; +import service.WaterQualityStationService; +import service.impl.WaterQualityStationServiceImpl; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@WebServlet("/FindIntroServlet") +public class FindIntroServlet extends HttpServlet +{ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + String id = request.getParameter("id"); + int intId = Integer.parseInt(id); + System.out.println(intId); + + WaterQualityStationService service=new WaterQualityStationServiceImpl(); + WaterQualityStation station = service.findIntroById(intId); + ObjectMapper mapper=new ObjectMapper(); + response.setContentType("application/json;charset=utf-8"); + mapper.writeValue(response.getOutputStream(),station); + + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + this.doPost(request, response); + + } +} diff --git a/src/src_houduan/web/servlet/waterQualityStation/FindLocationByNameServlet.java b/src/src_houduan/web/servlet/waterQualityStation/FindLocationByNameServlet.java new file mode 100644 index 0000000..0bf1013 --- /dev/null +++ b/src/src_houduan/web/servlet/waterQualityStation/FindLocationByNameServlet.java @@ -0,0 +1,36 @@ +package web.servlet.waterQualityStation; + +import com.fasterxml.jackson.databind.ObjectMapper; +import domain.WaterQualityStation; +import service.WaterQualityStationService; +import service.impl.WaterQualityStationServiceImpl; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@WebServlet("/FindLocationByNameServlet") +public class FindLocationByNameServlet extends HttpServlet +{ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + request.setCharacterEncoding("utf-8"); + String stationName = request.getParameter("stationName"); + WaterQualityStationService service=new WaterQualityStationServiceImpl(); + WaterQualityStation station = service.findByName(stationName); + ObjectMapper mapper=new ObjectMapper(); + response.setContentType("application/json;charset=utf-8"); + mapper.writeValue(response.getOutputStream(),station); + + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + this.doPost(request, response); + + } +} diff --git a/src/src_houduan/web/servlet/waterQualityStation/FindPollutedSiteServlet.java b/src/src_houduan/web/servlet/waterQualityStation/FindPollutedSiteServlet.java new file mode 100644 index 0000000..a4d9051 --- /dev/null +++ b/src/src_houduan/web/servlet/waterQualityStation/FindPollutedSiteServlet.java @@ -0,0 +1,39 @@ +package web.servlet.waterQualityStation; + +import com.fasterxml.jackson.databind.ObjectMapper; +import domain.WaterQualityStation; +import service.WaterQualityStationService; +import service.impl.WaterQualityStationServiceImpl; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.List; + +/** + * @author laoyingyong + * @date: 2020-02-01 22:29 + */ +@WebServlet("/FindPollutedSiteServlet") +public class FindPollutedSiteServlet extends HttpServlet +{ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + WaterQualityStationService service=new WaterQualityStationServiceImpl(); + List pollutedSite = service.findPollutedSite(); + ObjectMapper mapper=new ObjectMapper(); + response.setContentType("application/json;chartset=utf-8"); + mapper.writeValue(response.getOutputStream(),pollutedSite); + + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + this.doPost(request, response); + + } +} diff --git a/src/src_houduan/web/servlet/waterQualityStation/FindSimIntroServlet.java b/src/src_houduan/web/servlet/waterQualityStation/FindSimIntroServlet.java new file mode 100644 index 0000000..2eb25ae --- /dev/null +++ b/src/src_houduan/web/servlet/waterQualityStation/FindSimIntroServlet.java @@ -0,0 +1,55 @@ +package web.servlet.waterQualityStation; + +import com.fasterxml.jackson.databind.ObjectMapper; +import domain.WaterQualityStation; +import service.WaterQualityStationService; +import service.impl.WaterQualityStationServiceImpl; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * @author laoyingyong + * @date: 2020-02-03 14:21 + */ +@WebServlet("/FindSimIntroServlet") +public class FindSimIntroServlet extends HttpServlet +{ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + String zuobiao = request.getParameter("zuobiao"); + System.out.println("坐标是:"+zuobiao); + String[] split = zuobiao.split(","); + String lo=split[0]; + String la=split[1]; + double longitude=0; + double latitude=0; + try + { + longitude=Double.parseDouble(lo); + latitude=Double.parseDouble(la); + } catch (NumberFormatException e) + { + System.out.println(e); + } + + WaterQualityStationService service=new WaterQualityStationServiceImpl(); + WaterQualityStation station = service.findIntro(longitude, latitude); + ObjectMapper mapper=new ObjectMapper(); + response.setContentType("application/json/chartset=utf-8"); + mapper.writeValue(response.getOutputStream(),station); + + + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + this.doPost(request, response); + + } +} diff --git a/src/src_houduan/web/servlet/waterQualityStation/FindStationAndQualityServlet.java b/src/src_houduan/web/servlet/waterQualityStation/FindStationAndQualityServlet.java new file mode 100644 index 0000000..5cf651d --- /dev/null +++ b/src/src_houduan/web/servlet/waterQualityStation/FindStationAndQualityServlet.java @@ -0,0 +1,52 @@ +package web.servlet.waterQualityStation; + +import com.fasterxml.jackson.databind.ObjectMapper; +import domain.StationAndQuality; +import service.WaterQualityStationService; +import service.impl.WaterQualityStationServiceImpl; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * @author laoyingyong + * @date: 2020-02-03 17:07 + */ +@WebServlet("/FindStationAndQualityServlet") +public class FindStationAndQualityServlet extends HttpServlet +{ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + String lo = request.getParameter("jingdu"); + System.out.println("经度是:"+lo); + + String la = request.getParameter("weidu"); + System.out.println("纬度是:"+la); + double longitude=0; + double latitude=0; + try { + longitude=Double.parseDouble(lo); + latitude=Double.parseDouble(la); + } catch (NumberFormatException e) { + System.out.println(e); + } + + WaterQualityStationService service=new WaterQualityStationServiceImpl(); + StationAndQuality stationAndQuality = service.findStationAndQuality(longitude, latitude); + ObjectMapper mapper=new ObjectMapper(); + response.setContentType("application/json;chartset=utf-8"); + mapper.writeValue(response.getOutputStream(),stationAndQuality); + + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + this.doPost(request, response); + + } +} diff --git a/src/src_houduan/web/servlet/waterQualityStation/IndexingServlet.java b/src/src_houduan/web/servlet/waterQualityStation/IndexingServlet.java new file mode 100644 index 0000000..0af58a8 --- /dev/null +++ b/src/src_houduan/web/servlet/waterQualityStation/IndexingServlet.java @@ -0,0 +1,39 @@ +package web.servlet.waterQualityStation; + +import com.fasterxml.jackson.databind.ObjectMapper; +import domain.StationAndQuality; +import service.WaterQualityStationService; +import service.impl.WaterQualityStationServiceImpl; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.List; + +/** + * @author laoyingyong + * @date: 2020-02-08 11:32 + */ +@WebServlet("/IndexingServlet") +public class IndexingServlet extends HttpServlet +{ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + WaterQualityStationService service=new WaterQualityStationServiceImpl(); + List list = service.indexing(); + ObjectMapper mapper=new ObjectMapper(); + response.setContentType("application/json;chartset-utf-8"); + mapper.writeValue(response.getOutputStream(),list); + + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + this.doPost(request, response); + + } +} diff --git a/src/src_houduan/web/servlet/waterQualityStation/UpdateStationInfoServlet.java b/src/src_houduan/web/servlet/waterQualityStation/UpdateStationInfoServlet.java new file mode 100644 index 0000000..5960a71 --- /dev/null +++ b/src/src_houduan/web/servlet/waterQualityStation/UpdateStationInfoServlet.java @@ -0,0 +1,70 @@ +package web.servlet.waterQualityStation; + +import com.fasterxml.jackson.databind.ObjectMapper; +import domain.ResultInfo; +import domain.WaterQualityStation; +import service.WaterQualityStationService; +import service.impl.WaterQualityStationServiceImpl; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@WebServlet("/UpdateStationInfoServlet") +public class UpdateStationInfoServlet extends HttpServlet +{ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + request.setCharacterEncoding("utf-8"); + String id = request.getParameter("id"); + String stationName = request.getParameter("stationName"); + String longitude = request.getParameter("longitude"); + System.out.println(longitude); + String latitude = request.getParameter("latitude"); + System.out.println(latitude); + String section = request.getParameter("section"); + String introduction = request.getParameter("introduction"); + + WaterQualityStation station=new WaterQualityStation(); + try + { + station.setId(Integer.parseInt(id)); + station.setStationName(stationName); + station.setLongitude(Double.parseDouble(longitude)); + station.setLatitude(Double.parseDouble(latitude)); + station.setSection(section); + station.setIntroduction(introduction); + } catch (Exception e) + { + System.out.println(e); + } + + + WaterQualityStationService service=new WaterQualityStationServiceImpl(); + boolean flag = service.update(station); + ResultInfo info=new ResultInfo(); + if(flag) + { + info.setMsg("更新成功!"); + } + else + { + info.setMsg("更新失败!"); + } + + ObjectMapper mapper=new ObjectMapper(); + response.setContentType("appilication/json;charset=utf-8"); + mapper.writeValue(response.getOutputStream(),info); + + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + this.doPost(request, response); + + } +}