SpringBoot login + 6 sets of homepages-[JSB project actual combat]

SpringBoot series article directory

SpringBoot knowledge range - learning steps [000 of JSB series]

This series of school motto

Use the free public video to fly to the training class! If you are beaten to death, you will not report to work, and you will make money by working hard!
As long as you have a computer, you can do front and rear projects! N years of studying hard and no one asked, once you become famous, the world knows it!

There are many SpringBoot technologies

Han Shunping said: People who learn JAVA have two major difficulties
. The first is confusion. There is too much knowledge in JAVA from Baidu, and they don’t know what
to learn at all. The second confusion is that they don’t know what order to learn.
This part of SpringBoot is also the favorite to be interviewed. Many people’s resumes are packaged and embellished. The above experience seems to be at least 10K, but they only dare to ask for 3K, which makes the interview manager unable to cope.
Calling Juanjuan every day, in fact, he has no experience at all. I just want to be the king, and I have been fishing for a long time.
This [JSB project actual combat] is about learning and using SpringBoot (JSB series is the tutorial). In fact, it is basically a simplified SpringBoot. There is not a complete set like Ruoyi, but many people are completely fake because of the project experience, and the simplified ones are actually not. That roll is normal for others.
insert image description here

Environment and tools:

Environment of this series

environment win11
tool idea 2017
jdk 1.8
database mysql5.5
maven 3.2.1
Project import method maven import
Database front-end tools mysql-front (navicat also works)

Database front-end tool: mysql-front (navicat is also available)
is mainly because these are integrated with PHPStudy 2018, so sometimes it is lazy to open navicat
about the importance of the environment, directly see the above " SpringBoot project compilation and error handling – JSB series 001 "

Upper renderings

No matter what the system is, except for small games on windows, which one is not allowed to register, log in, and have a home page?
In fact, I came to show off the effect of the homepage.

home page

At the beginning, there is a dog, and Taoist priests are walking all over the place, er, the channel is connected to the wrong channel.
Start with a small circle, and then connect to a beautiful homepage. In fact, I originally wanted to put an animation, but it seems that only GIFs are available on CSDN? Not mp4, normal format. Is the 256 colors of GIF dazzling? I'll just post pictures. Over-animation self-brain supplement...insert image description here
insert image description here
insert image description here

log in

This appears
to be the case. Anyway, there are also verification codes, and you can change them by clicking. It can only be said that it is not ugly, right?
insert image description here

Profile settings

The project directory cannot contain Chinese characters or spaces, so it is best to obediently use variable names that can be recognized by the C language

#数据库连接池配置
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.platform=mysql
#配置数据源
spring.datasource.url=jdbc:mysql://localhost:3306/jsb_db_score?characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#Mybatis配置
#扫描的实体的包
mybatis.typeAliasesPackage=com.score.bean
#扫描的配置文件地址
mybatis.mapperLocations=classpath:mapper/*.xml
#mybatis.configLocation=classpath:mybatis-config.xml
server.port=8080

#控制台打印SQL语句
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl

It should be noted that the port number to start and
the name of the datasource in the datasource. Username Password. In addition, the driver of mysql is com.mysql.jdbc.Driver.
Generally speaking,
com.mysql.jdbc.Driverit is before mysql-connector-java 5.5, and
com.mysql.cj.jdbc.Driverit is after mysql-connector-java 6 and 6.
Beginners tend to fall into a misunderstanding, that is, the latest version of something is the best. In fact, it is very likely that what he wrote is obviously enough for JDK6.0. While shouting that his machine has insufficient memory, he let the memory run things that he can't use. For example, idea should be regarded as the most stuck among these developer tools. Someone might just open a few web pages, so why not use webstorm? Even when writing a lot of code, why not choose the lighter-weight VSCode?

import database

Open mysql-front or navicat
Note: Database name: jsb_db_scoresuper user: root Password: 123456
Just run the attachment in this example. The screenshot of the successful import of the database is as follows:
System user login: (account name: admin password: 123456) Without MD5 encryption,
insert image description here
the ER diagram is as follows:
insert image description here

The project directory is shown in the figure:

Those who are not familiar with SpringBoot can study the [JSB series] carefully and pay attention to the directory hierarchy.

insert image description here

For the difference between public and template, please refer to " Where to put the WEB page in the SpringBoot project – [JSB Series 008] "

code part:

controller

package com.score.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.score.bean.ResultObject;
import com.score.bean.TStudent;
import com.score.bean.User;
import com.score.service.IUserService;
import com.score.service.TStudentService;
import com.score.util.Constant;

/**
 * @author hmg
 *
 */
