1、在UserSqlMap.xml中键入关键代码
<select id="" 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>
从数据库中检索用户名和密码的一条记录
<select id=""parameterClass="cn.training.bean.UserBean"
resultClass="cn.training.bean.UserBean">
SELECT userid as userId, username as userName,
password as passWord FROM user
</select>
从前台显示所有数据库中的信息
2、在UserBean.java中键入关键代码
public class UserBean {
private String userId;
public String getUserId() {
return userId; }
public void setUserId(String userId) {
this.userId = userId; }
private String userName;
public String getUserName() {
return userName; }
public void setUserName(String userName) {
this.userName = userName; }
private String passWord;
public String getPassWord() {
return passWord; }
public void setPassWord(String passWord) {
this.passWord = passWord; }}
3、在hellowordservice.java中键入关键代码
public class HelloWorldService {
@Autowired QueryDAO queryDao;
@Autowired UpdateDAO updateDao;
public UserBean (UserBean result) {
result = ("User.", result,UserBean.class);
return result;}
public (UserBean frm)
{List<UserBean> result = queryDao.executeForObjectList(" null);return result; }
4、在hellowordController.java中键入关键代码
@RequestMapping(value = ", method = RequestMethod.POST,
public String initLogin(UserBean userBean, Model model)
{ result = helloWorldService.searchUser();
model.addAttribute("userBean", result);
if(){
List<UserBean> = helloWorldService.(userBean);
model.addAttribute("", );return "login";
}
else{ model.addAttribute("message", "用户名或密码错误");
return "helloWorld";}}
@RequestMapping(value = "/", method = RequestMethod.POST,params="zc")
public String initregister(UserBean userBean, Model model)
{UserBean result = helloWorldService.searchUser(userBean);
model.addAttribute("userBean", result);
return "register";}
5、在login
用户列表
<div th:each="userInfo,status:${list}">
<table>
<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>
6、在helloword
<div><span th:text="${message}"></span></div>
<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>
7、register
<form action="helloWorld" th:object="${UserBean}" method="post">
<table>
<tr><td><caption>注册界面</caption></td></tr>
<tr><td>ID:<input name="UserId" type="text"/></td></tr>
<tr><td>用户名:<input name="UserId" type="text"/></td></tr>
<tr><td>密码:<input name="password" type="text"/></td></tr>
<tr><td>确认密码:<input name="qrpassword" type="text"/></td></tr>
<tr><td> <button type="sumbit" name="login">登录</button>
<button type="sumbit" name="return">返回首页</button></td></tr>
</table></form>