• Java项目:教师师资管理系统(java+SSM+JSP+bootstrap+Mysql)


    源码获取:俺的博客首页 "资源" 里下载!

    项目介绍


    本项目包含管理员与教师两种角色;

    管理员角色包含以下功能:
    管理员角色登录,教师管理,教师授课管理,审批教师的项目开题,项目详情审批,项目总结审批,公告管理等功能。

    教师角色包含以下功能:
    教师角色登录,修改个人信息,修改密码,公告列表管理,开题审批管理,项目排名,项目详情审批管理,项目总结管理等功能。


    环境需要

    1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
    2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
    3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
    4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 
    5.数据库:MySql 5.7/8.0版本均可;
    6.是否Maven项目:是;


    技术栈

    1. 后端:Spring+SpringMVC+Mybatis
    2. 前端:Jsp+CSS+JavaScript+jQuery+bootstrap


    使用说明

    1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
    2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
    若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
    3. 将项目中db.properties配置文件中的数据库配置改为自己的配置;
    4. 运行项目,输入localhost:8080/ 登录

     

     

     

     

     

    教师管理控制层: 

    1. @Controller
    2. @RequestMapping("/teacher")
    3. public class TeacherController extends BaseController {
    4. /**
    5. * 依赖注入 start dao/service/===
    6. */
    7. @Autowired
    8. private TeacherService teacherService;
    9. // --------------------------------------- 华丽分割线 ------------------------------
    10. /**
    11. * 分页查询 返回list对象(通过对By Sql)
    12. *
    13. * @param request
    14. * @param response
    15. * @return
    16. */
    17. @RequestMapping(value = "/findBySql")
    18. public String findBySql(Teacher teacher, Model model, HttpServletRequest request, HttpServletResponse response) {
    19. //分页查询
    20. String sql = "SELECT * FROM teacher WHERE isDelete = 0 ";
    21. if(!isEmpty(teacher.getUsername())){
    22. sql += " and username like '%"+teacher.getUsername()+"%'";
    23. }
    24. if(!isEmpty(teacher.getSex())){
    25. sql += " and sex like '%"+teacher.getSex()+"%'";
    26. }
    27. if(!isEmpty(teacher.getPassword())){
    28. sql += " and password like '%"+teacher.getPassword()+"%'";
    29. }
    30. if(!isEmpty(teacher.getXw())){
    31. sql += " and xw like '%"+teacher.getXw()+"%'";
    32. }
    33. if(!isEmpty(teacher.getPhone())){
    34. sql += " and phone like '%"+teacher.getPhone()+"%'";
    35. }
    36. if(!isEmpty(teacher.getIsDelete())){
    37. sql += " and isDelete like '%"+teacher.getIsDelete()+"%'";
    38. }
    39. sql += " ORDER BY ID DESC ";
    40. Pager<Teacher> pagers = teacherService.findBySqlRerturnEntity(sql);
    41. model.addAttribute("pagers", pagers);
    42. //存储查询条件
    43. model.addAttribute("obj", teacher);
    44. return "teacher/teacher";
    45. }
    46. /**
    47. * 分页查询 返回list对象(通过Map)
    48. *
    49. * @param request
    50. * @param response
    51. * @return
    52. */
    53. @RequestMapping(value = "/findByMap")
    54. public String findByMap(Teacher teacher, Model model, HttpServletRequest request, HttpServletResponse response) {
    55. //通过map查询
    56. Map<String,Object> params = new HashMap<String,Object>();
    57. if(!isEmpty(teacher.getUsername())){
    58. params.put("username", teacher.getUsername());
    59. }
    60. if(!isEmpty(teacher.getSex())){
    61. params.put("sex", teacher.getSex());
    62. }
    63. if(!isEmpty(teacher.getPassword())){
    64. params.put("password", teacher.getPassword());
    65. }
    66. if(!isEmpty(teacher.getXw())){
    67. params.put("xw", teacher.getXw());
    68. }
    69. if(!isEmpty(teacher.getPhone())){
    70. params.put("phone", teacher.getPhone());
    71. }
    72. if(!isEmpty(teacher.getIsDelete())){
    73. params.put("isDelete", teacher.getIsDelete());
    74. }
    75. //分页查询
    76. Pager<Teacher> pagers = teacherService.findByMap(params);
    77. model.addAttribute("pagers", pagers);
    78. //存储查询条件
    79. model.addAttribute("obj", teacher);
    80. return "teacher/teacher";
    81. }
    82. /**********************************【增删改】******************************************************/
    83. /**
    84. * 跳至添加页面
    85. * @return
    86. */
    87. @RequestMapping(value = "/add")
    88. public String add() {
    89. return "teacher/add";
    90. }
    91. /**
    92. * 跳至详情页面
    93. * @return
    94. */
    95. @RequestMapping(value = "/view")
    96. public String view(Integer id,Model model) {
    97. Teacher obj = teacherService.load(id);
    98. model.addAttribute("obj",obj);
    99. return "teacher/view";
    100. }
    101. /**
    102. * 添加执行
    103. * @return
    104. */
    105. @RequestMapping(value = "/exAdd")
    106. public String exAdd(Teacher teacher, Model model, HttpServletRequest request, HttpServletResponse response) {
    107. teacher.setIsDelete(0);
    108. teacher.setPassword("111111");
    109. teacherService.insert(teacher);
    110. return "redirect:/teacher/findBySql.action";
    111. }
    112. /**
    113. * 跳至修改页面
    114. * @return
    115. */
    116. @RequestMapping(value = "/update")
    117. public String update(Integer id,Model model) {
    118. Teacher obj = teacherService.load(id);
    119. model.addAttribute("obj",obj);
    120. return "teacher/update";
    121. }
    122. /**
    123. * 添加修改
    124. * @return
    125. */
    126. @RequestMapping(value = "/exUpdate")
    127. public String exUpdate(Teacher teacher, Model model, HttpServletRequest request, HttpServletResponse response) {
    128. teacherService.updateById(teacher);
    129. return "redirect:/teacher/findBySql.action";
    130. }
    131. /**
    132. * 删除通过主键
    133. * @return
    134. */
    135. @RequestMapping(value = "/delete")
    136. public String delete(Integer id, Model model, HttpServletRequest request, HttpServletResponse response) {
    137. Teacher load = teacherService.load(id);
    138. load.setIsDelete(1);
    139. teacherService.updateById(load);
    140. return "redirect:/teacher/findBySql.action";
    141. }
    142. }

    管理员管理控制层:

    1. @Controller
    2. @RequestMapping("/manage")
    3. public class ManageController extends BaseController {
    4. /**
    5. * 依赖注入 start dao/service/===
    6. */
    7. @Autowired
    8. private ManageService manageService;
    9. // --------------------------------------- 华丽分割线 ------------------------------
    10. /*********************************查询列表【不分页】***********************************************/
    11. /**
    12. * 【不分页 => 查询列表 => 无条件】
    13. * @Title: listAll
    14. * @Description: TODO(这里用一句话描述这个方法的作用)
    15. * @param @return 设定文件
    16. * @author
    17. * @return String 返回类型
    18. * @throws
    19. */
    20. @RequestMapping(value = "/listAll")
    21. public String listAll(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response){
    22. List<Manage> listAll = manageService.listAll();
    23. model.addAttribute("list", listAll);
    24. return "manage/manage";
    25. }
    26. /**
    27. * 【不分页=》查询列表=>有条件】
    28. * @Title: listByEntity
    29. * @Description: TODO(这里用一句话描述这个方法的作用)
    30. * @param @return 设定文件
    31. * @author
    32. * @return String 返回类型
    33. * @throws
    34. */
    35. @RequestMapping(value = "/listByEntity")
    36. public String listByEntity(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response){
    37. List<Manage> listAll = manageService.listAllByEntity(manage);
    38. model.addAttribute("list", listAll);
    39. return "manage/manage";
    40. }
    41. /**
    42. * 【不分页=》查询列表=>有条件】
    43. * @Title: listByMap
    44. * @Description: TODO(这里用一句话描述这个方法的作用)
    45. * @param @return 设定文件
    46. * @author
    47. * @return String 返回类型
    48. * @throws
    49. */
    50. @RequestMapping(value = "/listByMap")
    51. public String listByMap(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response){
    52. //通过map查询
    53. Map<String,Object> params = new HashMap<String,Object>();
    54. if(!isEmpty(manage.getUserName())){
    55. params.put("userName", manage.getUserName());
    56. }
    57. if(!isEmpty(manage.getPassWord())){
    58. params.put("passWord", manage.getPassWord());
    59. }
    60. if(!isEmpty(manage.getRealName())){
    61. params.put("realName", manage.getRealName());
    62. }
    63. List<Manage> listAll = manageService.listByMap(params);
    64. model.addAttribute("list", listAll);
    65. return "manage/manage";
    66. }
    67. /*********************************查询列表【分页】***********************************************/
    68. /**
    69. * 分页查询 返回list对象(通过对象)
    70. *
    71. * @param request
    72. * @param response
    73. * @return
    74. */
    75. @RequestMapping(value = "/findByObj")
    76. public String findByObj(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response) {
    77. //分页查询
    78. Pager<Manage> pagers = manageService.findByEntity(manage);
    79. model.addAttribute("pagers", pagers);
    80. //存储查询条件
    81. model.addAttribute("obj", manage);
    82. return "manage/manage";
    83. }
    84. /**
    85. * 分页查询 返回list对象(通过对By Sql)
    86. *
    87. * @param request
    88. * @param response
    89. * @return
    90. */
    91. @RequestMapping(value = "/findBySql")
    92. public String findBySql(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response) {
    93. //分页查询
    94. String sql = "SELECT * FROM manage WHERE 1=1 ";
    95. if(!isEmpty(manage.getUserName())){
    96. sql += " and userName like '%"+manage.getUserName()+"%'";
    97. }
    98. if(!isEmpty(manage.getPassWord())){
    99. sql += " and passWord like '%"+manage.getPassWord()+"%'";
    100. }
    101. if(!isEmpty(manage.getRealName())){
    102. sql += " and realName like '%"+manage.getRealName()+"%'";
    103. }
    104. sql += " ORDER BY ID DESC ";
    105. Pager<Manage> pagers = manageService.findBySqlRerturnEntity(sql);
    106. model.addAttribute("pagers", pagers);
    107. //存储查询条件
    108. model.addAttribute("obj", manage);
    109. return "manage/manage";
    110. }
    111. /**
    112. * 分页查询 返回list对象(通过Map)
    113. *
    114. * @param request
    115. * @param response
    116. * @return
    117. */
    118. @RequestMapping(value = "/findByMap")
    119. public String findByMap(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response) {
    120. //通过map查询
    121. Map<String,Object> params = new HashMap<String,Object>();
    122. if(!isEmpty(manage.getUserName())){
    123. params.put("userName", manage.getUserName());
    124. }
    125. if(!isEmpty(manage.getPassWord())){
    126. params.put("passWord", manage.getPassWord());
    127. }
    128. if(!isEmpty(manage.getRealName())){
    129. params.put("realName", manage.getRealName());
    130. }
    131. //分页查询
    132. Pager<Manage> pagers = manageService.findByMap(params);
    133. model.addAttribute("pagers", pagers);
    134. //存储查询条件
    135. model.addAttribute("obj", manage);
    136. return "manage/manage";
    137. }
    138. /**********************************【增删改】******************************************************/
    139. /**
    140. * 跳至添加页面
    141. * @return
    142. */
    143. @RequestMapping(value = "/add")
    144. public String add() {
    145. return "manage/add";
    146. }
    147. /**
    148. * 跳至详情页面
    149. * @return
    150. */
    151. @RequestMapping(value = "/view")
    152. public String view(Integer id,Model model) {
    153. Manage obj = manageService.load(id);
    154. model.addAttribute("obj",obj);
    155. return "manage/view";
    156. }
    157. /**
    158. * 添加执行
    159. * @return
    160. */
    161. @RequestMapping(value = "/exAdd")
    162. public String exAdd(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response) {
    163. manageService.insert(manage);
    164. return "redirect:/manage/findBySql.action";
    165. }
    166. /**
    167. * 跳至修改页面
    168. * @return
    169. */
    170. @RequestMapping(value = "/update")
    171. public String update(Integer id,Model model) {
    172. Manage obj = manageService.load(id);
    173. model.addAttribute("obj",obj);
    174. return "manage/update";
    175. }
    176. /**
    177. * 添加修改
    178. * @return
    179. */
    180. @RequestMapping(value = "/exUpdate")
    181. public String exUpdate(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response) {
    182. //1.通过实体类修改,可以多传修改条件
    183. manageService.updateById(manage);
    184. //2.通过主键id修改
    185. //manageService.updateById(manage);
    186. return "redirect:/manage/findBySql.action";
    187. }
    188. /**
    189. * 删除通过主键
    190. * @return
    191. */
    192. @RequestMapping(value = "/delete")
    193. public String delete(Integer id, Model model, HttpServletRequest request, HttpServletResponse response) {
    194. ///1.通过主键删除
    195. manageService.deleteById(id);
    196. /*以下是多种删除方式*/
    197. // //2.通过实体条件删除
    198. // manageService.deleteByEntity(manage);
    199. // //3.通过参数删除
    200. // //通过map查询
    201. // Map<String,Object> params = new HashMap<String,Object>();
    202. //
    203. // if(!isEmpty(manage.getUserName())){
    204. // params.put("userName", manage.getUserName());
    205. // }
    206. //
    207. // if(!isEmpty(manage.getPassWord())){
    208. // params.put("passWord", manage.getPassWord());
    209. // }
    210. //
    211. // if(!isEmpty(manage.getRealName())){
    212. // params.put("realName", manage.getRealName());
    213. // }
    214. //
    215. // manageService.deleteByMap(params);
    216. // //4.状态删除
    217. // Manage load = manageService.getById(manage.getId())
    218. // load.setIsDelete(1);
    219. // manageService.update(load);
    220. //5.状态删除
    221. //Manage load = manageService.load(id);
    222. //load.setIsDelete(1);
    223. //manageService.update(load);
    224. return "redirect:/manage/findBySql.action";
    225. }
    226. // --------------------------------------- 华丽分割线 ------------------------------
    227. // --------------------------------------- 【下面是ajax操作的方法。】 ------------------------------
    228. /*********************************查询列表【不分页】***********************************************/
    229. /**
    230. * 【不分页 => 查询列表 => 无条件】
    231. * @Title: listAll
    232. * @Description: TODO(这里用一句话描述这个方法的作用)
    233. * @param @return 设定文件
    234. * @author
    235. * @return String 返回类型
    236. * @throws
    237. */
    238. @RequestMapping(value = "/listAllJson", method = RequestMethod.POST)
    239. @ResponseBody
    240. public String listAllJson(Manage manage, HttpServletRequest request, HttpServletResponse response){
    241. List<Manage> listAll = manageService.listAll();
    242. JSONObject jsonObject = new JSONObject();
    243. jsonObject.put("list", listAll);
    244. jsonObject.put("obj", manage);
    245. return jsonObject.toString();
    246. }
    247. /**
    248. * 【不分页=》查询列表=>有条件】
    249. * @Title: listByEntity
    250. * @Description: TODO(这里用一句话描述这个方法的作用)
    251. * @param @return 设定文件
    252. * @author
    253. * @return String 返回类型
    254. * @throws
    255. */
    256. @RequestMapping(value = "/listByEntityJson", method = RequestMethod.POST)
    257. @ResponseBody
    258. public String listByEntityJson(Manage manage, HttpServletRequest request, HttpServletResponse response){
    259. List<Manage> listAll = manageService.listAllByEntity(manage);
    260. JSONObject jsonObject = new JSONObject();
    261. jsonObject.put("list", listAll);
    262. jsonObject.put("obj", manage);
    263. return jsonObject.toString();
    264. }
    265. /**
    266. * 【不分页=》查询列表=>有条件】
    267. * @Title: listByMap
    268. * @Description: TODO(这里用一句话描述这个方法的作用)
    269. * @param @return 设定文件
    270. * @author
    271. * @return String 返回类型
    272. * @throws
    273. */
    274. @RequestMapping(value = "/listByMapJson", method = RequestMethod.POST)
    275. @ResponseBody
    276. public String listByMapJson(Manage manage,HttpServletRequest request, HttpServletResponse response){
    277. //通过map查询
    278. Map<String,Object> params = new HashMap<String,Object>();
    279. if(!isEmpty(manage.getUserName())){
    280. params.put("userName", manage.getUserName());
    281. }
    282. if(!isEmpty(manage.getPassWord())){
    283. params.put("passWord", manage.getPassWord());
    284. }
    285. if(!isEmpty(manage.getRealName())){
    286. params.put("realName", manage.getRealName());
    287. }
    288. List<Manage> listAll = manageService.listByMap(params);
    289. JSONObject jsonObject = new JSONObject();
    290. jsonObject.put("list", listAll);
    291. jsonObject.put("obj", manage);
    292. return jsonObject.toString();
    293. }
    294. /**
    295. * 分页查询 返回list json(通过对象)
    296. *
    297. * @param request
    298. * @param response
    299. * @return
    300. */
    301. @RequestMapping(value = "/findByObjJson", method = RequestMethod.POST)
    302. @ResponseBody
    303. public String findByObjByEntityJson(Manage manage, HttpServletRequest request, HttpServletResponse response) {
    304. //分页查询
    305. Pager<Manage> pagers = manageService.findByEntity(manage);
    306. JSONObject jsonObject = new JSONObject();
    307. jsonObject.put("pagers", pagers);
    308. jsonObject.put("obj", manage);
    309. return jsonObject.toString();
    310. }
    311. /**
    312. * 分页查询 返回list json(通过Map)
    313. *
    314. * @param request
    315. * @param response
    316. * @return
    317. */
    318. @RequestMapping(value = "/findByMapJson", method = RequestMethod.POST)
    319. @ResponseBody
    320. public String findByMapJson(Manage manage,HttpServletRequest request, HttpServletResponse response) {
    321. //通过map查询
    322. Map<String,Object> params = new HashMap<String,Object>();
    323. if(!isEmpty(manage.getUserName())){
    324. params.put("userName", manage.getUserName());
    325. }
    326. if(!isEmpty(manage.getPassWord())){
    327. params.put("passWord", manage.getPassWord());
    328. }
    329. if(!isEmpty(manage.getRealName())){
    330. params.put("realName", manage.getRealName());
    331. }
    332. //分页查询
    333. Pager<Manage> pagers = manageService.findByMap(params);
    334. JSONObject jsonObject = new JSONObject();
    335. jsonObject.put("pagers", pagers);
    336. jsonObject.put("obj", manage);
    337. return jsonObject.toString();
    338. }
    339. /**
    340. * ajax 添加
    341. * @param
    342. * @return
    343. */
    344. @RequestMapping(value = "/exAddJson", method = RequestMethod.POST)
    345. @ResponseBody
    346. public String exAddJson(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response) {
    347. manageService.insert(manage);
    348. JSONObject jsonObject = new JSONObject();
    349. jsonObject.put("message", "添加成功");
    350. return jsonObject.toString();
    351. }
    352. /**
    353. * ajax 修改
    354. * @param
    355. * @return
    356. */
    357. @RequestMapping(value = "/exUpdate.json", method = RequestMethod.POST)
    358. @ResponseBody
    359. public String exUpdateJson(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response) {
    360. //1.通过实体类修改,可以多传修改条件
    361. manageService.updateById(manage);
    362. //2.通过主键id修改
    363. //manageService.updateById(manage);
    364. JSONObject jsonObject = new JSONObject();
    365. jsonObject.put("message", "修改成功");
    366. return jsonObject.toString();
    367. }
    368. /**
    369. * ajax 删除
    370. * @return
    371. */
    372. @RequestMapping(value = "/delete.json", method = RequestMethod.POST)
    373. @ResponseBody
    374. public String exDeleteJson(Integer id, Model model, HttpServletRequest request, HttpServletResponse response) {
    375. ///1.通过主键删除
    376. manageService.deleteById(id);
    377. /*以下是多种删除方式*/
    378. // //2.通过实体条件删除
    379. // manageService.deleteByEntity(manage);
    380. // //3.通过参数删除
    381. // //通过map查询
    382. // Map<String,Object> params = new HashMap<String,Object>();
    383. //
    384. // if(!isEmpty(manage.getUserName())){
    385. // params.put("userName", manage.getUserName());
    386. // }
    387. //
    388. // if(!isEmpty(manage.getPassWord())){
    389. // params.put("passWord", manage.getPassWord());
    390. // }
    391. //
    392. // if(!isEmpty(manage.getRealName())){
    393. // params.put("realName", manage.getRealName());
    394. // }
    395. //
    396. // manageService.deleteByMap(params);
    397. // //4.状态删除
    398. // Manage load = manageService.getById(manage.getId())
    399. // load.setIsDelete(1);
    400. // manageService.updateById(load);
    401. //5.状态删除
    402. //Manage load = manageService.load(id);
    403. //load.setIsDelete(1);
    404. //manageService.updateById(load);
    405. JSONObject jsonObject = new JSONObject();
    406. jsonObject.put("message", "删除成功");
    407. return jsonObject.toString();
    408. }
    409. /**
    410. * 单文件上传
    411. * @param file
    412. * @param request
    413. * @param model
    414. * @return
    415. */
    416. @RequestMapping(value = "/saveFile")
    417. public String saveFile(@RequestParam(value = "file", required = false) MultipartFile file, HttpServletRequest request, Model model) {
    418. System.out.println("开始");
    419. String path = request.getSession().getServletContext().getRealPath("/upload");
    420. String fileName = file.getOriginalFilename();
    421. System.out.println(path);
    422. File targetFile = new File(path, fileName);
    423. if(!targetFile.exists()){
    424. targetFile.mkdirs();
    425. }
    426. //保存
    427. try {
    428. file.transferTo(targetFile);
    429. } catch (Exception e) {
    430. e.printStackTrace();
    431. }
    432. return "";
    433. }
    434. /**
    435. * springMvc多文件上传
    436. * @param files
    437. * @param id
    438. * @return
    439. */
    440. @RequestMapping(value = "/saveFiles")
    441. public String saveFiles(@RequestParam("file") CommonsMultipartFile[] files,Integer id,HttpServletRequest request){
    442. for(int i = 0;i<files.length;i++){
    443. System.out.println("fileName---------->" + files[i].getOriginalFilename());
    444. if(!files[i].isEmpty()){
    445. int pre = (int) System.currentTimeMillis();
    446. try {
    447. //拿到输出流,同时重命名上传的文件
    448. String filePath = request.getRealPath("/upload");
    449. File f=new File(filePath);
    450. if(!f.exists()){
    451. f.mkdirs();
    452. }
    453. String fileNmae=new Date().getTime() + files[i].getOriginalFilename();
    454. File file=new File(filePath+"/"+pre + files[i].getOriginalFilename());
    455. if(!file.exists()){
    456. file.createNewFile();
    457. }
    458. files[i].transferTo(file);
    459. } catch (Exception e) {
    460. e.printStackTrace();
    461. System.out.println("上传出错");
    462. }
    463. }
    464. }
    465. return "";
    466. }
    467. // --------------------------------------- 华丽分割线 ------------------------------
    468. }

    登录管理控制层: 

    1. @Controller
    2. @RequestMapping("/login")
    3. public class LoginController extends BaseController{
    4. @Autowired
    5. private ManageService manageService;
    6. @Autowired
    7. private TeacherService teacherService;
    8. /**
    9. * 跳转登陆
    10. * @return
    11. */
    12. @RequestMapping("/login")
    13. public String login(){
    14. return "login/mLogin";
    15. }
    16. @RequestMapping("/mtuichu")
    17. public String mtuichu(HttpServletRequest request){
    18. //request.getSession().invalidate();
    19. return "login/mLogin";
    20. }
    21. @RequestMapping("/welcome")
    22. private String welcome(){
    23. return "login/welcome";
    24. }
    25. @RequestMapping("/toLogin")
    26. public String toLogin(Manage manage, Integer type,HttpServletRequest request, HttpServletResponse response){
    27. if (type == null){
    28. return "redirect:/login/mtuichu";
    29. }
    30. if (type == 1){
    31. Manage byEntity = manageService.getByEntity(manage);
    32. if(byEntity == null){
    33. return "redirect:/login/mtuichu";
    34. }else{
    35. request.getSession().setAttribute("role", 1);
    36. request.getSession().setAttribute("username", byEntity.getUserName());
    37. request.getSession().setAttribute("userId", byEntity.getId());
    38. }
    39. }
    40. if (type == 2){
    41. Teacher t = new Teacher();
    42. t.setPassword(manage.getPassWord());
    43. t.setUsername(manage.getUserName());
    44. t.setIsDelete(0);
    45. Teacher byEntity = teacherService.getByEntity(t);
    46. if(byEntity == null){
    47. return "redirect:/login/mtuichu";
    48. }else{
    49. request.getSession().setAttribute("role", 2);
    50. request.getSession().setAttribute("username", byEntity.getUsername());
    51. request.getSession().setAttribute("userId", byEntity.getId());
    52. }
    53. }
    54. return "login/mIndex";
    55. }
    56. /**
    57. * 退出
    58. * @param request
    59. * @param response
    60. * @return
    61. */
    62. @RequestMapping("/tuichu")
    63. public String tuichu( HttpServletRequest request, HttpServletResponse response){
    64. HttpSession session = request.getSession();
    65. session.invalidate();
    66. return "login/login";
    67. }
    68. @RequestMapping("/head")
    69. private String head(){
    70. return "inc/head";
    71. }
    72. @RequestMapping("/left")
    73. private String left(){
    74. return "inc/left";
    75. }
    76. @RequestMapping(value = "/update")
    77. public String update(Integer id,Model model,HttpServletRequest request) {
    78. Object attribute = request.getSession().getAttribute("userId");
    79. if (attribute == null){
    80. return "redirect:/login/mtuichu";
    81. }
    82. Integer userId = Integer.valueOf(attribute.toString());
    83. Teacher byId = teacherService.getById(userId);
    84. model.addAttribute("obj",byId);
    85. return "login/update";
    86. }
    87. @RequestMapping(value = "/toUpdate")
    88. public String toUpdate(Integer id,String phone,Model model,HttpServletRequest request) {
    89. Object attribute = request.getSession().getAttribute("userId");
    90. if (attribute == null){
    91. return "redirect:/login/mtuichu";
    92. }
    93. Integer userId = Integer.valueOf(attribute.toString());
    94. Teacher byId = teacherService.getById(userId);
    95. byId.setPhone(phone);
    96. teacherService.updateById(byId);
    97. model.addAttribute("obj",byId);
    98. return "login/update";
    99. }
    100. @RequestMapping(value = "/pass")
    101. public String pass(Integer id,Model model,HttpServletRequest request) {
    102. Object attribute = request.getSession().getAttribute("userId");
    103. if (attribute == null){
    104. return "redirect:/login/mtuichu";
    105. }
    106. Integer userId = Integer.valueOf(attribute.toString());
    107. Teacher byId = teacherService.getById(userId);
    108. model.addAttribute("obj",byId);
    109. return "login/pass";
    110. }
    111. @RequestMapping("/upass")
    112. @ResponseBody
    113. public String upass(HttpServletRequest request,String password){
    114. Object attribute = request.getSession().getAttribute("userId");
    115. JSONObject j = new JSONObject();
    116. if (attribute == null){
    117. j.put("res", 0);
    118. return j.toString();
    119. }
    120. Integer userId = Integer.valueOf(attribute.toString());
    121. Teacher byId = teacherService.getById(userId);
    122. byId.setPassword(password);
    123. teacherService.updateById(byId);
    124. j.put("res", 1);
    125. return j.toString();
    126. }
    127. }

    源码获取:俺的博客首页 "资源" 里下载!

  • 相关阅读:
    入门必读:Python try except异常处理详解
    java版工程管理系统Spring Cloud+Spring Boot+Mybatis实现工程管理系统源码
    Redis的哨兵机制,一文全解
    C++异常处理
    idea 出现 “Can‘t use Subversion command line client: svn” 错误的解决方法
    vue的两种服务器端渲染方案
    Kutools for Excel v26.10 Excel插件工具箱中文版
    【基于Thread多线程+随机数(Random)+java版本JDBC手动提交事务+EasyExcel读取excel文件,向数据库生成百万级别模拟数据】
    kafka基础(2):kafka quickstart
    抖音web版地址个人主页和视频地址
  • 原文地址:https://blog.csdn.net/m0_66863468/article/details/125406775