@RequestMapping("/user")
@RestController //标识为返回类型为Json的控制器
public class UserController {
    
    
	
	//自动注入服务类
	@Autowired
	private IUserService userService;
	
	@Autowired
	private TStudentService studentService;
	
    //标识请求地址
    @RequestMapping("/login")
    public ResultObject<List<User>> getUsers(User user,HttpServletRequest request) {
    
    
    	//查询用户列表
    	List<User> list= userService.getUser(user);
    	ResultObject<List<User>> rs=new ResultObject<List<User>>();
    	if(list.isEmpty()) {
    
    
    		//状态码
        	rs.setCode(Constant.FAILURE_RETUEN_CODE);
        	//提示
        	rs.setMsg("登录失败");
    	}else {
    
    
    		//状态码
        	rs.setCode(Constant.SUCCESS_RETUEN_CODE);
        	request.getSession().setAttribute("user", list.get(0));
        	//提示
        	rs.setMsg("登录成功");
    	}    	
    	//数据
    	rs.setData(list);
        return rs;
    }
    @RequestMapping("/loginOut")
    public ResultObject<Object> loginOut(HttpServletRequest request) {
    
    
    	//查询用户列表
    	ResultObject<Object> rs=new ResultObject<Object>();
    	request.getSession().removeAttribute("user");	
    	//数据
    	rs.setCode(Constant.SUCCESS_RETUEN_CODE);
    	rs.setMsg("退出成功");
        return rs;
    }
    
    //标识请求地址
    @RequestMapping("/studentLogin")
    public ResultObject<List<TStudent>> studentLogin(User user,HttpServletRequest request) {
    
    
    	//查询用户列表
    	TStudent student=new TStudent();
    	student.setStudentNo(Integer.parseInt(user.getUserName()));
    	student.setStuPass(user.getPassword());
    	List<TStudent> list= studentService.selectloginStudent(student);
    	ResultObject<List<TStudent>> rs=new ResultObject<List<TStudent>>();
    	if(list.isEmpty()) {
    
    
    		//状态码
        	rs.setCode(Constant.FAILURE_RETUEN_CODE);
        	//提示
        	rs.setMsg("登录失败");
    	}else {
    
    
    		//状态码
        	rs.setCode(Constant.SUCCESS_RETUEN_CODE);
        	request.getSession().setAttribute("student", list.get(0));
        	//提示
        	rs.setMsg("登录成功");
    	}    	
    	//数据
    	rs.setData(list);
        return rs;
    }
    @RequestMapping("/studentloginOut")
    public ResultObject<Object> studentloginOut(HttpServletRequest request) {
    
    
    	//查询用户列表
    	ResultObject<Object> rs=new ResultObject<Object>();
    	request.getSession().removeAttribute("student");	
    	//数据
    	rs.setCode(Constant.SUCCESS_RETUEN_CODE);
    	rs.setMsg("退出成功");
        return rs;
    }
    
}

filter

Although there is no spring security, simple permissions still need to be controlled, and people cannot pass through the index directly. This is different from the previous requirement. See " SpringBoot only knows how to push SSM projects – [JSB project combat] "
, so it is best to learn step by step. The knowledge acquired in this way is solid enough.
The configuration class is definitely a must.
For this knowledge point, please refer to " SpringBoot Configuration Class – JSB Series 003 "

