In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "analyzing the project ideas of CRM in Java". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "analyzing the project ideas of CRM in Java".
First, the analysis of the whole process of login module
Login module:
1. Check the user name and password, and store them in cookie to facilitate login-free operation in the later stage.
2. Modify the basic information of the user, obtain the data modified by the form user, make the Ajax request, and modify the database information of the id corresponding to the user after the modification.
3. Change the password, get the form data entered by the user, check the service layer, judge the original password, confirm the new password, and finally modify the user password of the database.
4. Each time you modify the information, you will automatically clear the data in the cookie and log in again.
5. The service layer will call many tool classes to provide clean business processing.
⭐ core code
Controller layer UserController.java
@ Controller@RequestMapping ("user") public class UserController extends BaseController {@ Autowired UserService userService; / / change password page Jump @ RequestMapping ("toPasswordPage") public String updatePwd () {return "user/password";} / / Log in @ RequestMapping ("login") @ ResponseBody public ResultInfo login (User user) {ResultInfo result=new ResultInfo () Try {/ / catch exception UserModel userModel=userService.userLogin (user.getUserName (), user.getUserPwd ()); / / login succeeded result.setCode (200); result.setMsg ("login successful ~"); result.setResult (userModel);} catch (ParamsException ex) {ex.printStackTrace () Result.setCode (ex.getCode ()); result.setMsg (ex.getMsg ());} catch (Exception e) {e.printStackTrace (); result.setCode (500); result.setMsg ("Operation failed ~");} return result } / * modify password * / @ PostMapping ("updatePwd") @ ResponseBody public ResultInfo updatePwd (HttpServletRequest req,String oldPwd,String newPwd,String againPwd) {ResultInfo result=new ResultInfo (); / / get cookie to get user ID int userId=LoginUserUtil.releaseUserIdFromCookie (req); userService.updatePwd (userId,oldPwd,newPwd,againPwd); return result;}}
Service layer UserService.java
@ Servicepublic class UserService extends BaseService {@ Resource UserMapper userMapper; / * user login * / public UserModel userLogin (String userName,String userPwd) {/ / determine whether the user name and password are empty checkNull (userName,userPwd); / / check whether User user=userMapper.selectByuserName (userName) already exists; AssertUtil.isTrue (user==null, "user name does not exist!") ; / / check the password checkPwd (userPwd,user.getUserPwd ()); return buildInfo (user);} / / set the return message private UserModel buildInfo (User user) {UserModel um=new UserModel (); um.setUserName (user.getUserName ()); um.setUserId (UserIDBase64.encoderUserID (user.getId (); / / A pair of ID encrypted um.setTrueName (user.getTrueName ()) Return um;} / / password verification private void checkPwd (String userPwd, String userPwd1) {String enPwd=Md5Util.encode (userPwd); AssertUtil.isTrue (! enPwd.equals (userPwd1), "password is incorrect!") ;} / / determine whether the private void checkNull (String userName,String userPwd) {/ / determine whether the user name and password are empty AssertUtil.isTrue (StringUtils.isBlank (userName), "user name cannot be empty!") ; AssertUtil.isTrue (StringUtils.isBlank (userPwd), "user password cannot be empty!") ;} / * change password * / public void updatePwd (int userId,String oldPwd,String newPwd,String againPwd) {/ / obtain user System.out.println (userId) through id; User user=userMapper.selectByPrimaryKey (userId); System.out.println (user); / / verify and modify password isOkForPwd (user,oldPwd,newPwd,againPwd) / / change password user.setUserPwd (Md5Util.encode (newPwd)); / / modify database content AssertUtil.isTrue (userMapper.updateByPrimaryKeySelective (user) open) to open a page with a specified size
The addorupdata (Integer id,Model model) method under jump controller is used to determine
If there is no id, then the static resource page addorupdata.ftl page will be forwarded directly. At this point, the small page of open will
There is an empty form page.
2.2.Click modify: call the addorupdata (id) method on js-> open to open a page with a specified size
Forward to controller layer addorupdata (Integer id,Model model) method with id
Whether id has a value, the User object stored in the corresponding id is stored in model and forwarded to the addorupdata.ftl page.
Face, at this point the small page of open is a form with content.
Click delete: the js file will directly call deletesale (data) to obtain the id of the object to be deleted.
Multiple this returns to splice an ids=1&ids=2&ids=3 to send an Ajax request to the controller layer to call delete (Integer [] ids)
Methods to deal with it.
3. Secondly, after determining what operation, the corresponding window addorupdata.ftl will pop up, and at this time, the corresponding js will listen to whether to submit or not.
Click submit to determine whether the form submission data contains an id value, and send an Ajax request to the controller layer
Call the updata (User user) method to modify it.
3.2.Click submit. If id has no value, send an Ajax request to the controller layer and call the add (User user) method to add it.
4. Delete here and write a batch deletion directly, open a small window out of order, directly Ajax the request, and call the delete method of the controller layer to deal with it.
The logic of the rest of the module is the same as that of the marketing module. Do not do more overview. The source code will directly look at the uploaded resources.
⭐ core code
SaleChanceController.java
@ Controller@RequestMapping ("sale_chance") public class SaleChanceController extends BaseController {@ Autowired private SaleChanceService saleChanceService; @ Autowired private UserService userService; / / Marketing opportunity Page Jump @ RequestMapping ("index") public String toSale () {return "/ saleChance/sale_chance" } / / add and modify page @ RequestMapping ("addOrUpdateDialog") public String addorUpdata (Integer id, Model model) {/ / if id has a value if (idled null) {/ / get the object SaleChance saleChance=saleChanceService.selectByPrimaryKey (id) through ID; model.addAttribute ("saleChance", saleChance);} return "saleChance/add_update" } @ RequestMapping ("list") @ ResponseBody public Map manyPage (SaleChanceQuery query) {return saleChanceService.manyPage (query);} / * add opportunities * / @ RequestMapping ("save") @ ResponseBody public ResultInfo save (HttpServletRequest req, SaleChance saleChance) {/ / get id int id= LoginUserUtil.releaseUserIdFromCookie (req) in cookie; / / String createName=userService.selectByPrimaryKey (id). GetTrueName () / / set creator saleChance.setCreateMan (createName); / / add saleChanceService.addSaleChance (saleChance); return success ("added successfully");} / * modify marketing opportunity * / @ RequestMapping ("updata") @ ResponseBody public ResultInfo updata (SaleChance saleChance) {saleChanceService.updataSale (saleChance); return success ("modified successfully") } / * batch deletion * / @ RequestMapping ("dels") @ ResponseBody public ResultInfo delete (Integer [] ids) {System.out.println (Arrays.toString (ids)); saleChanceService.deleteall (ids); return success ("deleted successfully ~");}}
SaleChanceService.java
@ Servicepublic class SaleChanceService extends BaseService {@ Resource private SaleChanceMapper saleChanceMapper; / * / paged display * / public Map manyPage (SaleChanceQuery query) {Map map = new HashMap (); / / set paging PageHelper.startPage (query.getPage (), query.getLimit ()); / / a pair of data is paged PageInfo pageInfo = new PageInfo (saleChanceMapper.selectByParams (query)); map.put ("code", 0) Map.put ("msg", "success"); map.put ("count", pageInfo.getTotal ()); map.put ("data", pageInfo.getList ()); return map } / * / / add opportunity * / @ Transactional (propagation = Propagation.REQUIRED) public void addSaleChance (SaleChance saleChance) {/ / determine customer name, opportunity source, contact, contact number, checkInfo (saleChance.getCustomerName (), saleChance.getChanceSource (), saleChance.getLinkMan (), saleChance.getLinkPhone ()) / / whether the state status is assigned 0 unassigned 1 has been assigned if (StringUtils.isBlank (saleChance.getAssignMan () {saleChance.setDevResult (0); saleChance.setState (0);} if (StringUtils.isNotBlank (saleChance.getAssignMan () {saleChance.setDevResult (1); saleChance.setState (1); saleChance.setAssignTime (new Date ()) } / / set the default value saleChance.setCreateDate (new Date ()); saleChance.setUpdateDate (new Date ()); saleChance.setIsValid (1); / / determine whether the insertion is successful AssertUtil.isTrue (insertSelective (saleChance))
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.