[知了堂学习笔记] SSM框架项目中遇到的问题及解决办法_01

时间:2022-01-26 13:41:49

多参数传递问题

  • 功能描述:需要得到页面的参数传入数据库,进行多条件查找

    [知了堂学习笔记] SSM框架项目中遇到的问题及解决办法_01

  • 解决办法:在dao层对应的接口方法的参数前加上@Param(“XXX”)
    [知了堂学习笔记] SSM框架项目中遇到的问题及解决办法_01


前台界面传参至后台的问题

  • 报错:At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
  • 解决办法:
    前台jsp页面代码:sid_message.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta>
        <title></title>
        <link type="text/css" href="../bootstrap/css/bootstrap.min.css" rel="stylesheet">
        <link type="text/css" href="../css/theme.css" rel="stylesheet"/>
        <script type="text/javascript" src="../scripts/jquery-3.2.1.js"></script>
        <style type="text/css"> .title{ font-family: "微软雅黑"; font-size: larger; } </style>
    </head>
    <body>
        <div style="height: 30px;">
            <span class="title" style="margin-left: 10%;">用户信息</span>
            <span class="title" style="margin-left: 35%;">密码重置</span>
        </div>
         <div>
            <pre style="overflow-y: auto;height: 640px;">
            <table style="margin-top: 0px;padding: 0px;margin-top: 0px;padding-top:0px ;" cellpadding="0" cellspacing="0" border="0" class="datatable-1 table table-bordered table-striped display">                                                 
                                           <tbody id="sid_menu">
                                           <c:forEach items="${userMessageList }" var="map">
                                            <tr class="odd gradeA">
                                                <td style="margin-left: 2%;">${map.username }</td>
                                                <td style="margin-left: 2%;">${map.dept_name }</td>
                                                <td style="margin-left: 2%;">${map.role_name }</td>
                                                <td style="margin-left: 2%;"><input type="password" placeholder="请输入密码" class="sid_changepwd"/></td>
                                                <td style="margin-left: 2%;"><input type="password" placeholder="请再次输入密码" class="sid_rechangepwd" ononblur="repwdBlur()"/></td>
                                                <td style="margin-left: 2%;"><button class="btn btn-large btn-danger" onclick="updatePassword(this,${map.user_id })">确认</button></td>
                                                <td style="margin-left: 2%;"><input type="reset" class="btn btn-large btn-danger" style="background-color:black;border-color:black" value="取消"></td>
                                            </tr>
                                            </c:forEach>
                                            </tbody>
                                    </table>
                                   </pre>
                               </div>                        
        <div style="margin-top: 2%;">
            <span style="margin-left: 8%;"><input type="text" placeholder="按用户名选择查找" id="sid_choose_user"/></span>
            <span style="margin-left: 8%;"><input type="text" placeholder="按用户部门选择查找" id="sid_choose_dept"/></span>
            <span style="margin-left: 8%;"><input type="text" placeholder="按用户职位选择查找" id="sid_choose_role"/></span>
            <span style="margin-left: 2%;"><button class="btn btn-small" style="margin-top: -8px;background-color: #333333;color: white;" id="sid_choose">确定</button></span>
        </div>
    </body>
    <script type="text/javascript"> $(function(){ //多条件查询的点击事件 $("#sid_choose").click(function(){ var userChooseJson = { "username": $("#sid_choose_user").val(),//填写的用户名 "deptname":$("#sid_choose_dept").val(),//填写的部门名称 "rolename":$("#sid_choose_role").val()//填写的角色名称 };//json对象 $.ajax({ type:'POST', dataType:'json', url:'../user/userMessageChoose.do', contentType:'application/json;charset=UTF-8',//定义格式和编码 data:JSON.stringify(userChooseJson),//把json对象转为字符串传递给后台 success:function(data){ if(data == null || data == ""){ alert("无该信息!请重新输入关键字!"); }else{ var str = ""; $("#sid_menu").children().remove(); $.each(data,function(key,val){ str += '<tr class="odd gradeA">' +'<td style="margin-left: 2%;">'+val.username+'</td>' +'<td style="margin-left: 2%;">'+val.dept_name+'</td>' +'<td style="margin-left: 2%;">'+val.role_name+'</td>' +'<td style="margin-left: 2%;"><input type="password" placeholder="请输入密码" class="sid_changepwd"/></td>' +'<td style="margin-left: 2%;"><input type="password" placeholder="请再次输入密码" class="sid_rechangepwd"/></td>' +'<td style="margin-left: 2%;"><button class="btn btn-large btn-danger" onclick="updatePassword(this,${map.user_id })">确认</button></td>' +'<td style="margin-left: 2%;"><input type="reset" class="btn btn-large btn-danger" style="background-color:black;border-color:black" value="取消"></td>' +'</tr>'; }); $("#sid_menu").append(str); $('input:reset').click(function(){ $('.sid_changepwd').val(""); $('.sid_rechangepwd').val(""); }); } }, error:function(){ alert("无该数据!"); } }); }); }); //修改密码的点击事件 function updatePassword(thisObj,user_id){ var password = $(thisObj).closest("tr").find(".sid_changepwd").val();//得到当前密码输入框的值 var repassword = $(thisObj).closest("tr").find(".sid_rechangepwd").val();//得到当前重复密码输入框的值 if(password == repassword){ //alert("相同"); $(function(){ var passwordJson = { "user_id":user_id, "password":password };//将用户id和密码分装为json对象 $.ajax({ type:'POST', dataType:'json', url:'../user/editUserMessage.do', contentType:'application/json;charset=UTF-8',//定义格式和编码 data:JSON.stringify(passwordJson),//把json对象转为字符串传递给后台 success:function(data){//回调函数 if(data == 1){ alert("修改成功!"); }else{ alert("修改失败!"); } }, error:function(){ alert("失败"); } }); }); }else{ alert("两次密码不相同!请重新输入密码!"); } //alert(password); //alert(repassword); } //取消修改的点击事件 //存在一个bug 点击任意一个取消按钮,所有input中的内容都会被清空 $(function(){ $('input:reset').click(function(){ $('.sid_changepwd').val("");//将密码输入框的值清空 $('.sid_rechangepwd').val("");//将驸马重复输入框中的值清空 }); }); </script>
</html>

后台控制层:UserController.java

package com.bbd.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.bbd.model.UserModel;
import com.bbd.po.UserChooseJson;
import com.bbd.service.UserService;

/** * SID界面--权限管理--信息修改--控制层 * @author Administrator * */
@Controller
@RequestMapping("user")//给一个地址,用于访问
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping("userMessageList")
    public ModelAndView getUserMessage() {
        List<Map<String, Object>> userMessageList = userService.getUserMessage();
        ModelAndView mav = new ModelAndView("sid/sid_message","userMessageList",userMessageList);
        return mav;

    }

    /** * 通过@RequestBody接收参数 * @return */

    @RequestMapping(value = "/userMessageChoose" , method = RequestMethod.POST)
    public @ResponseBody List<Map<String, Object>> getUserMessageChoose(@RequestBody UserChooseJson userChooseJson) {

        String username = userChooseJson.getUsername();
        String deptname = userChooseJson.getDeptname();
        String rolename = userChooseJson.getRolename();
        //测试前台是否传回参数
        //System.out.println(username+" "+deptname+" "+rolename);

        List<Map<String, Object>> userMessageChoose = userService.getUserMessageChoose(username, deptname, rolename);
        //测试返回的值
        /*for(Map<String, Object> m: userMessageChoose) { for(String k:m.keySet()) { System.out.println(k+" : "+m.get(k)); } }*/
        return userMessageChoose;

    }
    /** * 根据用户id修改用户密码 * @return */
    @RequestMapping(value = "/editUserMessage" , method = RequestMethod.POST)
    public @ResponseBody Integer editUserMessage(@RequestBody UserModel userModel) {

/* UserModel userModel1 = new UserModel(14001,"123456789"); System.out.println(userModel1.getUser_id()+" "+userModel1.getPassword());*/
        Integer editState = userService.editUserMessage(userModel);
        //System.out.println(editState);
        return editState;
    }


     // 用于测试
/* @RequestMapping("editUserMessage") public String test() { String username = ""; String deptname = ""; String rolename = "SID"; //System.out.println(username); List<Map<String, Object>> userMessageChoose = userService.getUserMessageChoose(username, deptname, rolename); for(Map<String, Object> m: userMessageChoose) { for(String k:m.keySet()) { System.out.println(k+" : "+m.get(k)); } } UserModel userModel1 = new UserModel(14001,"123456789"); System.out.println(userModel1.getUser_id()+" "+userModel1.getPassword()); Integer editState = userService.editUserMessage(userModel1); System.out.println(userService); System.out.println(editState); return "成功"; }*/
}

eclipse启动报错问题

-报错内容:

An internal error occurred during: “Initializing Java Tooling”.

解决办法:
1.删除当前工作目录下的WORKSPACE_HOME/.metadata/.plugins/org.eclipse.core.resources/.project,然后重新启动Eclipse
2. 由于我的项目使用了SVN管理,所以将要删除的项目下的.indexes和.syncinfo文件拷贝出来,重启后再将这两个文件拷贝回来,或者先close相应项目,再操作步骤1.