springboot项目:家庭整理服务管理系统39774(java+VUE+Mybatis+Maven+Mysql)
一、项目运行
环境配置:
Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)。
项目技术:
Springboot + mybatis + Maven + Vue 等等组成,B/S模式 + Maven管理等等。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
6.数据库:MySql 5.7/8.0等版本均可;
技术栈
1. 后端:Springboot mybatis
2. 前端:vue+css+javascript+jQuery+easyUI+highcharts
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,修改配置,运行项目;
3. 将项目中applicationContext.xml配置文件中的数据库配置改为自己的配置,然后运行;
4. 运行成功后,在浏览器中输入:http://localhost:8080/
<%@ page contentType="text/html;charset=GB2312" %>
<%@page language="java" import="java.util.*" import="javax.servlet.http.*" import="myservlet.control.HandleCode"%>
<jsp:useBean id="loginBean" class="mybean.data.Login" scope="session"/>
<HTML>
<title>登录页面</title>
<HEAD>
</HEAD>
<BODY style="background:url(image/放风筝.jpg) ;background-size:cover; ">
<br>
<a href="shouye.jsp"><img src="image/箭头.png"/>回到首页</a>
<div align="center">
<br>
<br>
<br>
<FORM action="loginServlet" Method="post" name="loginForm">
登录名称: <Input type=text name="logname" onInput="lognameChange()">
<span id="lognameText"></span><span id="loginInfo"></span><br><br>
输入密码: <Input type=password name="password" onInput="passwordChange()">
<span id="passwordText"></span><br><br>
验证码:   <input type="text" name="code" size="10" onInput="validate()">
<img name="imgValidate" onclick="refresh()" border=0 src="code.jsp"></img>
<span id="codeText" name="codeText" style="color:green"></span><br><br>
<input type="submit" value="提交" style="background:url(imagepath) no-repeat">
<Input type=reset name="g" value="重置" style="background:url(imagepath) no-repeat">
</form>
</div >
<script type="text/javascript">
function lognameChange(){
var str=loginForm.logname.value;
var reg=/[a-zA-Z0-9]{4,16}/;
if(reg.test(str)){
lognameText.innerHTML="√";
lognameText.style.color="green";
}
else{
lognameText.innerHTML="账号为4位以上规定字符";
lognameText.style.color="red";
}
}
function passwordChange(){
var str=loginForm.password.value;
var reg=/^[x00-x7f]+$/;
if(reg.test(str)&&str.length>4&&str.length<17){
passwordText.innerHTML="√";
passwordText.style.color="green";
}else{
passwordText.innerHTML="密码是4位以上字符";
passwordText.style.color="red";
}
}
function refresh(){
loginForm.imgValidate.src="code.jsp"+"?id"+Math.random();
}
//AJAX
function validate(){
var code=loginForm.code.value;
var xmlHttp=new XMLHttpRequest();
var url="codeServlet?code="+ code;
xmlHttp.open("POST", url,true);
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
codeText.innerHTML=xmlHttp.responseText;
}else{
codeText.innerHTML="正在验证......";
}
}
xmlHttp.send();
}
</script>
</BODY>
</HTML>
package myservlet.control;
import mybean.data.*;
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class HandleLogin extends HttpServlet{
public void init(ServletConfig config) throws ServletException {
super.init(config);
try {
Class.forName("com.mysql.jdbc.Driver");
}
catch(Exception e){}
}
public String handleString(String s){
try{
byte bb[]=s.getBytes("iso-8859-1");
s=new String(bb);
}
catch(Exception ee){}
return s;
}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
Connection con;
Statement sql;
String logname=request.getParameter("logname").trim(), //trim() 函数用于去除字符串两端的空白字符。
password=request.getParameter("password").trim();
logname=handleString(logname);
password=handleString(password);
String uri="jdbc:mysql://127.0.0.1/toy_db?"+ "user=root&password=123456&characterEncoding=gb2312";
boolean boo=(logname.length()>3)&&(password.length()>3);
try{
con=DriverManager.getConnection(uri);
String condition="select * from client where logname = '"+logname+"' and password ='"+password+"'";
sql=con.createStatement();
if(boo){
ResultSet rs=sql.executeQuery(condition);
boolean m=rs.next();
Code codeBean=null;
HttpSession session=request.getSession(true);
codeBean=(Code)session.getAttribute("codeBean");
String code=codeBean.getCode();
if(!code.equals("√")){
String backNews="验证码错误!";
fail(request,response,logname,backNews);
}
else{
if(m==true){
//调用登录成功的方法:
success(request,response,logname,password);
RequestDispatcher dispatcher=request.getRequestDispatcher("/login_sucess.jsp");//转发
dispatcher.forward(request,response);
}
else{
String backNews="您输入的用户名不存在,或密码不般配";
//调用登录失败的方法:
fail(request,response,logname,backNews);
}
}
}
else{
String backNews="请输入用户名和密码";
fail(request,response,logname,backNews);
}
con.close();
}
catch(SQLException exp){
String backNews=""+exp;
fail(request,response,logname,backNews);
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
doPost(request,response);
}
public void success(HttpServletRequest request,HttpServletResponse response,String logname,String password) {
Login loginBean=null;
HttpSession session=request.getSession(true);
try{ loginBean=(Login)session.getAttribute("loginBean");
if(loginBean==null){
loginBean=new Login(); //创建新的数据模型
session.setAttribute("loginBean",loginBean);
loginBean=(Login)session.getAttribute("loginBean");
}
String name =loginBean.getLogname();
if(name.equals(logname)) {
loginBean.setBackNews(logname+"已经登录了");
loginBean.setLogname(logname);
}
else { //数据模型存储新的登录用户
loginBean.setBackNews(logname+"登录成功");
loginBean.setLogname(logname);
}
}
catch(Exception ee){
loginBean=new Login();
session.setAttribute("loginBean",loginBean);
loginBean.setBackNews(logname+"登录成功");
loginBean.setLogname(logname);
}
}
public void fail(HttpServletRequest request,HttpServletResponse response,String logname,String backNews) {
response.setContentType("text/html;charset=GB2312");
try {
PrintWriter out=response.getWriter();
out.println("<html><body>");
out.println("<h2>"+logname+"登录反馈结果<br>"+backNews+"</h2>") ;
out.println("返回登录页面或首页<br>");
out.println("<a href =login.jsp>登录页面</a>");
out.println("<br><a href =shouye.jsp>首页</a>");
out.println("</body></html>");
}
catch(IOException exp){}
}
}
package mybean.data;
import java.util.*;
import java.util.Date;
public class Login {
private String logname="",
backNews="",
password;
public void setLogname(String logname){
this.logname = logname;
}
public String getLogname(){
return logname;
}
public void setPassword(String password){
this.password = password;
}
public String getPassword(){
return password;
}
public void setBackNews(String s) {
backNews = s;
}
public String getBackNews(){
return backNews;
}
}
package mybean.data;
public class Code {
String code="";
public void setCode(String code){
this.code=code;
}
public String getCode(){
return code;
}
}
package net.amag.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Vector;
public class Paging {
/**
* 分页
* @author Etwo
*/
/*
* 分页要素:
* 1、首页first
* 2、最后一页last
* 3、页总数pageCount
* 4、总共显示的数据条数rowCount
* 5、每页显示的数据条数pageRowCount
* 6、当前页curPage
* 7、得到的数据data
*/
/**
* 1、首页first
*/
private int first;
/**
* 2、最后一页last
*/
private int last;
/**
* 3、页总数pageCount
*/
private int pageCount;
/**
* 4、总共显示的数据条数rowCount
*/
private int rowCount;
/**
* 5、每页显示的数据条数pageRowCount
*/
private int pageRowCount;
/**
* 6、当前页curPage
*/
private int curPage;
/**
* 7、得到的数据data
*/
private Collection data;
/**
* 默认显示10条数据
*/
public Paging(Collection data, int curPage) {
this.data = data;
this.curPage = curPage;
this.pageRowCount = 10;
this.rowCount = data.size();
this.pageCount = (int)Math.ceil((double)this.rowCount / (double)this.pageRowCount);
}
/**
* 自行设置每页显示的条数
*/
public Paging(Collection data, int curPage, int pageRowCount) {
this.data = data;
this.curPage = curPage;
this.pageRowCount = pageRowCount;
this.rowCount = data.size();
this.pageCount = (int)Math.ceil((double)this.rowCount / (double)this.pageRowCount);
}
/**
* 首页取得
* @return
*/
public int getFirst() {
return this.first = 1;
}
/**
* 最后一页取得
* @return
*/
public int getLast() {
return this.last = this.pageCount;
}
/**
* 上一页
* @return
*/
public int previous() {
return (this.curPage > 1) ? this.curPage - 1 : 1;
}
/**
* 下一页
* @return
*/
public int next() {
return (this.curPage < this.pageCount) ? this.curPage + 1 : this.pageCount;
}
/**
* 判断是否是首页
* @return
*/
public boolean isFirst() {
return (this.curPage == 1) ? true : false;
}
/**
* 判断是否是最后一页
* @return
*/
public boolean isLast() {
return (this.curPage == this.pageCount) ? true : false;
}
/**
* 当前要显示的数据取得
* @return
*/
public Collection getData() {
Collection curData = null;
if(data != null) {
//定义每一页开始到最后的显示的行数
int start, end;
start = (this.curPage - 1) * this.pageRowCount;
//判断当前显示的数据是否足以显示一整页
if(start + this.pageRowCount > this.rowCount) {
end = this.rowCount;
} else {
end = start + this.pageRowCount;
}
ArrayList arrayData = null;
Vector vectorData = null;
ArrayList arrayCurData = new ArrayList();
Vector vectorCurData = new Vector();
boolean isArrayData = true;
//判断是属于哪一种集合
if(data instanceof ArrayList) {
arrayData = (ArrayList)data;
isArrayData = true;
} else if(data instanceof Vector) {
vectorData = (Vector)data;
isArrayData = false;
}
//循环得到每一页的数据
for(int i = start; i < end; i++) {
if(isArrayData) {
arrayCurData.add(arrayData.get(i));
} else {
vectorCurData.add(vectorData.get(i));
}
}
if(isArrayData) {
curData = arrayCurData;
} else {
curData = vectorCurData;
}
}
return curData;
}
/**
* 客户端显示的工具条
*/
public String getToolBar(String url) {
String str, temp;
//用于判断url中是否存在?
if(url.indexOf("?") == -1) {
temp = "?";
} else {
temp = "&";
}
str = "
";
str += "";
str += "";
//判断是否是首页
if(isFirst()) {
str += "首页 上一页 ";
} else {
str += "首页 ";
str += "上一页 ";
}
//判断是否是最后一页
if(isLast()) {
str += "下一页 尾页 ";
} else {
str += "下一页 ";
str += "尾页 ";
}
str += " 共" + this.rowCount + "条记录 ";
str += " 转到";
for(int i = 1; i <= this.pageCount; i++) {
//判断是否是当前页,若是,则默认为选中当前页
if(i == curPage)
str += "第" + i + "页";
else
str += "第" + i + "页";
}
str += "
";
return str;
}
}
/**
* 文件上传提供的三个属性
*/
private String uploadFileName;//文件名称
private File upload;//上传文件
private String uploadContentType;//文件类型
public void setUploadFileName(String uploadFileName) {
this.uploadFileName = uploadFileName;
}
public void setUpload(File upload) {
this.upload = upload;
}
public void setUploadContentType(String uploadContentType) {
this.uploadContentType = uploadContentType;
}
package com.itheima.crm.utils;
import java.util.UUID;
/**
* 文件上传的工具类
* @author tycoon
*
*/
public class UploadUtils {
/**
* 解决目录下文件名重复的问题了
* @param fileName
* @return
*/
public static String getUuidFileName(String fileName){
int idx=fileName.lastIndexOf(".");//aa.txt
String extions=fileName.substring(idx);
return UUID.randomUUID().toString().replace("-", "");
}
/**
* 目录分离的方法
*/
public static String getPath(String uuidFileName){
int code1=uuidFileName.hashCode();
int d1=code1 & 0xf;//作为一级目录
int code2=code1>>>4;
int d2=code2 & 0xf;//作为二级目录
return "/"+d1+"/"+d2;
}
}
public String save() throws IOException{
//上传图片
if(upload!=null){
//文件上传
//设置文件上传的路径
String path="C:/upload";
//一个目录下存放相同的文件名:随机文件名
String uuidFileName=UploadUtils.getUuidFileName(uploadFileName);
//一个目录下存放的文件过多:目录分离
String realPath=UploadUtils.getPath(uuidFileName);
//创建目录
String url=path+realPath;
File file=new File(url);
if(!file.exists()){
file.mkdirs();
}
//文件上传
File dictFile=new File(url+"/"+uuidFileName);
FileUtils.copyFile(upload, dictFile);
}
}
更多推荐
springboot项目:家庭整理服务管理系统39774(java+VUE+Mybatis+Maven+Mysql)
发布评论