当前位置:   article > 正文

1.Spring Boot + 物业管理项目-配置+登陆_物业管理项目springboot

物业管理项目springboot

1.Spring Boot 概念      

        自动处理应用程序幕后的各种杂事(Spring框架的应用程序的配置和部署过程),让你专注于做那些使应用程序独特的工作

1.1 Spring Boot的核心功能

1.1.1 自动配置

        Spring Boot根据应用程序的依赖和配置信息,自动进行各种功能的配置,如数据源、缓存、安全等。开发者只需要添加相应的依赖和配置,即可轻松使用这些功能。

1.1.2 起步依赖

        Spring Boot提供了一系列预定义的"起步依赖"(Starter Dependencies),这些依赖项封装了特定功能的依赖和配置,简化了项目的依赖管理。

1.1.3 命令行界面

        Spring Boot提供了一个命令行界面(CLI)工具,用于在命令行中快速创建、运行和管理Spring Boot应用程序。CLI是Spring Boot的非必要组成部分

1.1.4 Actuator

        Spring Boot的Actuator模块提供了对应用程序运行时的监控和管理功能,包括健康检查、性能指标、日志查看等,方便开发者进行运维和监控。

1.1.5 内嵌服务器

        Spring Boot可以将应用程序打包为可执行的JAR文件,并内置了多个常用的服务器(如Tomcat、Jetty等),使得应用程序可以独立运行,不需要外部服务器的支持。

1.2 初始化Spring Boot项目

1.2.1 用IDEA创建Spring Boot项目

        Server URL是Initializr Web服务的位置,默认为spring官网提供的,国内使用可能会慢些,可以使用阿里提供的 http://start.aliyun.com/

         选择next后会让你选择需要添加的项目依赖

2.用Spring Boot创建一个物业管理项目

2.1 项目功能

        登录功能、主页、费用管理、住户管理、商铺管理、车位管理、保修管理、投诉建议

2.2 根据需求创建需要的数据库

2.3 开始搭建项目结构

2.4 登录页面

        index.html是启动页面,作为登录页面,获取用户的数据利用axios向controller发送请求,再根据controller的响应决定是否登录成功,是否跳转页面

2.4.1 导入需要的vue、axios、element-ui组件

  1. <!--
  2. vue:替代JavaScript
  3. axios:发请求的工具,作用与$.ajax一样
  4. elsement-ui:基于vue的组件库
  5. -->
  6. <script src="js/vue/vue.js"></script>
  7. <script src="js/vue/axios.min.js"></script>
  8. <link rel="stylesheet" href="css/vue/element-index.css">
  9. <script src="js/vue/element-index.js"></script>

2.4.2 设计登录前端界面

        使用v-model给输入框双向绑定某个vue中data定义的值,从而能获取到用户输入的信息;给登录等按钮添加点击事件@click并设置对应的触发函数,函数在vue的method中定义

2.4.2.1 html
  1. <body>
  2. <div id="app">
  3. <div class="container" id="container">
  4. <div class="form-container sign-up-container">
  5. <form action="#">
  6. <h1>创建用户</h1>
  7. <input type="text" placeholder="用户名" />
  8. <input type="email" placeholder="手机号" />
  9. <input type="password" placeholder="密码" />
  10. <button>确认注册</button>
  11. </form>
  12. </div>
  13. <div class="form-container sign-in-container">
  14. <form action="#">
  15. <h1>登录</h1>
  16. <el-input v-model="user.cellphone" placeholder="请输入账号" class="elinput"></el-input>
  17. <el-input v-model="user.password" placeholder="请输入密码" class="elinput" show-password></el-input>
  18. <a href="#">忘记密码?</a>
  19. <el-button @click="login()" icon="el-icon-ice-cream-square" class="elbutton" round>登录</el-button>
  20. </form>
  21. </div>
  22. <div class="overlay-container">
  23. <div class="overlay">
  24. <div class="overlay-panel overlay-left">
  25. <h1>欢迎回来!</h1>
  26. <p>只有登录才能访问我们的页面,请输入登录信息</p>
  27. <button class="ghost" id="signIn">登录</button>
  28. </div>
  29. <div class="overlay-panel overlay-right">
  30. <h1>你好啊,朋友!</h1>
  31. <p>输入你的信息,快来加入我们吧</p>
  32. <button class="ghost" id="signUp">注册</button>
  33. </div>
  34. </div>
  35. </div>
  36. </div>
  37. </div>
  38. </body>
