首页>代码>springMVC+Mybatis+Spring+Easyui+zTree+ueditor+highchart企业IT信息管理系统>/IT_M - 副本/src/com/gree/ssm/controller/DbController.java
package com.gree.ssm.controller; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.github.pagehelper.PageInfo; import com.gree.ssm.po.BaseData; import com.gree.ssm.po.DBCustom; import com.gree.ssm.po.Db; import com.gree.ssm.po.Server; import com.gree.ssm.po.TableInfo; import com.gree.ssm.po.UserInfo; import com.gree.ssm.service.BaseDataService; import com.gree.ssm.service.DbService; import com.gree.ssm.service.ServerService; import com.gree.ssm.util.DBTest; /** * 服务器管理 * * @author Administrator * */ @Controller @RequestMapping("/db") public class DbController { @Autowired private DbService dbService; @Autowired private ServerService serverService; @Autowired private BaseDataService baseDataService; @RequestMapping("/opDB") public String opDB(Model model, HttpServletRequest request, HttpServletResponse response) throws Exception { // 页面转发 return "DBManager"; } @RequestMapping("/opMyDB") public String opMyDB(Model model, HttpServletRequest request, HttpServletResponse response) throws Exception { // 页面转发 return "DBManager_User"; } /** * 管理基础数据 * * @param request * @param response * @param dbName * @param page * @param rows * @return * @throws Exception */ @RequestMapping("/query") public @ResponseBody Map<String, Object> query(HttpServletRequest request, HttpServletResponse response, DBCustom db, Integer page, Integer rows) throws Exception { Map<String, Object> re = new HashMap<String, Object>(); PageInfo<DBCustom> pageInfo = dbService.findPage(db, page, rows); if (pageInfo.getTotal() > 0) { re.put("total", pageInfo.getTotal()); re.put("rows", pageInfo.getList()); } else { re.put("total", 0); re.put("rows", new ArrayList<DBCustom>()); } return re; } @RequestMapping("/queryByUser") public @ResponseBody Map<String, Object> queryByUser(HttpServletRequest request, HttpServletResponse response, DBCustom db, Integer page, Integer rows) throws Exception { Map<String, Object> re = new HashMap<String, Object>(); HttpSession session = request.getSession(); UserInfo userInfo = (UserInfo) session.getAttribute("userinfo"); PageInfo<DBCustom> pageInfo = dbService.findPageByUser(db,userInfo, page, rows); if (pageInfo.getTotal() > 0) { re.put("total", pageInfo.getTotal()); re.put("rows", pageInfo.getList()); } else { re.put("total", 0); re.put("rows", new ArrayList<DBCustom>()); } return re; } @RequestMapping("/loadAll") public @ResponseBody List<Db> loadAll(HttpServletRequest request, HttpServletResponse response) throws Exception { List<Db> list = dbService.loadAll(); return list; } @RequestMapping("/queryTable") public @ResponseBody Map<String, Object> queryTable(HttpServletRequest request, HttpServletResponse response, TableInfo tb, Integer page, Integer rows) throws Exception { Map<String, Object> re = new HashMap<String, Object>(); PageInfo<TableInfo> pageInfo = dbService.findPage(tb, page, rows); if (pageInfo.getTotal() > 0) { re.put("total", pageInfo.getTotal()); re.put("rows", pageInfo.getList()); } else { re.put("total", 0); re.put("rows", new ArrayList<TableInfo>()); } return re; } @RequestMapping("/updateTable") public @ResponseBody Map<String, Object> updateTable(HttpServletRequest request, HttpServletResponse response, TableInfo tb) throws Exception { Map<String, Object> re = new HashMap<String, Object>(); boolean result = dbService.updateTable(tb); if (result) { re.put("success", true); re.put("msg", "修改成功"); } else { re.put("success", false); re.put("msg", "修改失败"); } return re; } @RequestMapping("/querySelf") public @ResponseBody Map<String, Object> querySelf(HttpServletRequest request, HttpServletResponse response, Db db, Integer page, Integer rows) throws Exception { Map<String, Object> re = new HashMap<String, Object>(); PageInfo<Db> pageInfo = dbService.findPage(db, page, rows); if (pageInfo.getTotal() > 0) { re.put("total", pageInfo.getTotal()); re.put("rows", pageInfo.getList()); } else { re.put("total", 0); re.put("rows", new ArrayList<Db>()); } return re; } /** * 修改 * * @param request * @param response * @param BaseDataCustom * @return * @throws Exception */ @RequestMapping("/update") public @ResponseBody Map<String, Object> update(HttpServletRequest request, HttpServletResponse response, Db db) throws Exception { Map<String, Object> re = new HashMap<String, Object>(); boolean result = dbService.update(db); if (result) { re.put("success", true); re.put("msg", "修改成功"); } else { re.put("success", false); re.put("msg", "修改失败"); } return re; } /** * 添加数据库 * * @param request * @param response * @param BaseDataCustom * @return * @throws Exception */ @RequestMapping("/add") public @ResponseBody Map<String, Object> add(HttpServletRequest request, HttpServletResponse response, Db db) throws Exception { Map<String, Object> re = new HashMap<String, Object>(); HttpSession session = request.getSession(); UserInfo userInfo = (UserInfo) session.getAttribute("userinfo"); db.setUserCode(userInfo.getUserCode()); boolean result = dbService.add(db); if (result) { re.put("success", true); re.put("msg", "添加成功"); } else { re.put("success", false); re.put("msg", "添加失败"); } return re; } /** * 删除数据库 * * @return */ @RequestMapping("/delete") public @ResponseBody Map<Object, Object> delete(Integer[] ids) { Map<Object, Object> resMap = new HashMap<Object, Object>(); boolean result = dbService.deleteByIds(ids); if (result) { resMap.put("success", true); resMap.put("msg", "删除成功!"); } else { resMap.put("success", false); resMap.put("msg", "删除失败!"); } return resMap; } /** * 删除表 * @param id * @return */ @RequestMapping("/deleteTable") public @ResponseBody Map<Object, Object> deleteTable(Integer id) { Map<Object, Object> resMap = new HashMap<Object, Object>(); boolean result = dbService.deleteByTableId(id); if (result) { resMap.put("success", true); resMap.put("msg", "删除成功!"); } else { resMap.put("success", false); resMap.put("msg", "删除失败!"); } return resMap; } /** * 打开详细页面 * * @param model * @param request * @param response * @param dbId * @return * @throws Exception */ @RequestMapping("/showAllDetail") public String showAllDetail(Model model, HttpServletRequest request, HttpServletResponse response, Integer dbId) throws Exception { Db db = dbService.querAllDetail(dbId); Server server = serverService.querAllDetail(db.getServerId()); if (db == null || server == null) { return "error"; } model.addAttribute("db", db); model.addAttribute("server", server); return "ShowDBDetail"; } @RequestMapping("/testCon") public @ResponseBody Map<Object, Object> testCon(Integer dbId) { Map<Object, Object> resMap = new HashMap<Object, Object>(); Db db = dbService.querAllDetail(dbId);// 获取数据库信息 Server server = serverService.querAllDetail(db.getServerId());// 获取服务器信息 BaseData baseData = baseDataService.load(db.getDbType());// 根据数据库类型获取对应驱动信息 if ("ORACLE".equals(db.getDbType()) || "MySQL".equals(db.getDbType()) || "SQL Server".equals(db.getDbType())) { boolean result = DBTest.testDb(db, server, baseData.getDataGroup()); if (result) { resMap.put("success", true); resMap.put("msg", "连接正常"); } else { resMap.put("success", true); resMap.put("msg", "连接异常"); } } else { resMap.put("success", true); resMap.put("msg", "暂不支持该数据库!"); } return resMap; } @RequestMapping("/addTable") public @ResponseBody Map<String, Object> addTable(HttpServletRequest request, HttpServletResponse response, TableInfo tb) throws Exception { Map<String, Object> re = new HashMap<String, Object>(); boolean result = dbService.addTable(tb); if (result) { re.put("success", true); re.put("msg", "添加成功"); } else { re.put("success", false); re.put("msg", "添加失败"); } return re; } }
最近下载更多
zhaoyangwfd LV17
2022年1月20日
wanglinddad LV55
2022年1月19日
543666826 LV33
2021年11月18日
2231788897 LV6
2021年10月20日
lewis365 LV2
2021年8月22日
ericxu1116 LV24
2021年6月7日
幸运疯子 LV13
2021年5月16日
小屁孩 LV7
2021年4月11日
skipple3 LV39
2020年11月26日
ddqddqddq LV14
2020年9月5日