单条记录

在login.html界面

<div th:each="userInfo,status:${userBean}">单条记录传递    ${list}列表记录传递

<table>

<tr><td>用户列表</td></tr>

<tr>

<td><a th:href="@{delete?(userId=${userInfo.userId})}"><span th:text="${userInfo.userId}"></span></a></td>

<td><span th:text="${userInfo.userName}"></span></td>

</tr>

</table>

</div>

2、在helloword.html界面

<form action="init" th:object="${UserBean}" method="post">

<table><tr><td>登录界面</td></tr>

   <tr>

     <td>用户名:<input name="UserId" type="text"/></td>

    </tr>

      <tr>

       <td>密码:<input name="passWord" type="password"/></td>

       </tr>

   </table>

 <button type="submit" name="dl">登 陆</button>

 <button type="submit" name="zc">注 册</button>

</form>

3、init的调用方法在hellowordcontroller中写

 @RequestMapping(value = "/init", method = RequestMethod.POST,params="dl")

    public String initLogin(UserBean userBean, Model model) {


    UserBean result = helloWorldService.searchUser(userBean); 

      单条记录利用userbean,列表利用list

 model.addAttribute("userBean", result);

      return "login"; }

  @RequestMapping(value = "/init", method = RequestMethod.POST,params="zc")

    public String initregister(UserBean userBean, Model model) {

    UserBean  result1 = helloWorldService.searchUser(userBean);

    model.addAttribute("userBean", result1);

        return "register";

   4、在Helloworldservice中键入关键代码

public UserBean searchUser(UserBean result) {

result = queryDao.executeForObject("User.selectUser", result,UserBean.class);

      return result;

}

5、在sqlmap中

<sqlMap namespace="User">

<select id="selectUser"

parameterClass="cn.training.bean.UserBean"

resultClass="cn.training.bean.UserBean">

SELECT

userid as userId,

username as userName,

password as passWord

FROM

user

   where userid=#userId# and password=#passWord#

 

</select>





你可能感兴趣的:(单条记录)