package com.score.interceptor;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FilterConfig {
    
    
 
    @Bean
    public FilterRegistrationBean registFilter() {
    
    
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new LoginFilter());
        registration.addUrlPatterns("/*");
        registration.setName("loginFilter");
        registration.setOrder(1);
        return registration;
    }
 
}

Then, the Filter code is as follows:

package com.score.interceptor;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.score.util.Constant;

@WebFilter(filterName = "loginFilter", urlPatterns = "/*.html")
public class LoginFilter implements Filter {
    
    
 
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    
    
 
        System.out.println("----------------------->过滤器被创建");
    }
 
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
    
    
 
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response=(HttpServletResponse)servletResponse;
        String requestURI = request.getRequestURI();
        System.out.println("--------------------->过滤器:请求地址"+requestURI);
        if(Constant.loginUrl.equals(requestURI)||requestURI.contains(Constant.AESSET)||Constant.LOGIN_URI.equals(requestURI)||Constant.STUDENT_LOGIN_URL.equals(requestURI)) {
    
    
         	  filterChain.doFilter(servletRequest, servletResponse);
        }else {
    
    
        	  if(Constant.STUDENT_INDEX.equals(requestURI)||Constant.MY_SCORE.equals(requestURI)||
        			  Constant.STUDENT_LOGINOUT_URL.equals(requestURI)||Constant.GET_MY_SCORE.equals(requestURI)||
        			  	Constant.SCORE.equals(requestURI)||Constant.GET_MY_SCORE_COUNT.equals(requestURI)
        			  ) {
    
    
        		  Object obj=request.getSession().getAttribute("student");
                  if(obj==null){
    
    
                  	response.sendRedirect("/login.html");
                  	return;
                  }else {
    
    
                  	 filterChain.doFilter(servletRequest, servletResponse);
                  }
        	  }else {
    
    
        		  Object obj=request.getSession().getAttribute("user");
                  if(obj==null){
    
    
                  	response.sendRedirect("/login.html");
                  	return;
                  }else {
    
    
                  	 filterChain.doFilter(servletRequest, servletResponse);
                  }
        	  }
             
        }
    }
    @Override
    public void destroy() {
    
    
        System.out.println("----------------------->过滤器被销毁");
    }

}

Analyze the situation of filters and sessions in detail

In fact, this method was the first method used in the project. It was only after the performance of the client’s computer improved that the cookie method was slowly used. The “3Q War” pushed the security issue of cookies to the forefront, and returned to the session login method again. To be precise, one server can support 1 million users now. What about the group of clusters? This is why even a large company like Huawei has some systems (some systems, of course not all) that still use the session method. As for why even 1% of Huawei's users still use springCloud, and a full set of JWT, token, etc., this can only be said to be the company's strategy. What if the company goes public in three years like Duoduo?
Some problems are not technical problems, but the company's operational decision-making matters. As a worker, that is what the company uses, whatever is the best!
insert image description here

