创建maven项目

pop.xml

<?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 http://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.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.loaderman</groupId>
<artifactId>crm</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>crm</name>
<description>Demo project for Spring Boot</description> <properties>
<java.version>1.8</java.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> <!-- 数据库连接池 -->
<!-- alibaba的druid数据库连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>

resources下创建

application.yml

spring:
thymeleaf:
mode: HTML5
encoding: UTF-8
sourceType: text/html; charset=utf-8
type: text/html; charset=utf-8
# 开发禁用缓存
cache: false
datasource:
druid:
#监控统计拦截的filters
filters: stat
driver-class-name: com.mysql.jdbc.Driver
#基本属性
url: jdbc:mysql://localhost:3306/infos
username: root
password: root
#配置初始化大小/最小/最大
initial-size: 5
min-idle: 5
max-active: 20
#获取连接等待超时时间
max-wait: 60000
#间隔多久进行一次检测,检测需要关闭的空闲连接
time-between-eviction-runs-millis: 60000
#一个连接在池中最小生存的时间
min-evictable-idle-time-millis: 300000 test-while-idle: true
test-on-borrow: false
test-on-return: false
#打开PSCache,并指定每个连接上PSCache的大小。oracle设为true,mysql设为false。分库分表较多推荐设置为false
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
hikari:
connection-timeout: 60000
mvc:
view:
prefix: /WEB-INF/
suffix: .jsp
resources:
add-mappings: false
jackson:
serialization:
write-dates-as-timestamps: true
mybatis:
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.loaderman.crm.entity
configuration:
use-column-label: true
use-generated-keys: true
map-underscore-to-camel-case: true
# spring-boot默认打印输出info级别以上的,可在此处修改输出级别
logging:
config: classpath:logback-spring.xml
path: /var/log
debug: true

logback-spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration> <!-- 控制台输出 -->
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date [%thread] %-5level %logger{80} - %msg%n</pattern>
</encoder>
</appender> <!-- 时间滚动输出 level为 INFO 日志 -->
<appender name="file-info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY </onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>./logs/info.%d{yyyy-MM-dd}.log</FileNamePattern>
<MaxHistory>30</MaxHistory>
</rollingPolicy>
<encoder>
<pattern>%date [%thread] %-5level %logger{80} - %msg%n</pattern>
</encoder>
</appender> <!-- 时间滚动输出 level为 DEBUG 日志 -->
<appender name="file-debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>DEBUG</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY </onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>./logs/debug.%d{yyyy-MM-dd}.log</FileNamePattern>
<MaxHistory>30</MaxHistory>
</rollingPolicy>
<encoder>
<pattern>%date [%thread] %-5level %logger{80} - %msg%n</pattern>
</encoder>
</appender> <!-- 时间滚动输出 level为 ERROR 日志 -->
<appender name="file—error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY </onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>./logs/error.%d{yyyy-MM-dd}.log</FileNamePattern>
<MaxHistory>30</MaxHistory>
</rollingPolicy>
<encoder>
<pattern>%date [%thread] %-5level %logger{80} - %msg%n</pattern>
</encoder>
</appender> <logger name="org.apache.ibatis" level="INFO"/>
<logger name="java.sql.Connection" level="debug" />
<logger name="java.sql.Statement" level="debug" />
<logger name="java.sql.PreparedStatement" level="debug" /> <root level="info">
<appender-ref ref="stdout" />
<appender-ref ref="file-info" />
</root>
</configuration>

创建用户MyBatis 的 Mapper

userMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!-- namespace属性是名称空间,必须唯一 -->
<mapper namespace="com.loaderman.crm.dao.UserDao"> <update id="modifyUser" parameterType="com.loaderman.crm.entity.User">
update t_user set id=#{id},name=#{name},telephone=#{telephone},age=#{age},telephone=#{telephone},idCard=#{idCard},address=#{address},weixin=#{weixin},qq=#{qq},email=#{email},job=#{job},area=#{area},grade=#{grade},remark=#{remark} where id=#{id} </update> <delete id="delUser" parameterType="com.loaderman.crm.entity.User">
delete from t_user where id = #{id}
</delete>
<insert id="addUser" parameterType="com.loaderman.crm.entity.User" >
insert into t_user (name,sex,age,telephone,idCard,address,weixin,qq,email,job,area,grade,remark) values(#{name},#{sex},#{age},#{telephone},#{idCard},#{address},#{weixin},#{qq},#{email},#{job},#{area},#{grade},#{remark}) </insert>
<select id="getUserByName" parameterType="String" resultType="com.loaderman.crm.entity.User">
select * from t_user where name=#{name}
</select >
<select id="getUserMoreInfo" parameterType="com.loaderman.crm.entity.User" resultType="com.loaderman.crm.entity.User">
select * from t_user where id=#{id}
</select>
<select id="findUser" parameterType="com.loaderman.crm.entity.User" resultType="com.loaderman.crm.entity.User">
select * from t_user where id=#{id}
</select> <select id="getAllUser" resultType="com.loaderman.crm.entity.User">
select * from t_user
</select > </mapper>

User实体类

package com.loaderman.crm.entity;

import org.springframework.stereotype.Service;

import java.io.Serializable;

@Service
public class User {
private int id;
private String name; private String sex;
private String age;
private String telephone;
private String idCard;
private String address;
private String weixin ;
private String qq;
private String email;
private String job;
private String grade; public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getGrade() {
return grade;
} public void setGrade(String grade) {
this.grade = grade;
} public String getArea() {
return area;
} public void setArea(String area) {
this.area = area;
} private String remark;
private String area;
public User() {
} public String getAge() {
return age;
} public void setAge(String age) {
this.age = age;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getSex() {
return sex;
} public void setSex(String sex) {
this.sex = sex;
} public String getTelephone() {
return telephone;
} public void setTelephone(String telephone) {
this.telephone = telephone;
} public String getIdCard() {
return idCard;
} public void setIdCard(String idCard) {
this.idCard = idCard;
} public String getAddress() {
return address;
} public void setAddress(String address) {
this.address = address;
} public String getWeixin() {
return weixin;
} public void setWeixin(String weixin) {
this.weixin = weixin;
} public String getQq() {
return qq;
} public void setQq(String qq) {
this.qq = qq;
} public String getEmail() {
return email;
} public void setEmail(String email) {
this.email = email;
} public String getJob() {
return job;
} public void setJob(String job) {
this.job = job;
} public String getRemark() {
return remark;
} public void setRemark(String remark) {
this.remark = remark;
} @Override
public String toString() {
return "User{" +
"name='" + name + '\'' +
", sex='" + sex + '\'' +
", age='" + age + '\'' +
", telephone='" + telephone + '\'' +
", idCard='" + idCard + '\'' +
", address='" + address + '\'' +
", weixin='" + weixin + '\'' +
", qq='" + qq + '\'' +
", email='" + email + '\'' +
", job='" + job + '\'' +
", grade='" + grade + '\'' +
", remark='" + remark + '\'' +
", area='" + area + '\'' +
'}';
}
}

dao层

package com.loaderman.crm.dao;

import com.loaderman.crm.entity.User;

import java.util.List;

/*
*
* @ class description:对客户表的操作接口
*
*/
public interface UserDao {
//获取所有客户信息
public List<User> getAllUser();
//获取指定客户信息
public User getUserMoreInfo(User user);
public List<User> getUserByName(String name);
//添加客户
public int addUser(User user);
//删除客户
public int delUser(User user);
//修改客户
public int modifyUser(User user);
//查找指定的客户存在不存在
public boolean findUser(User user); }

service层

package com.loaderman.crm.service;

import com.loaderman.crm.entity.User;

import java.util.List;

public interface UserService {
public List<User> getAllUser();
public User getUserMoreInfo(User user);
public List<User> getUserByName(String name);
public int addUser(User user);
public int delUser(User user);
public int modifyUser(User user);
public boolean findUser(User user);
}
package com.loaderman.crm.service.impl;

import com.loaderman.crm.entity.User;
import com.loaderman.crm.dao.UserDao;
import com.loaderman.crm.service.UserService;
import org.springframework.stereotype.Service; import javax.annotation.Resource;
import java.util.List; /*
*
* @ class description:操作客户
*
*/
@Service
public class UserServiceimp implements UserService { @Resource
private UserDao userDao;
@Override
public List<User> getAllUser() {
return userDao.getAllUser();
} @Override
public User getUserMoreInfo(User user) {
return userDao.getUserMoreInfo(user);
} @Override
public List<User> getUserByName(String name) {
return userDao.getUserByName(name);
} @Override
public int addUser(User user) {
return userDao.addUser(user);
} @Override
public int delUser(User user) {
return userDao.delUser(user);
} @Override
public int modifyUser(User user) {
return userDao.modifyUser(user);
} public boolean findUser(User user) {
return userDao.findUser(user); } }

控制层

package com.loaderman.crm.controller;

import com.loaderman.crm.entity.Account;
import com.loaderman.crm.entity.User;
import com.loaderman.crm.service.impl.UserServiceimp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List; @Controller
public class UserController {
@Resource
private UserServiceimp userService;
@Autowired
private User user; @RequestMapping(value = "/getUserMoreInfo")
public String getUserMoreInfo(Model model, @RequestParam(required = true) int id) {
user.setId(id);
User user1 = userService.getUserMoreInfo(user);
model.addAttribute("user", user1);
return "/userDetail";
} @RequestMapping(value = "/adduser")
public String adduser() {
return "/addUser";
} @RequestMapping(value = "/addUser", method = RequestMethod.GET)
public void addUser(HttpServletResponse response, @ModelAttribute User user, @RequestParam(required = true) String opr, @RequestParam(required = false) Integer id) {
int n = 0;
if (opr.equals("addUser")) {
n = userService.addUser(user);
} else if (opr.equals("modifyUser")) {
user.setId(id);
n = userService.modifyUser(user);
}
if (n > 0) {
try {
response.sendRedirect("/getUserList");
} catch (IOException e) {
e.printStackTrace();
}
} else {
try {
response.sendRedirect("/addUser");
} catch (IOException e) {
e.printStackTrace();
}
}
} @RequestMapping(value = "/delUser", method = RequestMethod.GET)
public void delUser(@RequestParam(required = true) int id, HttpServletResponse response) {
user.setId(id);
userService.delUser(user);
try {
response.sendRedirect("/getUserList");
} catch (IOException e) {
e.printStackTrace();
}
} @RequestMapping(value = "/getUserList")
public String getUserList(HttpServletResponse response, @RequestParam(required = false) String name, ModelMap model, HttpServletRequest request, Model model1) throws IOException {
Account account = (Account) request.getSession().getAttribute("account");
System.out.println(account); if (name != null && (!name.isEmpty())) { List<User> list = userService.getUserByName(name);
model.addAttribute("list", list);
} else {
List<User> list = userService.getAllUser();
model.addAttribute("list", list);
}
return "/getUserList";
} @RequestMapping(value = "/modifyUser", method = RequestMethod.GET)
public String modifyUser(@RequestParam(required = true) int id, Model model) {
user.setId(id);
User user1 = userService.getUserMoreInfo(user);
model.addAttribute("user", user1);
return "/modifyUser";
}
}

web 页面演示,具体查看demo

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<title>Home</title>
<link href="css/common.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div align="right" > 欢迎你 <td th:text="${session.account.username} "></td><a th:href="@{/}"> 退出</a> </div> <h2>客户信息列表</h2>
<div align="right" style="margin-right: 50px">
<form action="/getUserList" style="text-align: right" >
<tr>
<input type="text" placeholder="请输入要查询姓名" name="name"></td>
</tr>
<td ><input type="submit" value="查询"></td>
</tr>
</form>
<p>
<a th:href="@{/adduser}" ><input type="button" value="添加客户"></a>
<a href="/getPolicyList"><input type="button" value="保单列表"></a>
</p> </div> <table>
<tr>
<td class="listTable">编号</td>
<td class="listTable">姓名</td>
<td class="listTable">性别</td>
<td class="listTable">年龄</td>
<td class="listTable">电话</td>
<td class="listTable">等级</td>
<td class="listTable">身份证</td>
<td class="listTable">地区</td>
<td class="listTable">地址</td>
<td class="listTable">微信</td>
<td class="listTable">QQ</td>
<td class="listTable">邮箱</td>
<td class="listTable">职业</td>
<td id="profile">备注</td>
<td id="operate">操作</td>
</tr> </td>
<!--/*@thymesVar id="list" type="java"*/-->
<li th:each = "user, iterStat : ${list} " >
<tr>
<td th:text="${iterStat.count}">
</td>
<td th:text="${user.getName()}">
</td>
<td th:text="${user.getSex()}">
</td>
<td th:text="${user.getAge()}">
</td>
<td th:text="${user.getTelephone()}">
</td>
<td th:text="${user.getGrade()}">
</td>
<td th:text="${user.getIdCard()}">
</td>
<td th:text="${user.getArea()}">${
</td>
<td th:text="${user.getAddress()}">
</td>
<td th:text="${user.getWeixin()}">
</td>
<td th:text="${user.getQq()}">$
</td >
<td th:text="${user.getEmail()}">$
</td>
<td th:text="${user.getJob()}">
</td>
<td th:text="${user.getRemark()}">
</td>
<td><a th:href="@{/getUserMoreInfo(id = ${user.getId()})}" >查看&nbsp;&nbsp;</a>
<a th:href="@{/modifyUser(id = ${user.getId()})} ">修改&nbsp;&nbsp;</a>
<a th:href="@{/delUser(id = ${ user.getId()})} "
onclick="return check()">删除&nbsp;&nbsp;</a></td>
</tr> </li> </table> </body>
</html>

点击 源码下载


简易的CRM系统案例SpringBoot + thymeleaf + MySQL + MyBatis版本的更多相关文章

  1. 简易的CRM系统案例之SpringMVC+JSP+MySQL+myBatis框架版本

    主要对上一版DAO框架的替换hibernate变成myBatis 简易的CRM系统案例之SpringMVC+JSP+MySQL+hibernate框架版本 src/mybatis.xml <?x ...

  2. 简易的CRM系统案例之SpringMVC+JSP+MySQL+hibernate框架版本

    继续对上一版本进行改版,变成SpringMVC框架 简易的CRM系统案例之易的CRM系统案例之JSP+MySQL+SSH框架版本 src/spring.xml <?xml version=&qu ...

  3. 简易的CRM系统案例之易的CRM系统案例之JSP+MySQL+SSH框架版本

    主要对上一篇hibernate与Spring进行整合改进 简易的CRM系统案例之Struts2+Hibernate3+JSP+MySQL版本 bean-base.xml <?xml versio ...

  4. 简易的CRM系统案例之Struts2&Spring整合+Hibernate3+JSP+MySQL版本

    主要对上一篇Struts2&Spring整合的改造 简易的CRM系统案例之Struts2+Hibernate3+JSP+MySQL版本 src/bean.xml <beans xmlns ...

  5. 简易的CRM系统案例之Struts2+Hibernate3+JSP+MySQL版本

    改造上一版本的DAO层 简易的CRM系统案例之Struts2+JSP+MySQL版本 src文件下hibernate.cfg.xml <!DOCTYPE hibernate-configurat ...

  6. 简易的CRM系统案例之Struts2+JSP+MySQL版本

    对简易的CRM系统案例之Servlet+Jsp+MySQL版本改进 Servlet优化为Struts2 学习 <?xml version="1.0" encoding=&qu ...

  7. 简易的CRM系统案例之Servlet+Jsp+MySQL版本

    数据库配置 datebase.properties driver=com.mysql.jdbc.Driver url=jdbc:mysql://127.0.0.1:3306/infos usernam ...

  8. springboot学习笔记:11.springboot+shiro+mysql+mybatis(通用mapper)+freemarker+ztree+layui实现通用的java后台管理系统(权限管理+用户管理+菜单管理)

    一.前言 经过前10篇文章,我们已经可以快速搭建一个springboot的web项目: 今天,我们在上一节基础上继续集成shiro框架,实现一个可以通用的后台管理系统:包括用户管理,角色管理,菜单管理 ...

  9. 微服务之分布式跟踪系统(springboot+zipkin+mysql)

    通过上一节<微服务之分布式跟踪系统(springboot+zipkin)>我们简单熟悉了zipkin的使用,但是收集的数据都保存在内存中重启后数据丢失,不过zipkin的Storage除了 ...

随机推荐

  1. 使用华为云+GitHub搭建自己的博客

    1.搭建自己博客首先创建GitHub账号 在GitHub官网上创建一个账号:   我的账号地址是 : https://github.com/SueKayTian 2.GitHub账号创建好之后,客户端 ...

  2. 动态规划——python

    1.爬楼梯问题一个人爬楼梯,每次只能爬1个或两个台阶,假设有n个台阶,那么这个人有多少种不同的爬楼梯方法 动态规划的状态转移:第 i 个状态的方案数和第 i-1, i-2时候的状态有关,即:dp[i] ...

  3. 【恐怖的数组模拟】Secret Poems - HihoCoder - 1632

    Secret Poems - HihoCoder - 1632 图一 图二 Following the order indicated by arrows, you can get “THISISAV ...

  4. Centos 安装JDK(最最最最最方便的方法)

    1.下载rpm安装文件,链接:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 2 ...

  5. spring security控制session

    spring security控制session本文给你描述在spring security中如何控制http session.包括session超时.启用并发session以及其他高级安全配置. 创 ...

  6. LOJ P10117 简单题 题解

    每日一题 day15 打卡 Analysis 树状数组 用树状数组来维护每个字符变化的次数,如果是偶数就是0,奇数就是1 #include<iostream> #include<cs ...

  7. bzoj 1396/2865: 识别子串 后缀自动机+线段树

    水水的字符串题 ~ #include <map> #include <cstdio> #include <cstring> #include <algorit ...

  8. NetworkX系列教程(10)-算法之二:最小/大生成树问题

    小书匠 Graph 图论  重头戏部分来了,写到这里我感觉得仔细认真点了,可能在NetworkX中,实现某些算法就一句话的事,但是这个算法是做什么的,用在什么地方,原理是怎么样的,不清除,所以,我决定 ...

  9. 如何将web转化成应用程序?

    nativefier  最近无意中发现这个开源项目,Nativefier,看着它的项目介绍,以及1w+ 的 Star,感觉自己错过了一个世纪. 介绍 Nativefier是一个命令行工具,可以轻松地为 ...

  10. PCIe - 周扒皮,扒扒TLP层

    来来来,南来的,北往的,看一看,瞧一瞧,不好用不要钱,快来看呐. 来,客观,摘抄几篇PCIe文章给您看看, 1. http://xillybus.com/tutorials/pci-express-d ...