SpringBoot+layui社区人员健康信息管理系统-毕业设计-【JSB项目实战】

SpringBoot系列文章目录

SpringBoot知识范围-学习步骤【JSB系列之000】


本项目效果图

本项目特色, springBoot+mybatis-plus+ layui,文件上传 JSP页面放web-inf下,经后台映射转发
在这里插入图片描述

SpringBoot技术很多很多

韩顺平说:学习JAVA的人有两大难
第一困惑,JAVA能百度到的知识太多太多,完全不知道学啥
第二困惑,就是不知道以什么样的顺序去学,有的时候乱看一堆视频有遗漏,有的时候,两边的视频还有重复。
在这里插入图片描述
然后,再来看一般的springboot 的书籍中内容。
一般是这样。右侧为基础
在这里插入图片描述

如果基础不牢,要回避的知识

假定,你在学校做过了JAVA的小项目了。(我指的是swing,servlet 之类) 可能会点SSM,也可能不会,那我马上就要毕业了,我得搞项目,搞毕设呀。啊!!!

  • 第一个要回避的就是JWT。
  • 上面的不使用了,shiro 也就不需要了
  • 然后是redis
    说一下理由。第一,你一个人使用的系统,你用啥JWT?Session. cookie , JWT 都是你一个人在用。完全不存在用户信息泄漏。
    单点登录就更用不上了。一共就一个系统。
    redis 也不需要,别说你一个人在使用,就是全班的人都在使用50人在线,redis 的优势也自不出来。mysql 数据库连这一点点的数据都不能快速响应,那PHP的平台的不是要直接宕机?而且mybatis 本身还有缓存。
    当然了,这是指你自己要把代码弄懂的这个前提下说的。如果说别人运行好的。那用啥环境也不是你能决定了,是吧?

环境及工具:

本系列环境

环境win11
工具idea 2018
jdk1.8
数据库mysql5.5
maven3.6.0
项目导入方式maven 导入
数据库前端工具mysql-front (navicat 也可以)

数据库前端工具:mysql-front (navicat 也可以)
主要是这些跟PHPStudy 2018 整合了,所以有的时候懒的打开navicat
关于环境的重要性,直接看上面的《SpringBoot 的项目编译即报错处理–JSB系列之001

项目里可能要用到的技术

json

JSON(JavaScript Object Notation, JS对象简谱)是一种轻量级的数据交换格式。它基于 ECMAScript(European Computer Manufacturers Association, 欧洲计算机协会制定的js规范)的一个子集,采用完全独立于编程语言的文本格式来存储和表示数据。简洁和清晰的层次结构使得 JSON 成为理想的数据交换语言。 易于人阅读和编写。
这个东东一出来就直接把xml 的这种格式按地上摩擦了。而且可以可读性好,也把一些不可读的数据包形式也给取代了。

spring是一个开源的Java开发框架,它提供了一种全面的解决方案,用于构建企业级应用程序。Spring框架的设计理念是基于面向对象的编程思想和松耦合的架构原则,旨在简化Java应用程序的开发,并提供可扩展性和灵活性。
在这里插入图片描述
Spring框架的核心特性包括:
1、 控制反转(IoC):Spring通过控制反转将对象的创建和管理交给框架来完成,开发人员只需关注业务逻辑的实现。这种解耦的设计模式可以降低组件之间的耦合度,提高代码的可维护性和可测试性。

在这里插入图片描述
2、 依赖注入(DI):Spring通过依赖注入将组件之间的依赖关系注入到对象中,而不是硬编码在代码中。这样可以使得组件之间的关系更加灵活,并方便进行单元测试和模块化开发。
spring会自动的把JAR里的功能加到项目里,不管你用不用得上。过于灵活,导致spring的JAR包依赖成为了一个噩梦。
注意的是,这个是SSM为啥 要升级成springBoot的重大原因
如果用升级成使用maven ,不用springBoot 这种父pom 的办法,那么初学者 把一个项目的JAR的依赖整明白,怕是黄瓜菜都凉了。关公大老爷都可以把1000多个华雄杀一个来回了。:)
在这里插入图片描述
3、 面向切面编程(AOP)
Spring提供了面向切面编程的支持,可以将横切关注点(如事务管理、安全性等)从业务逻辑中分离出来,以提高代码的模块化和重用性。
spring成名之作。SSM的时候,你可以理解为事务的最方便的实现。
springBoot的时候,你可以理解为配置类的各种妙用。
4、 组件化开发:Spring鼓励使用组件化开发的方式,通过将应用程序划分为多个独立的模块(组件),来提高代码的可重用性和可维护性。同时,Spring提供了一些开箱即用的组件(如数据访问、Web开发、消息传递等),简化了开发过程。

