logincontroller
package com.zz.xd.controller;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import com.zz.xd.model.User1;
import com.zz.xd.service.User1Service;
@RestController
public class RegisterController {
@Resource
User1Service us = new User1Service();
@RequestMapping("successRegister")
public ModelAndView r1(User1 user) {
String name = user.getName();
List<User1> ls = us.selectByName(name);
if (ls.isEmpty()) {
us.save(user);
}
return new ModelAndView("register.html");
}
@RequestMapping("pwdexamine")
public String r2(@RequestParam("pwd") String pwd, @RequestParam("pwd1") String pwd1) {
String rs = "ok";
if (!pwd.equals(pwd1)) {
rs = "两次输入有误,请修改!";
}
return rs;
}
@RequestMapping("nameexamine")
public String r3(@RequestParam("name") String name) {
String rs = "恭喜!用户名可以使用!";
if(name.length()>15){
rs="用户名过长,请修改!";
}
for(User1 u:us.selectByName(name)){
if(u.getName().equals(name)){
rs = "用户名已被使用,请修改!";
}
}
return rs;
}
}
RegisterController
package com.zz.xd.controller;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import com.zz.xd.model.User1;
import com.zz.xd.service.User1Service;
@RestController
public class RegisterController {
@Resource
User1Service us = new User1Service();
@RequestMapping("successRegister")
public ModelAndView r1(User1 user) {
String name = user.getName();
List<User1> ls = us.selectByName(name);
if (ls.isEmpty()) {
us.save(user);
}
return new ModelAndView("register.html");
}
@RequestMapping("pwdexamine")
public String r2(@RequestParam("pwd") String pwd, @RequestParam("pwd1") String pwd1) {
String rs = "ok";
if (!pwd.equals(pwd1)) {
rs = "两次输入有误,请修改!";
}
return rs;
}
@RequestMapping("nameexamine")
public String r3(@RequestParam("name") String name) {
String rs = "恭喜!用户名可以使用!";
if(name.length()>15){
rs="用户名过长,请修改!";
}
for(User1 u:us.selectByName(name)){
if(u.getName().equals(name)){
rs = "用户名已被使用,请修改!";
}
}
return rs;
}
}