Compare commits
3 Commits
9944f93c1a
...
bfeea7ea53
Author | SHA1 | Date |
---|---|---|
ysh | bfeea7ea53 | 2 years ago |
易俊弛 | 497947fd4b | 2 years ago |
易俊弛 | 404fe6625a | 2 years ago |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 50 KiB |
After Width: | Height: | Size: 27 KiB |
After Width: | Height: | Size: 21 KiB |
Binary file not shown.
@ -0,0 +1,47 @@
|
||||
package dao;
|
||||
|
||||
|
||||
|
||||
import domain.User;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 用户操作的DAO
|
||||
*/
|
||||
public interface UserDao {
|
||||
|
||||
|
||||
public List<User> 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<String, String[]> condition);
|
||||
|
||||
/**
|
||||
* 分页查询每页记录
|
||||
* @param start
|
||||
* @param rows
|
||||
* @param condition
|
||||
* @return
|
||||
*/
|
||||
List<User> findByPage(int start, int rows, Map<String, String[]> condition);
|
||||
|
||||
boolean updateUserInfo(User user);
|
||||
}
|
@ -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<WaterQualityStation> findAll();
|
||||
public abstract WaterQualityStation findByName(String stationName);
|
||||
public abstract WaterQualityStation findIntroByName(String name);
|
||||
public abstract boolean addWaterQualityStation(WaterQualityStation station);
|
||||
public abstract List<WaterQualityStation> findByPage(int start,int pageSize);
|
||||
public abstract int findTotalCount();
|
||||
public abstract WaterQualityStation findIntroById(int id);
|
||||
public abstract List<WaterQualityStation> conditonalQueryByPage(int start, int pageSize, Map<String,String[]> condition);
|
||||
public abstract int conditionalFindAllCount(Map<String, String[]> condition);
|
||||
public abstract boolean update(WaterQualityStation station);
|
||||
public abstract boolean delete(int id);
|
||||
public abstract List<WaterQualityStation> findPollutedSite();
|
||||
public abstract WaterQualityStation findIntro(double longitude,double latitude);
|
||||
|
||||
public abstract StationAndQuality findStationAndQuality(double longitude,double latitude);
|
||||
|
||||
public abstract List<StationAndQuality> indexing();
|
||||
}
|
@ -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<User> findAll() {
|
||||
//使用JDBC操作数据库...
|
||||
//1.定义sql
|
||||
String sql = "select * from user";
|
||||
List<User> users = template.query(sql, new BeanPropertyRowMapper<User>(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>(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>(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<String, String[]> condition) {
|
||||
//1.定义模板初始化sql
|
||||
String sql = "select count(*) from user where 1 = 1 ";
|
||||
StringBuilder sb = new StringBuilder(sql);
|
||||
//2.遍历map
|
||||
Set<String> keySet = condition.keySet();
|
||||
//定义参数的集合
|
||||
List<Object> params = new ArrayList<Object>();
|
||||
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<User> findByPage(int start, int rows, Map<String, String[]> condition) {
|
||||
String sql = "select * from user where 1 = 1 ";
|
||||
|
||||
StringBuilder sb = new StringBuilder(sql);
|
||||
//2.遍历map
|
||||
Set<String> keySet = condition.keySet();
|
||||
//定义参数的集合
|
||||
List<Object> params = new ArrayList<Object>();
|
||||
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>(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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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<User> 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<User> findUserByPage(String currentPage, String rows, Map<String, String[]> condition);
|
||||
|
||||
|
||||
boolean updateUserInfo(User user);
|
||||
}
|
@ -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<WaterQualityStation> 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<WaterQualityStation> getPageBean(int currentPage,int pageSize);
|
||||
public abstract WaterQualityStation findIntroById(int id);
|
||||
public abstract PageBean<WaterQualityStation> conditonalQueryByPage(int currentPage, int pageSize, Map<String,String[]> condition);
|
||||
public abstract int conditionalFindAllCount(Map<String, String[]> condition);
|
||||
public abstract boolean update(WaterQualityStation station);
|
||||
public abstract boolean delete(int id);
|
||||
public abstract List<WaterQualityStation> findPollutedSite();
|
||||
public abstract WaterQualityStation findIntro(double longitude,double latitude);
|
||||
public abstract StationAndQuality findStationAndQuality(double longitude, double latitude);
|
||||
public abstract List<StationAndQuality> indexing();
|
||||
}
|
@ -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<User> 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<User> findUserByPage(String _currentPage, String _rows, Map<String, String[]> condition) {
|
||||
|
||||
int currentPage = Integer.parseInt(_currentPage);
|
||||
int rows = Integer.parseInt(_rows);
|
||||
|
||||
if(currentPage <=0) {
|
||||
currentPage = 1;
|
||||
}
|
||||
//1.创建空的PageBean对象
|
||||
PageBean<User> pb = new PageBean<User>();
|
||||
//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<User> 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;
|
||||
}
|
||||
}
|
@ -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<WaterQualityStation> 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<WaterQualityStation> getPageBean(int currentPage, int pageSize)
|
||||
{
|
||||
PageBean<WaterQualityStation> 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<WaterQualityStation> 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<WaterQualityStation> conditonalQueryByPage(int currentPage, int pageSize, Map<String, String[]> condition)
|
||||
{
|
||||
PageBean<WaterQualityStation> 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<WaterQualityStation> list = dao.conditonalQueryByPage((currentPage - 1) * pageSize, pageSize, condition);
|
||||
pageBean.setList(list);
|
||||
return pageBean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int conditionalFindAllCount(Map<String, String[]> 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<WaterQualityStation> 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<StationAndQuality> indexing()
|
||||
{
|
||||
return dao.indexing();
|
||||
}
|
||||
}
|
@ -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<String, String[]> 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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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<String, String[]> condition = request.getParameterMap();
|
||||
|
||||
|
||||
//2.调用service查询
|
||||
UserService service = new UserServiceImpl();
|
||||
PageBean<User> 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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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<String, String[]> 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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
@ -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<String, String[]> 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);
|
||||
}
|
||||
}
|
@ -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<User> 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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
@ -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<String, String[]> 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<WaterQualityStation> 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);
|
||||
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
@ -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<WaterQualityStation> 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);
|
||||
|
||||
}
|
||||
}
|
@ -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<WaterQuality> 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);
|
||||
|
||||
}
|
||||
}
|
@ -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<WaterQualityStation> 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);
|
||||
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
@ -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<WaterQualityStation> 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);
|
||||
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
@ -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<StationAndQuality> 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);
|
||||
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in new issue