I. mybatis generator GUI
Download address: https://github.com/LittlePageProgram/mybatis-generator-gui.git
Usage: fill in related items and click generate
Note:
1. For EntityExample, you need to drag it into the mapper layer
2. For modifying XML configuration information, the corresponding example also needs to be adjusted to the mapper layer.
Case study:
service level
package com.littlepage.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.littlepage.entity.User; import com.littlepage.mapper.UserExample; import com.littlepage.mapper.UserMapper; @Service public class UserService { @Autowired UserMapper userMapper; public List<User> selectAll() { UserExample example=new UserExample(); example.createCriteria(); return userMapper.selectByExample(example); } public void add() { UserExample example=new UserExample(); userMapper.deleteByExample(example); } public boolean selectByLoginNameAndPassword(String name,String password) { UserExample example=new UserExample(); System.out.println(name); System.out.println(password); example.createCriteria().andNameEqualTo(name).andPasswordEqualTo(password); List<User> li=userMapper.selectByExample(example); System.out.println(li); return li.size()!=0 ; } }
2. PageHelper is a good paging plug-in
public List<User> selectAll(int pageNum,int pageSize) { PageHelper.startPage(pageNum, pageSize); UserExample example=new UserExample(); example.createCriteria(); return userMapper.selectByExample(example); }
Fast value transfer paging, this principle uses AOP programming
III. front and rear end separation
Theory:
The back-end only provides interfaces, and the front-end performs data acquisition and jump.
Advantage:
1. Minimize the pressure on the server
2. Background errors will not be directly reflected to the front desk, and it is friendly to receive the second error.
3. The difficulty of development can be reduced to the greatest extent if the front and rear platforms do their respective duties.
Realization:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> </head> <link rel="stylesheet" href="/css/bootstrap.min.css" /> <script src="/js/jquery.min.js"></script> <script src="/js/bootstrap.min.js"></script> <script> $(function (){ $("#login_btn").click(function (){ var loginName=$('#loginName').val(); var password=$('#password').val(); if(loginName==''||password==''){ $('#tip').html('User name and password cannot be empty'); $('#tip').css('color','red'); return false; }else{ var url='/account/validateAccount'; var args={loginName:loginName,password:password}; $.post(url,args,function(data){ if(data=='success'){ window.location.href='/account/success'; }else{ $('#tip').html('Password error'); $('#tip').css('color','red'); } console.log(data); }) return false; } }) }) </script> <body> <div align="middle"> <br /> <br /> <hr/> <br /> <div align="middle"> <h3>Login interface</h3> </div> <br /> <br /> <form action="/account/validateAccount" method="post"> <input type="text" placeholder="User name" id="loginName" /><br /><br /> <input type="password" placeholder="Password" id="password" /><br /><br /> <div><span id="tip"></span></div><br /> <button id="login_btn" type="submit" >Sign in</button> </form> </div> </body> </html>
HTML page
package com.littlepage.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import com.littlepage.entity.User; import com.littlepage.service.UserService; @Controller @RequestMapping("/account") public class AccountController { @Autowired UserService userService; @RequestMapping("/login") public String loginPage() { return "login"; } @RequestMapping("/validateAccount") @ResponseBody public String list(@RequestParam("loginName")String loginName,@RequestParam("password")String password) { if(userService.selectByLoginNameAndPassword(loginName, password)) { return "success"; }else { return "false"; } } @RequestMapping("/success") public String successPage() { return "account/success"; } @RequestMapping("/list") @ResponseBody public List<User> list() { return userService.selectAll(2, 2); } }
Controller