2.4.2.2 css

        设置前端元素的样式、动画效果,这里复制的网上的资源做了些点修改

  1. <style>
  2. @import url('https://fonts.googleapis.com/css?family=Montserrat:400,800');
  3. * {
  4. box-sizing: border-box;
  5. }
  6. body {
  7. background: #f6f5f7;
  8. display: flex;
  9. justify-content: center;
  10. align-items: center;
  11. flex-direction: column;
  12. font-family: 'Montserrat', sans-serif;
  13. height: 100vh;
  14. margin: -20px 0 50px;
  15. }
  16. h1 {
  17. font-weight: bold;
  18. margin: 0;
  19. }
  20. h2 {
  21. text-align: center;
  22. }
  23. p {
  24. font-size: 14px;
  25. font-weight: 100;
  26. line-height: 20px;
  27. letter-spacing: 0.5px;
  28. margin: 20px 0 30px;
  29. }
  30. span {
  31. font-size: 12px;
  32. }
  33. a {
  34. color: #333;
  35. font-size: 14px;
  36. text-decoration: none;
  37. margin: 15px 0;
  38. }
  39. button {
  40. border-radius: 20px;
  41. border: 1px solid #FF4B2B;
  42. background-color: #FF4B2B;
  43. color: #FFFFFF;
  44. font-size: 12px;
  45. font-weight: bold;
  46. padding: 12px 45px;
  47. letter-spacing: 1px;
  48. text-transform: uppercase;
  49. transition: transform 80ms ease-in;
  50. }
  51. .elbutton {
  52. border-radius: 20px;
  53. border: 1px solid #FF4B2B;
  54. background: linear-gradient(to right, #fd545c,#FF65A7);
  55. color: #FFFFFF;
  56. font-size: 12px;
  57. font-weight: bold;
  58. padding: 12px 45px;
  59. letter-spacing: 1px;
  60. text-transform: uppercase;
  61. transition: transform 80ms ease-in;
  62. }
  63. button:active {
  64. transform: scale(0.95);
  65. }
  66. button:focus {
  67. outline: none;
  68. }
  69. button.ghost {
  70. background-color: transparent;
  71. border-color: #FFFFFF;
  72. }
  73. form {
  74. background-color: #FFFFFF;
  75. display: flex;
  76. align-items: center;
  77. justify-content: center;
  78. flex-direction: column;
  79. padding: 0 50px;
  80. height: 100%;
  81. text-align: center;
  82. }
  83. input {
  84. background-color: #eee;
  85. border: none;
  86. padding: 12px 15px;
  87. margin: 8px 0;
  88. width: 100%;
  89. }
  90. .container {
  91. background-color: #fff;
  92. border-radius: 10px;
  93. box-shadow: 0 14px 28px rgba(0,0,0,0.25),
  94. 0 10px 10px rgba(0,0,0,0.22);
  95. position: relative;
  96. overflow: hidden;
  97. width: 768px;
  98. max-width: 100%;
  99. min-height: 480px;
  100. }
  101. .form-container {
  102. position: absolute;
  103. top: 0;
  104. height: 100%;
  105. transition: all 0.6s ease-in-out;
  106. }
  107. .sign-in-container {
  108. left: 0;
  109. width: 50%;
  110. z-index: 2;
  111. }
  112. .container.right-panel-active .sign-in-container {
  113. transform: translateX(100%);
  114. }
  115. .sign-up-container {
  116. left: 0;
  117. width: 50%;
  118. opacity: 0;
  119. z-index: 1;
  120. }
  121. .container.right-panel-active .sign-up-container {
  122. transform: translateX(100%);
  123. opacity: 1;
  124. z-index: 5;
  125. animation: show 0.6s;
  126. }
  127. @keyframes show {
  128. 0%, 49.99% {
  129. opacity: 0;
  130. z-index: 1;
  131. }
  132. 50%, 100% {
  133. opacity: 1;
  134. z-index: 5;
  135. }
  136. }
  137. .overlay-container {
  138. position: absolute;
  139. top: 0;
  140. left: 50%;
  141. width: 50%;
  142. height: 100%;
  143. overflow: hidden;
  144. transition: transform 0.6s ease-in-out;
  145. z-index: 100;
  146. }
  147. .container.right-panel-active .overlay-container{
  148. transform: translateX(-100%);
  149. }
  150. .overlay {
  151. background: #FF416C;
  152. background: -webkit-linear-gradient(to right, #FF4B2B, #FF416C);
  153. background: linear-gradient(to right, #FF4B2B, #FF416C);
  154. background-repeat: no-repeat;
  155. background-size: cover;
  156. background-position: 0 0;
  157. color: #FFFFFF;
  158. position: relative;
  159. left: -100%;
  160. height: 100%;
  161. width: 200%;
  162. transform: translateX(0);
  163. transition: transform 0.6s ease-in-out;
  164. }
  165. .container.right-panel-active .overlay {
  166. transform: translateX(50%);
  167. }
  168. .overlay-panel {
  169. position: absolute;
  170. display: flex;
  171. align-items: center;
  172. justify-content: center;
  173. flex-direction: column;
  174. padding: 0 40px;
  175. text-align: center;
  176. top: 0;
  177. height: 100%;
  178. width: 50%;
  179. transform: translateX(0);
  180. transition: transform 0.6s ease-in-out;
  181. }
  182. .overlay-left {
  183. transform: translateX(-20%);
  184. }
  185. .container.right-panel-active .overlay-left {
  186. transform: translateX(0);
  187. }
  188. .overlay-right {
  189. right: 0;
  190. transform: translateX(0);
  191. }
  192. .container.right-panel-active .overlay-right {
  193. transform: translateX(20%);
  194. }
  195. .social-container {
  196. margin: 20px 0;
  197. }
  198. .social-container a {
  199. border: 1px solid #DDDDDD;
  200. border-radius: 50%;
  201. display: inline-flex;
  202. justify-content: center;
  203. align-items: center;
  204. margin: 0 5px;
  205. height: 40px;
  206. width: 40px;
  207. }
  208. </style>
2.4.2.3 vue

        定义需要的属性,定义函数,使用axios带着属性向后台Controller层发起请求,根据的到的响应数据决定是否登陆成功跳转页面

  1. <script>
  2. //创建vue对象
  3. new Vue({
  4. el:"#app", //vue作用于指定的元素及其子元素
  5. data:{ //用来声明vue的属性,页面上需要的东西
  6. user:{
  7. cellphone:"",
  8. password:""
  9. }
  10. },
  11. methods:{
  12. login: function (){
  13. console.log("登录")
  14. console.log("账号"+this.user.cellphone)
  15. console.log("密码"+this.user.password)
  16. //利用axios发送请求
  17. // then等于ajax的success
  18. axios.post("employee/login",this.user).then(res =>{
  19. //res后台返回的结果
  20. console.log(res)
  21. if(res.data.code == 200){
  22. window.location.href = "html/main.html"
  23. }else{
  24. this.$message.error(res.data.message);
  25. }
  26. })
  27. }
  28. }
  29. })
  30. const signUpButton = document.getElementById('signUp');
  31. const signInButton = document.getElementById('signIn');
  32. const container = document.getElementById('container');
  33. signUpButton.addEventListener('click', () => {
  34. container.classList.add("right-panel-active");
  35. });
  36. signInButton.addEventListener('click', () => {
  37. container.classList.remove("right-panel-active");
  38. });
  39. </script>

2.4.3 搭建后端处理业务

2.4.3.1 Controller层
        1.添加所需的注解
  1. @Controller
  2. @RequestMapping("/employee")
  3. @Slf4j
  4. public class EmployeeController {}
        2.处理前端请求(其实大部分业务逻辑应该在service层处理)

        获取响应service层对象,定义map存储用户登录数据,定义方法,添加方法所需的注解,接收前端所传的数据,设置单态登录

  1. @Resource
  2. private EmployeeService employeeService;
  3. //记录当前登录的用户有哪些
  4. //ConcurrentHashMap是一个线程安全的Map,效率比hashmap低,比hashtable高
  5. private static final ConcurrentHashMap<String,HttpSession> sessions = new ConcurrentHashMap<>();
  6. @RequestMapping("/login") // employee/login
  7. @ResponseBody
  8. //在处理请求的方法中如果想要request、response、session只需在形参指定
  9. public ResponseResult<Boolean> login(@RequestBody EmployeeVo employee, HttpSession session){
  10. log.debug("处理登录请求");
  11. log.debug(employee.toString());
  12. Employee byCellphone = employeeService.findByCellphone(employee.getCellphone());
  13. if(byCellphone!=null&&byCellphone.getPassword().equals(employee.getPassword())) {
  14. log.debug(byCellphone.toString());
  15. session.setAttribute("eid",byCellphone.getId());
  16. // 查看当前账号是否在其他地方登录过,有登录则让之前的下线
  17. log.debug("session:"+session.isNew());
  18. if(sessions.containsKey(byCellphone.getCellphone())){
  19. log.debug(byCellphone.getCellphone());
  20. //获取之前的session
  21. HttpSession old = sessions.get(byCellphone.getCellphone());
  22. try {
  23. old.removeAttribute("eid");
  24. session.setAttribute("eid",byCellphone.getId());
  25. }catch (IllegalStateException e){
  26. sessions.put(byCellphone.getCellphone(),session);
  27. return new ResponseResult<>(200,"登录成功",true);
  28. }
  29. }
  30. //将当前的session放入map
  31. sessions.put(byCellphone.getCellphone(),session);
  32. return new ResponseResult<>(200,"登录成功",true);
  33. }else{
  34. return new ResponseResult<>(500,"账号或密码有误",false);
  35. }
  36. }
2.4.3.2 service层
  1. @Data
  2. @Slf4j
  3. @Service
  4. public class EmployeeServiceimpl implements EmployeeService {
  5. @Resource
  6. private EmployeeMapper employeeMapper;
  7. @Override
  8. public Employee findByCellphone(String cellphone) {
  9. log.info("调用 mapper执行sql");
  10. return employeeMapper.findByCellphone(cellphone);
  11. }
  12. }
2.4.3.3 mapper层(dao层)
  1. @Mapper
  2. public interface EmployeeMapper {
  3. Employee findByCellphone(String cellphone);
  4. }

        mapper.xml

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <!--namespace:命名空间,用来避免id相同的sql语句冲突
  6. 一般使用一个完整的类名
  7. -->
  8. <mapper namespace="com.woniuxy.property1002.mapper.EmployeeMapper">
  9. <select id="findByCellphone" resultType="com.property.entity.Employee">
  10. select * from employee where cellphone = #{cellphone}
  11. </select>
  12. </mapper>
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/276420
推荐阅读
相关标签
  

闽ICP备14008679号