Mybatis

M 一般指的是mybatis.
MyBatis本是apache的一个开源项目iBatis,2010年这个项目由apache software foundation迁移到了google code,并且改名为MyBatis。

Mybatis-plus

MyBatis-Plus (opens new window)(简称 MP)是一个 MyBatis (opens new window)的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。

MyBatis-Plus 已连续 5 年(2017 (opens new window)、2018 (opens new
window)、2019 (opens new window)、2020 (opens new window)、2021 (opens
new window))获得“OSC 年度最受欢迎中国开源软件”殊荣

MyBatis 项目是 apache 的一个开源项目
MyBatis Plus 是国内一家苞米豆公司对 MyBatis 进行的为此封装
按道理,苞米豆是不可能把他的产品名称起的这么让人混淆的。而且这个名称里还有mybatis 的字样,貌似不太光明正大的感觉。

其它的必要知识

  • 网页三剑客,这个不用说了
  • JAVA,你总得会idea吧
  • maven 这个也是必须的

配置文件

这个项目的重点是配置文件,因为这个项目使用的springboot + mybatis 并非是mybatis plus。

POM

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.code</groupId>
    <artifactId>myproject</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>myproject</name>
    <description>module project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <!--mysql8以上版本-->
        <mysql.version>5.1.6</mysql.version>
        <!--mysql8以下版本-->
        <mahout.version>0.6</mahout.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.mahout</groupId>
            <artifactId>mahout-core</artifactId>
            <version>${mahout.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.mahout</groupId>
            <artifactId>mahout-integration</artifactId>
            <version>${mahout.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>jetty</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.cassandra</groupId>
                    <artifactId>cassandra-all</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>me.prettyprint</groupId>
                    <artifactId>hector-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
            <version>${mysql.version}</version>
        </dependency>
        <!--dbutils-->
        <dependency>
            <groupId>commons-dbutils</groupId>
            <artifactId>commons-dbutils</artifactId>
            <version>1.6</version>
        </dependency>

        <!--druid-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.6</version>
        </dependency>


        <!--        springboot热部署-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
        <!--        不用写getset toString 构造函数-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.10</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>

        <!-- 添加servlet依赖模块 -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
           <!-- <scope>provided</scope>-->
        </dependency>
        <!-- 添加jstl标签库依赖模块 -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>

        <!-- 使用jsp引擎,springboot内置tomcat没有此依赖 -->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>


        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jdbc</artifactId>
        </dependency>
        <!--        springboot整合jpa-->
        <!--
        <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-data-jpa</artifactId>
         </dependency>
         -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>


        <!--java爬虫 \\-->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.3.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient-cache</artifactId>
            <version>4.3.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpmime</artifactId>
            <version>4.3.3</version>
        </dependency>
        <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.1</version>
        </dependency>
        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.10.3</version>
        </dependency>
        <!--java爬虫 //-->

        <!-- poi操作excel -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.8</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.8</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml-schemas</artifactId>
            <version>3.8</version>
        </dependency>

        <!-- file upload tools -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.2</version>
        </dependency>

        <!--fastjson json解析 打包-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.7</version>
        </dependency>


        <!-- 工具类-->
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>

        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.9.3</version>
        </dependency>


        <!-- 二维码 -->
        <dependency>
            <groupId>com.google.zxing</groupId>
            <artifactId>core</artifactId>
            <version>3.2.1</version>
        </dependency>
        <!-- 二维码 -->
        <dependency>
            <groupId>com.google.zxing</groupId>
            <artifactId>javase</artifactId>
            <version>3.2.1</version>
        </dependency>
        <!-- java mail -->
        <dependency>
            <groupId>com.sun.mail</groupId>
            <artifactId>javax.mail</artifactId>
            <version>1.4.4</version>
        </dependency>

        <!--  mybatis分页插件-->
        <!--导入pagehelper相关依赖-->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.1.2</version>
        </dependency>

        <!--整合mybatisplus-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatisplus-spring-boot-starter</artifactId>
            <version>1.0.5</version>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus</artifactId>
            <version>2.3</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.1</version>
        </dependency>

    </dependencies>

    <build>
        <resources>
            <!--引入静态文件-->
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
            <!--引入mapper对应的xml文件-->
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>

    </build>

</project>

yml配置

#运行端口号
server.port=8889
#配置项目路径
server.servlet.context-path=/myproject
#数据库连接配置信息  Ctrl+/ 注释
#mysql8驱动
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#mysql5驱动   记得把连接地址换成本机ip地址
#spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/jsbperson_db?characterEncoding=utf-8&useSSL=false&serverTimezone=GMT
spring.datasource.username=root
spring.datasource.password=123456
#mybatis配置
mybatis.type-aliases-package=com.code.entity
#mybatis.mapper-locations=classpath*:mapper/*.xml
mybatis-plus.mapper-locations=classpath*:mapper/*.xml
#jsp视图解析器
spring.mvc.view.prefix=/view/
spring.mvc.view.suffix=.jsp
#文件上传的配置
spring.servlet.multipart.max-file-size=120MB
spring.servlet.multipart.max-request-size=120MB
#开启日志调试
#logging.level.root=debug
#显示mybatis日志
logging.level.com.code.mapper=debug

这里要特别注意的是
这两行。

#jsp视图解析器
spring.mvc.view.prefix=/view/
spring.mvc.view.suffix=.jsp

上代码

package com.code.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.code.entity.*;
import com.code.util.GlobalResult;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@CrossOrigin("*") //允许跨域请求
public class IndexController extends BaseController {

    //跳转发布信息
    @RequestMapping("/send")
    public String send(Model model, HttpSession session) {
        List<Sorttype> sorttypeList = sorttypeMapper.selectByMap(null);
        model.addAttribute("sorttypeList", sorttypeList);
        return "send";
    }

    //跳转发布信息
    @RequestMapping("/yiqingMap")
    public String yiqingMap(Model model, HttpSession session) {
        return "yiqingMap";
    }

    //发布信息保存
    @RequestMapping("/sendSubmit")
    public String sendSubmit(Datainfo datainfo, Model model, HttpSession session) {
        datainfoMapper.insert(datainfo);
        return "redirect:index";
    }

    //信息删除
    @RequestMapping("/datainfoDelete")
    public String datainfoDelete(Integer id, Model model, HttpSession session) {
        datainfoMapper.deleteById(id);
        return "redirect:myDataList";
    }

    //发布信息
    @RequestMapping("/myDataList")
    public String myDataList(Model model, HttpSession session) {
        //判断是否登陆
        if (session.getAttribute("loginUserinfo") == null) {
            model.addAttribute("errorMsg", "登陆以后才可以操作");
            return "login";
        }
        Userinfo loginUserinfo = getLoginUserinfo(session);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("adduser", loginUserinfo.getName());
        List<Datainfo> datainfoList = datainfoMapper.selectByMap(map);
        model.addAttribute("datainfoList", datainfoList);   //绑定搜索关键词
        return "myDataList";
    }


    @RequestMapping("/")
    public String index2() {
        return "redirect:index";
    }

    @RequestMapping("/core")
    public String core() {
        return "core";
    }

    //列表页面  分页搜索功能都有
    @RequestMapping("/index")
    public String index(String keyword, String sorttype, String type, Integer p, Model model, HttpSession session) {
        System.out.println("进入系统首页......");
        p = null == p ? 1 : p; //默认显示第一页
        Integer pageSize = 6; //默认每页显示10条

        EntityWrapper<Datainfo> queryWrapper = new EntityWrapper<Datainfo>();
        if (StringUtils.isNotEmpty(keyword)) {
            queryWrapper.like("name", keyword);
            model.addAttribute("keyword", keyword);   //绑定搜索关键词
            pageSize = 1000;
        }
        if (StringUtils.isNotEmpty(sorttype)) {
            queryWrapper.eq("sorttype", sorttype);
            model.addAttribute("sorttype", sorttype);   //绑定搜索关键词
            pageSize = 1000;
        }
        queryWrapper.orderBy("id", true);  // order by id desc 根据id倒序
        Page<Datainfo> sortPage = new Page<Datainfo>(p, pageSize);//参数一是当前页,参数二是每页个数
        List<Datainfo> datainfoList = datainfoMapper.selectPage(sortPage, queryWrapper);

        long total = sortPage.getTotal(); //总页数
        int current = sortPage.getCurrent();
        long pages = sortPage.getPages();
        model.addAttribute("datainfoList", datainfoList);  //绑定接受参数
        model.addAttribute("cp", current);   //当前页
        model.addAttribute("tp", pages);   //总页数
        model.addAttribute("total", total);   //总条数
        model.addAttribute("pageListURL", "/index");   //总条数

        List<Sorttype> sorttypeList = sorttypeMapper.selectByMap(null);
        model.addAttribute("sorttypeList", sorttypeList);
        List<Carousel> carouselList = carouselMapper.selectByMap(null);
        session.setAttribute("carouselListIndex", carouselList);
        if (null != type) {
            return "index2";
        }
        return "index";
    }


    //详情页面
    @RequestMapping("/detail")
    public String index(Integer id, Model model, HttpSession session) {
        Datainfo datainfo = datainfoMapper.selectById(id);
        model.addAttribute("datainfo", datainfo);
        datainfo.setNums(datainfo.getNums() + 1);
        datainfoMapper.updateById(datainfo);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("tid", id);
        List<Commentinfo> commentinfoList = commentinfoMapper.selectByMap(map);
        model.addAttribute("commentinfoList", commentinfoList);
        List<Sorttype> sorttypeList = sorttypeMapper.selectByMap(null);
        model.addAttribute("sorttypeList", sorttypeList);
        return "detail";
    }


    //评论保存
    @RequestMapping("/commentinfoSubmit")
    public String commentinfoSubmit(Commentinfo obj, Model model, HttpSession session) {
        commentinfoMapper.insert(obj);
        return "redirect:detail?id=" + obj.getTid();
    }

    //评论点赞
    @RequestMapping("/commentinfoDianzan")
    @ResponseBody
    public GlobalResult commentinfoDianzan(int id, Model model, HttpSession session) {
        Commentinfo commentinfo = commentinfoMapper.selectById(id);
        commentinfo.setLikenum(commentinfo.getLikenum() + 1);
        commentinfoMapper.updateById(commentinfo);
        return GlobalResult.ok("评论点赞成功");
    }

    //个人中心
    @RequestMapping("/userinfoCenter")
    public String userinfoCenter(HttpSession session, Model model) {
        Userinfo userinfo = (Userinfo) session.getAttribute("loginUserinfo");
        model.addAttribute("userinfo", userinfo);
        return "userinfoCenter";
    }


    //退出登陆
    @RequestMapping("/loginOut")
    public String loginOut(HttpSession session, Model model) {
        session.invalidate();
        return "redirect:index";
    }

    @RequestMapping("/infoList")
    public String infoList(Model model, String keyword) {
        EntityWrapper<Noticeinfo> queryWrapper = new EntityWrapper<Noticeinfo>();
        //如果有搜索内容 则进行模糊查询
        if (StringUtils.isNotEmpty(keyword)) {
            queryWrapper.like("noticetitle", keyword).or().like("noticecontent", keyword);
            model.addAttribute("keyword", keyword);   //绑定搜索关键词
        }
        List<Noticeinfo> noticeinfoList = noticeinfoMapper.selectList(queryWrapper);
        model.addAttribute("noticeinfoList", noticeinfoList);
        return "infoList";
    }


    @ResponseBody
    @RequestMapping("/checkName")
    public GlobalResult registerSubmit(String name, HttpSession session) {
        List<Userinfo> userinfoList = userinfoMapper.selectByMap(null);
        for (Userinfo u : userinfoList) {
            if (u.getName().equals(name)) {
                return GlobalResult.errorMsg("用户名已经存在");
            }
        }
        return GlobalResult.ok("可用使用");
    }

    //注册提交
    @ResponseBody
    @RequestMapping("/registerSubmit")
    public GlobalResult registerSubmit(Userinfo userinfo, String vercode, HttpSession session) {
        String randCode = session.getAttribute("randCode").toString();
        if (!randCode.equals(vercode)) {
            return GlobalResult.errorMsg("验证码不正确");
        }
        List<Userinfo> userinfoList = userinfoMapper.selectByMap(null);
        for (Userinfo u : userinfoList) {
            if (u.getName().equals(userinfo.getName())) {
                return GlobalResult.errorMsg("用户名已经存在");
            }
            if (u.getPhone().equals(userinfo.getPhone())) {
                return GlobalResult.errorMsg("手机号已经存在");
            }
            if (u.getEmail().equals(userinfo.getEmail())) {
                return GlobalResult.errorMsg("邮箱已经存在");
            }
        }
        Integer insert = userinfoMapper.insert(userinfo);
        return GlobalResult.ok("用户注册成功");
    }

    //个人信息修改
    @ResponseBody
    @RequestMapping("/updateUserinfo")
    public GlobalResult updateUserinfo(HttpSession session, Userinfo userinfo) {
        Integer insert = userinfoMapper.updateById(userinfo);
        setLoginUserinfo(session, userinfo);
        return GlobalResult.ok("个人信息修改成功");
    }

    //公共查询方法
    @ResponseBody
    @RequestMapping("/selectAction")
    public GlobalResult selectAction(String sql) {
        List<Map> mapList = commonMapper.selectAction(sql);
        return GlobalResult.ok(mapList);
    }

    //公共修改方法
    @ResponseBody
    @RequestMapping("/updateAction")
    public GlobalResult updateAction(String sql) {
        commonMapper.updateAction(sql);
        return GlobalResult.ok("操作成功");
    }

    //登陆提交验证
    @ResponseBody
    @RequestMapping("/loginSubmit") //插入数据
    public GlobalResult login(String username, String password, String vercode, HttpSession session, Model model) {
        String randCode = session.getAttribute("randCode").toString();
        if (!randCode.equals(vercode)) {
            return GlobalResult.errorMsg("验证码不正确");
        }
        List<Userinfo> userinfoList = userinfoMapper.selectByMap(null);
        Userinfo admin = new Userinfo();
        boolean is = false;
        for (Userinfo admininfo : userinfoList) {
            if (admininfo.getName().equals(username) && admininfo.getPassword().equals(password)) {
                admin = admininfo;
                is = true;
                break;
            }
        }
        if (is) {
            session.setAttribute("loginUserinfo", admin);
            return GlobalResult.ok("登陆成功");
        } else {
            model.addAttribute("msg", "账号或者密码错误");
            return GlobalResult.errorMsg("账号或者密码错误");
        }
    }


    //测试直接登录
    @RequestMapping("/index00")
    public String index00(HttpSession session) {
        session.setAttribute("loginUserinfo", userinfoMapper.selectById(1));
        return "redirect:index";
    }

}

	@RequestMapping("/location")
	public R location(String lng,String lat) {
		if(BAIDU_DITU_AK==null) {
			BAIDU_DITU_AK = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "baidu_ditu_ak")).getValue();
			if(BAIDU_DITU_AK==null) {
				return R.error("请在配置管理中正确配置baidu_ditu_ak");
			}
		}
		Map<String, String> map = BaiduUtil.getCityByLonLat(BAIDU_DITU_AK, lng, lat);
		return R.ok().put("data", map);
	}

mapper

mybatis-plus的mapper 肯定比mybatis 要简单一些。


package com.code.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.code.entity.Admininfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public interface CommonMapper extends BaseMapper<Admininfo> {

    //公共的查询方法
    @Select(" ${sql} ")
    public List<Map> selectAction(@Param("sql") String sql);

    //公共的增删修改方法
    @Update(" ${sql} ")
    public int updateAction(@Param("sql") String sql);



}


实体类

这里有必要说一下idea2018并不直接支持lombok,需要自己导入一下。
在这里插入图片描述

跑起来

后台

数据库的部分你自己搞定吧,如果到了做毕设还不会数据库,这个还是要下点功夫了。
加入启动的URL 与用户的提示,这样对初学者要方便太多。

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<ul class="layui-nav layui-bg-blue" lay-filter="" style="margin-bottom: 0px;text-align: center;">
    <li class="layui-nav-item"><a href="${ctx}/index">某社区人员健康信息管理系统</a></li>
    <li class="layui-nav-item"><a href="${ctx}/index">首页</a></li>
    <li class="layui-nav-item"><a href="${ctx}/infoList">公告</a></li>
    <c:if test="${sessionScope.loginUserinfo==null}">
        <li class="layui-nav-item"><a href="${ctx}/admininfo/tologin" target="_blank">后台管理</a></li>
        <li class="layui-nav-item"><a href="${ctx}/view/login.jsp">用户登陆</a></li>
        <li class="layui-nav-item"><a href="${ctx}/view/register.jsp">点我注册</a></li>
    </c:if>
    <c:if test="${sessionScope.loginUserinfo!=null}">

      <%--  <li class="layui-nav-item"><a href="${ctx}/send">发布信息</a></li>
        <li class="layui-nav-item"><a href="${ctx}/myDataList">我的数据</a></li>--%>
        <li class="layui-nav-item"><a href="${ctx}/core">我的功能</a></li>
        <li class="layui-nav-item">
            <a href=""><img src="${sessionScope.loginUserinfo.picurl}"
                            class="layui-nav-img">${sessionScope.loginUserinfo.name}-${sessionScope.loginUserinfo.role}
            </a>
            <dl class="layui-nav-child">
                <dd><a href="${ctx}/userinfoCenter">个人中心</a></dd>
                <dd><a href="${ctx}/loginOut">退出登录</a></dd>
            </dl>
        </li>
    </c:if>
</ul>

用浏览器最原始的方式验证

在浏览器上念出一段神奇的古老埃及法老的字符。点击运行出来的那个命令窗口里的URL就可以了。
事实上这种方式比程序直接打开CHROME还方便,因为有人会使用好几个浏览器

http://localhost:8889/myproject/index

在这里插入图片描述

页面展示

前台登陆可以填写的信息如下:
在这里插入图片描述
在这里插入图片描述
后台的登陆。(入口从前台的菜单进入)
在这里插入图片描述
在这里插入图片描述
有管理员维护,社区用户维护,健康等信息维护,以及网站的轮播,新闻等的维护。
在这里插入图片描述
在这里插入图片描述
是一个SSM或springBoot 的大作业,或毕业设计。
好,一步成功点亮,关电,拉闸,领盒饭!走人。

总结

提示:IT是一个要多动手的职业,一定要多练不要贪快:
这一部涉及到的知识可以说非常之多。能花一周的时间把这篇文章里的东西弄一个大概并运行出来,也是很不容易的,而且难度也不低,准确一点说,培训机构也能让你似懂非懂的把这个代码跑起来。
做到这一步,你会了springBoot了么?会了,但是现在你会的都是初级基本上就是对付一下简单项目。传的对象复杂了,数据信息多了,都可能会出现这样那样的问题。
还有就是springboot 的缓存,JWT,消息队列,安全机制 ,任务管理其实他们从SSM甚至SSH的时候就有了。只是springboot 一下子全集成过来了。你去看别人的SSM项目 ,这些东西也都有。
所以,程序猿与学员纯在着本质的差别。那么如何提高呢?当然要多读别人的成功项目了。
GITEE上面存在着大量的springboot的项目,英文没有问题的话,可以去github。

配套资源

这个资源上成的VIP的,不好意思了
SpringBoot+layui社区人员健康信息管理系统-毕业设计-【JSB项目实战】

https://download.csdn.net/download/dearmite/88175536

非VIP的0积分资源
https://download.csdn.net/download/dearmite/88235718

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
我希望我点击注册的时候跳转到regist.html页面,用layui的方式实现,<div class="layui-container"> <div class="admin-login-background"> <div class="layui-form login-form"> <form class="layui-form" action=""> <div class="layui-form-item logo-title"> <h1>用户登录</h1> </div> <div class="layui-form-item"> <label class="layui-icon layui-icon-username" for="username"></label> <input type="text" name="email" lay-verify="required|account" placeholder="邮箱" autocomplete="off" class="layui-input" value="admin"> </div> <div class="layui-form-item"> <label class="layui-icon layui-icon-password" for="password"></label> <input type="password" name="password" lay-verify="required|password" placeholder="密码" autocomplete="off" class="layui-input" value="123456"> </div> <div class="layui-form-item"> <label class="layui-icon layui-icon-vercode" for="captcha"></label> <input type="text" name="captcha" lay-verify="required|captcha" placeholder="图形验证码" autocomplete="off" class="layui-input verification captcha" value="xszg"> <div class="captcha-img"> <img id="captchaPic" src="../images/captcha.jpg"> </div> </div> <!-- <div class="layui-form-item"> <input type="checkbox" name="rememberMe" value="true" lay-skin="primary" title="记住密码"> </div> --> <div class="layui-form-item"> <button class="layui-btn layui-btn layui-btn-normal layui-btn-fluid" lay-submit="" lay-filter="login">登 录</button> </div> <div class="layui-form-item"> <button class="layui-btn layui-btn layui-btn-normal layui-btn-fluid" lay-submit="" lay-filter="regist">注 册</button> </div>
06-12

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

项目花园范德彪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值