1.编写实体类
略
2. 写mapper映射文件
通过名字查询 通过ID主键查询… 略
写dao
CRUD相关抽象方法
List
Student getOneBySid(int sid);
int deleteOne(int sid);
int deleteSome(int[] sidArrInt);
int addOne(Student student);
int updateOne(Student student);
写业务层service(和dao差不多)
Teacher Login(String tname,String tpwd);
写实现类
public Teacher Login(String tname,String tpwd) {
//通过byname方法获取一个老师对象 然后通过数据库数据对比 账号密码是否一致
Teacher teacher = teacherDao.getOneByTname(tname);
if (teacher==null){
//自定义异常
throw new TeacherLoginException("账号不存在");
}
if (!teacher.getTpwd().equals(tpwd)){
throw new TeacherLoginException("密码错误");
}
return teacher;
}
填写action层
restful风格的CRUD
@Autowired
private TeacherService service;
@RequestMapping(value = "/teacher/getYzmImg.action",method = RequestMethod.GET)
public void getYzmImgMethod(HttpServletRequest req, HttpServletResponse resp){
try {
CheckImage.getYzm(resp,req);
} catch (Exception e) {
throw new TeacherLoginException("图片验证码错误");
}
}
@RequestMapping(value = "/teacher/login.action",method = RequestMethod.GET)
public ResponseVo
String yzmSession = (String) req.getSession().getAttribute("yzmSession");
if (!tyzm.equals(yzmSession)){
throw new TeacherLoginException("验证码错误!");
}
Teacher teacher = service.Login(tname, tpwd);
req.getSession().setAttribute("teacher",teacher);
return new ResponseVo<>(200, "登陆成功", teacher);
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章