bean类的无效属性“loginformdata”< >bean属性“loginformdata”不可读或具有无效的getter方法

tvokkenx  于 2021-07-07  发布在  Java
关注(0)|答案(0)|浏览(300)

我尝试使用片段作为我的登录表单,它可以选择在点击按钮时打开。这是为了避免所有页面中的代码重复。但是我在使用th:字段时得到以下错误

Invalid property 'loginFormData' of bean class [io.community.translation.munselvom.auth.LoginFormData]: Bean property 'loginFormData' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

我的主要 HTML page ```

        <nav>
            <ul>
            <li id="login-form">
            <a href="#" id="logged-user-icon" th:text="${userdesc}"> </a>
            <a href="#" id="login-icon" class="fas fa-lock"> Login</a>

                <div id="login-content">
                <form id="loginid" th:action="${action}" method="post" th:object="${__${formdata}__}" role="form"> 
                <fieldset id="inputs">
                        <input id="username" th:field="*{__${formdata}__.username}" type="text" name="username" required placeholder="User Id">
                        <input id="password" th:field="*{userpass}" type="password"  name="password" placeholder="Password" required>
                </fieldset>
                <div id="auth-error">
                <a th:text="${loginerrormess}">
                    Invalid User-id/Password!
                </a>
                </div>
                <fieldset id="actions">
                    <input type="submit" id="submit" value="Login"> 
                </fieldset>
                </form> 
                </div>          
                <div id="logout-content">
                    <div id="logout-user-det">
                        <a id="logout-user-disp" th:text="${userdesc}"></a>
                        <a id="logout-user-mail" th:text="${useremail}"></a>
                    </div>
                    <div id="logout-link">
                        <a  href="/logoutuser" >Sign out</a>
                    </div>
               </div>
        </nav>
    </div>
</div>
这是我的 `controller` ```
@GetMapping("/")

   public String home(Model model) {

        userService.updateSession();
        UserList userList = userService.getAuthStatus();

        model.addAttribute("loginFormData", new LoginFormData());

        if (!Objects.isNull(userList)) {
            model.addAttribute("userdesc", userList.getUserdesc());
            model.addAttribute("useremail", userList.getEmailid());
        }
        else {
            model.addAttribute("userdesc", "");
            model.addAttribute("useremail", "");
        }

        model.addAttribute("loginerrormess", "Success");

        return "homepage/index";
    }

    @RequestMapping(value = "/", method = RequestMethod.POST)
    public String loginUser(@ModelAttribute("loginFormData") LoginFormData loginForm, //
            Model model) throws Exception
 {
            System.out.println("User Id "+loginForm.getUsername());

            String login_mess = userService.userLogin(loginForm.getUsername(),loginForm.getUserpass());

            System.out.println("login Status "+ login_mess+" End of message");

            //return login_mess;

            if (login_mess != "Success") {
                model.addAttribute("loginerrormess", login_mess);
                model.addAttribute("userdesc", "");
                model.addAttribute("useremail","");

                //throw new Exception("Authentication Failed");
            } else {

                model.addAttribute("loginerrormess", "Success");
                model.addAttribute("userdesc", userService.getUserByName(loginForm.getUsername()).getUserdesc() );
                model.addAttribute("useremail", userService.getUserByName(loginForm.getUsername()).getEmailid() );
            }
            //return "redirect:/";

            return "homepage/index";
    }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题