日志能打印sql
pom.xml
4.0.0
com.huawei
welink
0.0.1
jar
welink
welink kylin project for Spring Boot
org.springframework.boot
spring-boot-starter-parent
2.0.5.RELEASE
UTF-8
UTF-8
1.8
org.mybatis.spring.boot
mybatis-spring-boot-starter
1.2.0
org.springframework.boot
spring-boot-starter
org.springframework.boot
spring-boot-starter-web
com.google.code.gson
gson
2.6.2
com.alibaba
fastjson
1.2.38
jar
com.huaban
jieba-analysis
1.0.2
mysql
mysql-connector-java
5.1.39
junit
junit
4.12
test
jar
org.springframework.boot
spring-boot-starter-thymeleaf
org.apache.maven.plugins
maven-jar-plugin
2.3.2
true
lib/
com.welink.WeApplication
org.apache.maven.plugins
maven-dependency-plugin
2.4
copy
install
copy-dependencies
${project.build.directory}/lib
一、java部分
1.main
com.welink\WeApplication.java
package com.welink;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class WeApplication {
public static void main(String[] args) {
SpringApplication.run(WeApplication.class, args);
}
}
2.controller
com.welink.controller\RoleController.java
package com.welink.controller;
import com.alibaba.fastjson.JSON;
import com.welink.domain.ERole;
import com.welink.service.ERoleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.*;
@Controller
public class RoleController {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private ERoleService eRoleService;
@GetMapping("/ERoleIndex")
public String eroleIndex(Model model) throws IOException {
List eRoles = eRoleService.getAllERoles();
logger.debug("eRoles:" +eRoles);
model.addAttribute("eRoles", eRoles);
return "usrIndex";
}
@RequestMapping(value = "/incERole1", method = RequestMethod.POST)
public String incERoleByEmployeeNos( String employee_nos, int model_id, Model model) {
logger.debug("employee_nos: " + employee_nos);
logger.debug("model_id: " + model_id);
List msg = new ArrayList<>();
List eRoles = new ArrayList();
String[] ws = employee_nos.split("\\|");
Date dt = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
int count = 0;
try {
for (String employee_no : ws) {
System.out.println("employee_no: " + employee_no);
employee_no = StringUtils.trimAllWhitespace(employee_no);
if (!StringUtils.isEmpty(employee_no)) {
ERole user = new ERole(employee_no , model_id, sdf.format(dt));
eRoles.add(user);
}
}
eRoleService.updateOrInsertERole(eRoles);
if (eRoles.size() > 0) msg.add("添加成功!");
count++;
} catch (Exception e) {
e.printStackTrace();
}
if (count == 0) msg.add("添加失败!");
model.addAttribute("messages", msg);
return "uploadMessage";
}
@RequestMapping(value = "/incERole2", method = RequestMethod.POST)
public String incERoleByModel_Ids( String employee_no, String model_ids, Model model) {
logger.debug("employee_no: " + employee_no);
logger.debug("model_ids: " + model_ids);
List msg = new ArrayList<>();
List eRoles = new ArrayList();
String[] ws = model_ids.split("\\|");
Date dt = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
int count = 0;
try {
for (String model_id : ws) {
System.out.println("employee_no: " + employee_no);
employee_no = StringUtils.trimAllWhitespace(employee_no);
if (!StringUtils.isEmpty(employee_no)) {
ERole user = new ERole(employee_no , Integer.valueOf(model_id), sdf.format(dt));
eRoles.add(user);
}
}
eRoleService.updateOrInsertERole(eRoles);
if (eRoles.size() > 0) msg.add("添加成功!");
count++;
} catch (Exception e) {
e.printStackTrace();
}
if (count == 0) msg.add("添加失败!");
model.addAttribute("messages", msg);
return "uploadMessage";
}
@RequestMapping(value = "/delERole", method = RequestMethod.POST)
public void delERole( String employee_no,int model_id, Model model, HttpServletResponse rep) {
System.out.println("employee_no: "+employee_no);
PrintWriter out = null;
try {
eRoleService.deleteERoleById(new ERole(employee_no , model_id, null));
rep.setCharacterEncoding("utf-8");
out = rep.getWriter();
out.write("success!!! delete employee_no : " + employee_no);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (out != null) {
out.close();
}
}
}
@RequestMapping("/showERoles")
public void showERoles( Model model, HttpServletResponse rep) {
System.out.println("-----------showERoles------------");
PrintWriter out = null;
try {
List eRoles = eRoleService.getAllERoles();
Map eRolesMap = new HashMap();
for(ERole eRole: eRoles){
eRolesMap.put(eRole.getEmployee_no(), eRole.getModel_id());
}
rep.setCharacterEncoding("utf-8");
out = rep.getWriter();
out.write(JSON.toJSONString(eRolesMap));
} catch (Exception e) {
e.printStackTrace();
} finally {
if (out != null) {
out.close();
}
}
}
}
3.service
com.welink.service\ERoleService.java
package com.welink.service;
import com.welink.domain.ERole;
import com.welink.domain.WordDict;
import java.util.List;
public interface ERoleService {
void updateOrInsertERole(List eRoles);
List getAllERoles();
void deleteERoleById(ERole eRole);
}
com.welink.service.impl\ERoleServiceImpl.java
package com.welink.service.impl;
import com.welink.dao.ERoleDao;
import com.welink.domain.ERole;
import com.welink.service.ERoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class ERoleServiceImpl implements ERoleService {
@Autowired
private ERoleDao eRoleDao;
@Override
public void updateOrInsertERole(List eRoles) {
eRoleDao.updateOrInsertERole(eRoles);
}
@Override
public List getAllERoles() {
return eRoleDao.getAllERoles();
}
@Override
public void deleteERoleById(ERole eRole) {
eRoleDao.deleteERoleById(eRole);
}
}
4.dao
com.welink.dao\ERoleDao.java
package com.welink.dao;
import com.welink.domain.ERole;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface ERoleDao {
void updateOrInsertERole(@Param("eRoleList") List eRoles);
List getAllERoles();
void deleteERoleById(@Param("eRole") ERole eRole);
}
二、配置文件
1.resources\application.properties
server.port=8081
spring.datasource.url=jdbc:mysql://localhost:3306/welink?useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
## Mybatis 配置
mybatis.typeAliasesPackage=com.welink.domain
mybatis.mapperLocations=classpath:mapper/*.xml
2.resources\ERoleMapper.xml
replace into t_employee_role
(employee_no, model_id, tdate)
VALUES
( #{it.employee_no},#{it.model_id},#{it.tdate})
delete from t_employee_role where employee_no=#{eRole.employee_no} and model_id=#{eRole.model_id}
3.resources\logback-spring.xml
logback
%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n
${log.path}/logback.%d{yyyy-MM-dd}.log
%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n
三、mysql
mysql:
service mysqld start 2>&1 & stop
mysql -u root
为数据库设置密码
set password for root@localhost = password('123456') ;
mysql -u root -p
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql:
cd C:\wamp\bin\mysql\mysql5.7.14\bin
mysql -u root -p
change password:
mysql -u root mysql
另开一个dos窗口输入mysql -uroot -p,然后无需输入密码直接enter键进入;
use mysql;
set password for root@localhost = password('root123') ;
update mysql.user set authentication_string=password('root123') where user='root';
flush privileges;
quit;
1.新建用户
1.1 登录MYSQL:
@>mysql -u root -p
@>密码
1.2 创建用户:
CREATE USER 'gan'@'host' IDENTIFIED BY '123456';
-- use mysql ;
-- insert into mysql.user(Host,User,Password) values("localhost","gan",password("123456"));
2.对建的用户进行授权
-- GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROPON welink.* TO 'gan'@'localhost' IDENTIFIED BY '123456';
mysql> grant all privileges on gan.* to gan@localhost identified by '123456';
3.生效授权,创建完毕
FLUSH PRIVILEGES;
#开启日志记录
mysql>show global variables like '%log%';
mysql>show global variables like '%general%';
mysql>set global slow_query_log_file='/data01/logs/welink/mysql_slowquery.log'; #设置路径
mysql>set global general_log_file='/data01/logs/welink/mysql.log'; #设置路径
set global log_error='/data01/logs/welink/mysql_error.log';
mysql>set global general_log=on; # 开启general log模式
SET GLOBAL general_log = 'ON';
mysql>set global general_log=off; # 关闭general log模式
修改配置文件
/etc/my.cnf
-- create database welink;
CREATE DATABASE IF NOT EXISTS welink DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
use welink;
status;
--工号表:模块权限处理
create table IF NOT EXISTS t_employee_role(
employee_no VARCHAR(30)
,model_id int
,tdate CHAR(10)
,primary key(employee_no, model_id)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
--'yyyy-MM-dd'
insert into t_employee_role values('00188625',1,'2019-06-10');
replace into t_employee_role (employee_no,model_id, tdate)
values ('00188625',1,'2019-06-08'),('00188625',2,'2019-06-10'),('003',1,'2019-06-10');
整体名单1
开发灰度2
上线灰度3
下载权限3
词云自定义词典4
埋码系统5
管理员6
四、测试
http://localhost:8081/showERoles
终于明白,有些路,只能一个人走。
那些邀约好同行的人,一起相伴雨季,走过年华,但有一天终究会在某个渡口离散。
红尘陌上,独自行走,绿萝拂过衣襟,青云打湿诺言。
山和水可以两两相忘,日与月可以毫无瓜葛。那时候,只一个人的浮世清欢,一个人的细水长流。
–原作者:白落梅 《你若安好,便是晴天》