front page

	<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>后台登录</title>
		<link rel="stylesheet" type="text/css" href="assets/admin/layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="assets/admin/css/login.css" />
		<script src="assets/js/aJaxUtil.js"></script>
		<script src="assets/js/jquery-3.3.1.min.js"></script>
	</head>

	<body>
		<div class="m-login-bg">
			<div class="m-login">
				<h3>范德彪成绩管理查询系统</h3>
				<div class="m-login-warp">
					<form class="layui-form">
						<div class="layui-form-item">
							<input type="text" name="userName" required lay-verify="required" placeholder="用户名" autocomplete="off" class="layui-input">
						</div>
						<div class="layui-form-item">
							<input type="password" name="password" required lay-verify="required" placeholder="密码" autocomplete="off" class="layui-input">
						</div>
						<div class="layui-form-item">
							<input type="radio" name="type" value="1" title="教师" checked="">
      						<input type="radio" name="type" value="2" title="学生">
						</div>
						<div class="layui-form-item m-login-btn">
							<div class="layui-inline">
								<button class="layui-btn layui-btn-normal" lay-submit lay-filter="login">登录</button>
							</div>
							<div class="layui-inline">
								<button type="reset" class="layui-btn layui-btn-primary">取消</button>
							</div>
						</div>
					</form>
				</div>
				<p class="copyright" style="color: #00b7ee"><a href="https://blog.csdn.net/dearmite">Copyright 2021 by 项目开发后花园</a></p>
			</div>
		</div>
		<script src="assets/admin/layui/layui.all.js" type="text/javascript" charset="utf-8"></script>
		<script>
			layui.use(['form', 'layedit', 'laydate','jquery'], function() {
    
    
				var form = layui.form,
					layer = layui.layer,
					admin = layui.admin,
					$ = layui.jquery;

				//自定义验证规则
				form.verify({
    
    
					userName: function(value) {
    
    
						if(value.length < 4) {
    
    
							return '用户名至少4个字符';
						}
					},
					password: [/(.+){
    
    5,12}$/, '密码必须5到12位']
					
				});
				//监听提交
				form.on('submit(login)', function(data) {
    
    
					   var str = JSON.stringify(data.field);
			            var param = JSON.parse(str);
			     		if("1"==param.type){
    
    
			     			$.ajax({
    
    
				                //几个参数需要注意一下
				                    type: "POST",//方法类型
				                    dataType: "json",//预期服务器返回的数据类型
				                    url: "/user/login",//url
				                    data: param,
				                    success: function (result) {
    
    
				                    	if (result.code == "0") {
    
    
						                       location.href="/index.html";
						                    } else {
    
    
						                        layer.msg('用户名密码错误', {
    
    
						                            icon: 5
						                        });
						                    }
				                    },
				                    error : function() {
    
    
				                    	layer.msg('服务器错误', {
    
    
				                            icon: 5
				                        });
				                    }
				                });
			     		}else{
    
    
			     			debugger;
			     			var userName=param.userName;
			     			var reg=/^[\d]{
    
    6,10}$/;
			     			if(userName.length>10){
    
    
			     				layer.msg('学号长度不能大于10位', {
    
    
		                            icon: 5
		                        });
			     			}
			     			if(reg.test(userName)){
    
    
			     				$.ajax({
    
    
					                //几个参数需要注意一下
					                    type: "POST",//方法类型
					                    dataType: "json",//预期服务器返回的数据类型
					                    url: "/user/studentLogin",//url
					                    data: param,
					                    success: function (result) {
    
    
					                    	if (result.code == "0") {
    
    
							                       location.href="/student-index.html";
							                    } else {
    
    
							                        layer.msg('用户名密码错误', {
    
    
							                            icon: 5
							                        });
							                    }
					                    },
					                    error : function() {
    
    
					                    	layer.msg('服务器错误', {
    
    
					                            icon: 5
					                        });
					                    }
					                });
			     			}else{
    
    
			     				layer.msg('学生角色登录请使用学号', {
    
    
		                            icon: 5
		                        });
			     			}
			     		}	
					return false;
				});

			});
		</script>
	</body>

</html>

The homepage is generally more complicated, so it is often a homepage with more than 2,000 lines. Can you guess that you can read it all? I just want to tell everyone that beauty has a price. Here just shows the page code of login.html.
The last interface seen:
insert image description here

Other supporting page display

Directly to the page of the second scheme

insert image description here

insert image description here

The page of the third set of plans.

insert image description here

Crazy long, long pages for Package 4.

insert image description here

Matching 5 pages without e-commerce and homepage

insert image description here

insert image description here

Package 6 of mini e-commerce

insert image description here

insert image description here

supporting resources

No VIP, it depends on how many points you have, and CSDN seems to raise its price.











Operation:

No, understand is god
Biao's classic quotation: You have to be flexible when learning a project, if the opponent doesn't play cards according to the routine, then you can't play according to the routine.
insert image description here

Guess you like

Origin blog.csdn.net/dearmite/article/details/131919535