文档信息整理

This commit is contained in:
fxb 2018-11-10 17:10:02 +08:00
parent 39bdf37640
commit cec89b67a6
20 changed files with 440 additions and 382 deletions

View File

@ -1,5 +1,5 @@
[id]: 2018-11-09 [id]: 2018-11-09
[type]: 软件使用 [type]: 软件
[tag]: linux,mongodb [tag]: linux,mongodb
  首先到官网下载安装包,官网地址如下:[点击跳转](https://www.mongodb.com/download-center/community),选中合适的版本,下面会出现下载链接,然后使用 wget url 下载到当前文件夹下。mongodb 4.04 ubuntu18.04 64 下载命令如下:   首先到官网下载安装包,官网地址如下:[点击跳转](https://www.mongodb.com/download-center/community),选中合适的版本,下面会出现下载链接,然后使用 wget url 下载到当前文件夹下。mongodb 4.04 ubuntu18.04 64 下载命令如下:

View File

@ -1,4 +1,7 @@
[id]: 62ee59a0d6c111e8aa858b6a40460626 [id]:2018-08-12_1
[type]:javaee
[tag]:java,spring
  spring是为了解决企业级应用开发的复杂性而创建的spring最根本的使命是简化Java开发。为降低开发复杂性有以下四种关键策略。   spring是为了解决企业级应用开发的复杂性而创建的spring最根本的使命是简化Java开发。为降低开发复杂性有以下四种关键策略。
- 基于POJO的轻量级和最小侵入性编程 - 基于POJO的轻量级和最小侵入性编程

View File

@ -1,4 +1,7 @@
[id]: 6d17f940d6c111e8aa858b6a40460626 [id]:2018-08-12_2
[type]:javaee
[tag]:java,spring
## 一、自动装配 ## 一、自动装配
### 1、四种类型的自动装配 ### 1、四种类型的自动装配

View File

@ -1,6 +1,10 @@
[id]: 6f135410d6c111e8aa858b6a40460626 [id]:2018-08-12_3
[type]:javaee
[tag]:java,spring
## 一.面向切面编程 ## 一.面向切面编程
  Spring的基础是IOC和AOP前面两节对IOC和DI做了简单总结这里再对AOP进行一个学习总结Spring基础就算有一个初步了解了。   Spring的基础是IOC和AOP前面两节对IOC和DI做了简单总结这里再对AOP进行一个学习总结Spring基础就算有一个初步了解了。
  在软件开发中,我们可能需要一些跟业务无关但是又必须做的东西,比如日志,事务等,这些分布于应用中多处的功能被称为横切关注点,通常横切关注点从概念上是与应用的业务逻辑相分离的。如何将这些横切关注点与业务逻辑在代码层面进行分离,是面向切面编程(**AOP**)所要解决的。   在软件开发中,我们可能需要一些跟业务无关但是又必须做的东西,比如日志,事务等,这些分布于应用中多处的功能被称为横切关注点,通常横切关注点从概念上是与应用的业务逻辑相分离的。如何将这些横切关注点与业务逻辑在代码层面进行分离,是面向切面编程(**AOP**)所要解决的。

View File

@ -1,4 +1,6 @@
[id]: 729b1b40d6c111e8aa858b6a40460626 [id]:2018-08-13
[type]:javaee
[tag]:java,spring,springboot
  前面的博客有说到spring boot搭建见另一篇博文其实那篇博文还没写现在来填个坑。我们使用spring initializr来构建idea和eclipse都支持这种方式构建过程类似这里以idea为例详细记录构建过程。   前面的博客有说到spring boot搭建见另一篇博文其实那篇博文还没写现在来填个坑。我们使用spring initializr来构建idea和eclipse都支持这种方式构建过程类似这里以idea为例详细记录构建过程。
###1.选择spring initializr ###1.选择spring initializr

View File

@ -1,4 +1,7 @@
[id]: 7a77bda0d6c111e8aa858b6a40460626 [id]:2018-08-20
[type]:javaee
[tag]:java,spring,springsecurity,scurity
**说明springboot版本2.0.3** **说明springboot版本2.0.3**
##一、 介绍 ##一、 介绍

View File

@ -1,4 +1,7 @@
[id]: 7c140880d6c111e8aa858b6a40460626 [id]:2018-08-21
[type]:javaee
[tag]:java,spring,springsecurity,scurity
  紧接着上一篇上一篇中登录验证都由security帮助我们完成了如果我们想要增加一个验证码登录或者其它的自定义校验就没办法了因此这一篇讲解如何实现这个功能。   紧接着上一篇上一篇中登录验证都由security帮助我们完成了如果我们想要增加一个验证码登录或者其它的自定义校验就没办法了因此这一篇讲解如何实现这个功能。
##一、 实现自定义登录校验类 ##一、 实现自定义登录校验类

View File

@ -1,4 +1,7 @@
[id]: 7cfc1e90d6c111e8aa858b6a40460626 [id]:2018-08-22
[type]:javaee
[tag]:java,spring,springsecurity,scurity
  这篇讲解如何自定义鉴权过程实现根据数据库查询出的url和method是否匹配当前请求的url和method来决定有没有权限。security鉴权过程如下   这篇讲解如何自定义鉴权过程实现根据数据库查询出的url和method是否匹配当前请求的url和method来决定有没有权限。security鉴权过程如下
![鉴权流程](./picFolder/pic2.png) ![鉴权流程](./picFolder/pic2.png)

View File

@ -1,4 +1,7 @@
[id]: 7e229d30d6c111e8aa858b6a40460626 [id]:2018-08-25
[type]:javaee
[tag]:java,spring,websocket
<h3 id="#一、背景">一、背景</h3> <h3 id="#一、背景">一、背景</h3>
&emsp;&emsp;我们都知道http协议只能浏览器单方面向服务器发起请求获得响应服务器不能主动向浏览器推送消息。想要实现浏览器的主动推送有两种主流实现方式 &emsp;&emsp;我们都知道http协议只能浏览器单方面向服务器发起请求获得响应服务器不能主动向浏览器推送消息。想要实现浏览器的主动推送有两种主流实现方式

View File

@ -1,363 +1,366 @@
[id]: 818f3b40d6c111e8aa858b6a40460626 [id]:2018-09-01
## 写在前面 [type]:javaee
[tag]:java,spring,mysql,mybatis,xml
刚毕业的第一份工作是java开发项目中需要用到mybatis特此记录学习过程这只是一个简单demomybatis用法很多不可能全部写出来有更复杂的需求建议查看mybatis的官方中文文档[点击跳转](http://www.mybatis.org/mybatis-3/zh/index.html)。下面时项目环境/版本。
## 写在前面
- 开发工具IDEA
- jdk版本1.8 刚毕业的第一份工作是java开发项目中需要用到mybatis特此记录学习过程这只是一个简单demomybatis用法很多不可能全部写出来有更复杂的需求建议查看mybatis的官方中文文档[点击跳转](http://www.mybatis.org/mybatis-3/zh/index.html)。下面时项目环境/版本。
- springboot版本2.03
- 开发工具IDEA
其他依赖版本见下面pom.xml: - jdk版本1.8
- springboot版本2.03
```xml
<?xml version="1.0" encoding="UTF-8"?> 其他依赖版本见下面pom.xml:
<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"> ```xml
<modelVersion>4.0.0</modelVersion> <?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"
<groupId>com.example</groupId> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<artifactId>mybatis-test</artifactId> <modelVersion>4.0.0</modelVersion>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <groupId>com.example</groupId>
<artifactId>mybatis-test</artifactId>
<name>mybatis-test</name> <version>0.0.1-SNAPSHOT</version>
<description>Demo project for Spring Boot</description> <packaging>jar</packaging>
<parent> <name>mybatis-test</name>
<groupId>org.springframework.boot</groupId> <description>Demo project for Spring Boot</description>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version> <parent>
<relativePath/> <!-- lookup parent from repository --> <groupId>org.springframework.boot</groupId>
</parent> <artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<properties> <relativePath/> <!-- lookup parent from repository -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </parent>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version> <properties>
</properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<dependencies> <java.version>1.8</java.version>
<dependency> </properties>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <dependencies>
</dependency> <dependency>
<dependency> <groupId>org.springframework.boot</groupId>
<groupId>mysql</groupId> <artifactId>spring-boot-starter-web</artifactId>
<artifactId>mysql-connector-java</artifactId> </dependency>
<scope>runtime</scope> <dependency>
</dependency> <groupId>mysql</groupId>
<!--mybatis依赖 --> <artifactId>mysql-connector-java</artifactId>
<dependency> <scope>runtime</scope>
<groupId>org.mybatis.spring.boot</groupId> </dependency>
<artifactId>mybatis-spring-boot-starter</artifactId> <!--mybatis依赖 -->
<version>1.3.2</version> <dependency>
</dependency> <groupId>org.mybatis.spring.boot</groupId>
<!--alibaba连接池依赖--> <artifactId>mybatis-spring-boot-starter</artifactId>
<dependency> <version>1.3.2</version>
<groupId>com.alibaba</groupId> </dependency>
<artifactId>druid-spring-boot-starter</artifactId> <!--alibaba连接池依赖-->
<version>1.1.9</version> <dependency>
</dependency> <groupId>com.alibaba</groupId>
<!--分页依赖--> <artifactId>druid-spring-boot-starter</artifactId>
<dependency> <version>1.1.9</version>
<groupId>com.github.pagehelper</groupId> </dependency>
<artifactId>pagehelper-spring-boot-starter</artifactId> <!--分页依赖-->
<version>1.2.5</version> <dependency>
</dependency> <groupId>com.github.pagehelper</groupId>
<dependency> <artifactId>pagehelper-spring-boot-starter</artifactId>
<groupId>org.springframework.boot</groupId> <version>1.2.5</version>
<artifactId>spring-boot-starter-test</artifactId> </dependency>
<scope>test</scope> <dependency>
</dependency> <groupId>org.springframework.boot</groupId>
</dependencies> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<build> </dependency>
<plugins> </dependencies>
<plugin>
<groupId>org.springframework.boot</groupId> <build>
<artifactId>spring-boot-maven-plugin</artifactId> <plugins>
</plugin> <plugin>
</plugins> <groupId>org.springframework.boot</groupId>
</build> <artifactId>spring-boot-maven-plugin</artifactId>
</project> </plugin>
``` </plugins>
</build>
## 1.创建项目 </project>
```
使用idea中的spring initializr生成maven项目项目命令为mybatis-test选择webmysqlmybatis依赖即可成功。详细过程不赘述如有需要学习springboot创建过程可参考[这篇文章]()。
## 1.创建项目
然后依照上面的pom文件补齐缺少的依赖。接着创建包entityservice和mybatis映射文件夹mapper创建。为了方便配置将application.properties改成application.yml。由于我们时REST接口故不需要static和templates目录。修改完毕后的项目结构如下
使用idea中的spring initializr生成maven项目项目命令为mybatis-test选择webmysqlmybatis依赖即可成功。详细过程不赘述如有需要学习springboot创建过程可参考[这篇文章]()。
![项目结构](./picFolder/pic1.png)
然后依照上面的pom文件补齐缺少的依赖。接着创建包entityservice和mybatis映射文件夹mapper创建。为了方便配置将application.properties改成application.yml。由于我们时REST接口故不需要static和templates目录。修改完毕后的项目结构如下
修改启动类,增加`@MapperScan("com.example.mybatistest.dao") `,以自动扫描dao目录避免每个dao都手动加`@Mapper`注解。代码如下:
![项目结构](./picFolder/pic1.png)
```java
@SpringBootApplication 修改启动类,增加`@MapperScan("com.example.mybatistest.dao") `,以自动扫描dao目录避免每个dao都手动加`@Mapper`注解。代码如下:
@MapperScan("com.example.mybatistest.dao")
public class MybatisTestApplication { ```java
public static void main(String[] args) { @SpringBootApplication
SpringApplication.run(MybatisTestApplication.class, args); @MapperScan("com.example.mybatistest.dao")
} public class MybatisTestApplication {
} public static void main(String[] args) {
``` SpringApplication.run(MybatisTestApplication.class, args);
}
修改application.yml,配置项目,代码如下: }
```
```yml
mybatis: 修改application.yml,配置项目,代码如下:
#对应实体类路径
type-aliases-package: com.example.mybatistest.entity ```yml
#对应mapper映射文件路径 mybatis:
mapper-locations: classpath:mapper/*.xml #对应实体类路径
type-aliases-package: com.example.mybatistest.entity
#pagehelper物理分页配置 #对应mapper映射文件路径
pagehelper: mapper-locations: classpath:mapper/*.xml
helper-dialect: mysql
reasonable: true #pagehelper物理分页配置
support-methods-arguments: true pagehelper:
params: count=countSql helper-dialect: mysql
returnPageInfo: check reasonable: true
support-methods-arguments: true
server: params: count=countSql
port: 8081 returnPageInfo: check
spring: server:
datasource: port: 8081
name: mysqlTest
type: com.alibaba.druid.pool.DruidDataSource spring:
#druid连接池相关配置 datasource:
druid: name: mysqlTest
#监控拦截统计的filters type: com.alibaba.druid.pool.DruidDataSource
filters: stat #druid连接池相关配置
driver-class-name: com.mysql.jdbc.Driver druid:
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=true #监控拦截统计的filters
username: root filters: stat
password: 123456 driver-class-name: com.mysql.jdbc.Driver
#配置初始化大小,最小,最大 url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=true
initial-size: 1 username: root
min-idle: 1 password: 123456
max-active: 20 #配置初始化大小,最小,最大
#获取连接等待超时时间 initial-size: 1
max-wait: 6000 min-idle: 1
#间隔多久检测一次需要关闭的空闲连接 max-active: 20
time-between-eviction-runs-millis: 60000 #获取连接等待超时时间
#一个连接在池中的最小生存时间 max-wait: 6000
min-evictable-idle-time-millis: 300000 #间隔多久检测一次需要关闭的空闲连接
#打开PSCache并指定每个连接上PSCache的大小。oracle设置为truemysql设置为false。分库分表设置较多推荐设置 time-between-eviction-runs-millis: 60000
pool-prepared-statements: false #一个连接在池中的最小生存时间
max-pool-prepared-statement-per-connection-size: 20 min-evictable-idle-time-millis: 300000
http: #打开PSCache并指定每个连接上PSCache的大小。oracle设置为truemysql设置为false。分库分表设置较多推荐设置
encoding: pool-prepared-statements: false
charset: utf-8 max-pool-prepared-statement-per-connection-size: 20
enabled: true http:
``` encoding:
charset: utf-8
## 2.编写代码 enabled: true
```
首先创建数据表sql语句如下
## 2.编写代码
```sql
CREATE TABLE `user` ( 首先创建数据表sql语句如下
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL, ```sql
`age` tinyint(4) NOT NULL DEFAULT '0', CREATE TABLE `user` (
`password` varchar(255) NOT NULL DEFAULT '123456', `id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`) `name` varchar(255) NOT NULL,
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8; `age` tinyint(4) NOT NULL DEFAULT '0',
``` `password` varchar(255) NOT NULL DEFAULT '123456',
PRIMARY KEY (`id`)
然后在entity包中创建实体类User.java ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
```
```java
public class User { 然后在entity包中创建实体类User.java
private int id;
private String name; ```java
private int age; public class User {
private String password; private int id;
private String name;
public User(int id, String name, int age, String password) { private int age;
this.id = id; private String password;
this.name = name;
this.age = age; public User(int id, String name, int age, String password) {
this.password = password; this.id = id;
} this.name = name;
public User(){} this.age = age;
//getter setter自行添加 this.password = password;
} }
``` public User(){}
//getter setter自行添加
在dao包下创建UserDao.java }
```
```java
public interface UserDao { 在dao包下创建UserDao.java
//插入用户
int insert(User user); ```java
//根据id查询 public interface UserDao {
User selectById(String id); //插入用户
//查询所有 int insert(User user);
List<User> selectAll(); //根据id查询
} User selectById(String id);
``` //查询所有
List<User> selectAll();
在mapper文件夹下创建UserMapper.xml,具体的xml编写方法查看文首的官方文档。 }
```
```xml
<?xml version="1.0" encoding="utf-8" ?> 在mapper文件夹下创建UserMapper.xml,具体的xml编写方法查看文首的官方文档。
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.example.mybatistest.dao.UserDao"> ```xml
<sql id="BASE_TABLE"> <?xml version="1.0" encoding="utf-8" ?>
user <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
</sql> <mapper namespace="com.example.mybatistest.dao.UserDao">
<sql id="BASE_COLUMN"> <sql id="BASE_TABLE">
id,name,age,password user
</sql> </sql>
<sql id="BASE_COLUMN">
<insert id="insert" parameterType="com.example.mybatistest.entity.User" useGeneratedKeys="true" keyProperty="id"> id,name,age,password
INSERT INTO <include refid="BASE_TABLE"/> </sql>
<trim prefix="(" suffix=")" suffixOverrides=",">
name,password, <insert id="insert" parameterType="com.example.mybatistest.entity.User" useGeneratedKeys="true" keyProperty="id">
<if test="age!=null"> INSERT INTO <include refid="BASE_TABLE"/>
age <trim prefix="(" suffix=")" suffixOverrides=",">
</if> name,password,
</trim> <if test="age!=null">
<trim prefix=" VALUE(" suffix=")" suffixOverrides=","> age
#{name,jdbcType=VARCHAR},#{password}, </if>
<if test="age!=null"> </trim>
#{age} <trim prefix=" VALUE(" suffix=")" suffixOverrides=",">
</if> #{name,jdbcType=VARCHAR},#{password},
</trim> <if test="age!=null">
</insert> #{age}
</if>
<select id="selectById" resultType="com.example.mybatistest.entity.User"> </trim>
select </insert>
<include refid="BASE_COLUMN"/>
from <select id="selectById" resultType="com.example.mybatistest.entity.User">
<include refid="BASE_TABLE"/> select
where id=#{id} <include refid="BASE_COLUMN"/>
</select> from
<include refid="BASE_TABLE"/>
<select id="selectAll" resultType="com.example.mybatistest.entity.User"> where id=#{id}
select </select>
<include refid="BASE_COLUMN"/>
from <select id="selectAll" resultType="com.example.mybatistest.entity.User">
<include refid="BASE_TABLE"/> select
</select> <include refid="BASE_COLUMN"/>
</mapper> from
``` <include refid="BASE_TABLE"/>
</select>
至此使用mybatis的代码编写完了之后要用时调用dao接口中的方法即可。 </mapper>
```
## 3.测试
至此使用mybatis的代码编写完了之后要用时调用dao接口中的方法即可。
我们通过编写servicecontroller然后使用postman进行测试。
## 3.测试
首先编写UserService.java,代码如下:
我们通过编写servicecontroller然后使用postman进行测试。
```java
@Component 首先编写UserService.java,代码如下:
public class UserService {
```java
@Autowired @Component
private UserDao userDao; public class UserService {
public User getByUserId(String id){ @Autowired
return userDao.selectById(id); private UserDao userDao;
}
//获取全部用户 public User getByUserId(String id){
public List<User> getAll(){ return userDao.selectById(id);
return userDao.selectAll(); }
} //获取全部用户
//测试分页 public List<User> getAll(){
public PageInfo<User> getAll(int pageNum,int pageSize){ return userDao.selectAll();
PageHelper.startPage(pageNum,pageSize); }
List<User> users = userDao.selectAll(); //测试分页
System.out.println(users.size()); public PageInfo<User> getAll(int pageNum,int pageSize){
PageInfo<User> result = new PageInfo<>(users); PageHelper.startPage(pageNum,pageSize);
return result; List<User> users = userDao.selectAll();
} System.out.println(users.size());
PageInfo<User> result = new PageInfo<>(users);
public int insert(User user){ return result;
return userDao.insert(user); }
}
public int insert(User user){
} return userDao.insert(user);
``` }
编写UserController.java }
```
```java
@RestController 编写UserController.java
public class UserController {
```java
@Autowired @RestController
private UserService userService; public class UserController {
@GetMapping("/user/{userId}") @Autowired
public User getUser(@PathVariable String userId){ private UserService userService;
return userService.getByUserId(userId);
} @GetMapping("/user/{userId}")
public User getUser(@PathVariable String userId){
@GetMapping("/user") return userService.getByUserId(userId);
public List<User> getAll(){ }
return userService.getAll();
} @GetMapping("/user")
public List<User> getAll(){
@GetMapping("/user/page/{pageNum}") return userService.getAll();
public Object getPage(@PathVariable int pageNum, }
@RequestParam(name = "pageSize",required = false,defaultValue = "10") int pageSize){
return userService.getAll(pageNum,pageSize); @GetMapping("/user/page/{pageNum}")
} public Object getPage(@PathVariable int pageNum,
@RequestParam(name = "pageSize",required = false,defaultValue = "10") int pageSize){
@PostMapping("/user") return userService.getAll(pageNum,pageSize);
public Object addOne(User user){ }
userService.insert(user);
return user; @PostMapping("/user")
} public Object addOne(User user){
} userService.insert(user);
``` return user;
}
启动项目通过postman进行请求测试测试结果如下 }
```
- 插入数据:
启动项目通过postman进行请求测试测试结果如下
![插入](./picFolder/pic2.png)
- 插入数据:
- 查询数据
![插入](./picFolder/pic2.png)
![查询](./picFolder/pic3.png)
- 查询数据
![查询](./picFolder/pic3.png)
- 分页查询
![分页查询](./picFolder/pic4.png)
- 分页查询
![分页查询](./picFolder/pic4.png)
## 4.注解编写sql
上面使用的是xml方式编写sql代码其实mybatis也支持在注解中编写sql这样可以避免编写复杂的xml查询文件但同时也将sql语句耦合到了代码中也不易实现复杂查询因此多用于简单sql语句的编写。
## 4.注解编写sql
要使用注解首先将applicaton.yml配置文件中的`mapper-locations: classpath:mapper/*.xml`注释掉。然后在UserDao.java中加入sql注解代码如下
上面使用的是xml方式编写sql代码其实mybatis也支持在注解中编写sql这样可以避免编写复杂的xml查询文件但同时也将sql语句耦合到了代码中也不易实现复杂查询因此多用于简单sql语句的编写。
```java
public interface UserDao { 要使用注解首先将applicaton.yml配置文件中的`mapper-locations: classpath:mapper/*.xml`注释掉。然后在UserDao.java中加入sql注解代码如下
//插入用户
@Insert("insert into user(name,age,password) value(#{name},#{age},#{password})") ```java
@Options(useGeneratedKeys=true,keyColumn="id",keyProperty="id") public interface UserDao {
int insert(User user); //插入用户
//根据id查询 @Insert("insert into user(name,age,password) value(#{name},#{age},#{password})")
@Select("select * from user where id=#{id}") @Options(useGeneratedKeys=true,keyColumn="id",keyProperty="id")
User selectById(String id); int insert(User user);
//查询所有 //根据id查询
@Select("select * from user") @Select("select * from user where id=#{id}")
List<User> selectAll(); User selectById(String id);
} //查询所有
``` @Select("select * from user")
List<User> selectAll();
然后重新启动项目测试,测试结果跟上面完全一样。 }
```
```
如果对你有帮助记得点赞、收藏哦! 然后重新启动项目测试,测试结果跟上面完全一样。
```
如果对你有帮助记得点赞、收藏哦!
``` ```

View File

@ -1,5 +1,8 @@
[id]: 82f50cd0d6c111e8aa858b6a40460626 [id]:2018-09-05
# <div align="center">springboot与activeMQ入门1</div> [type]:javaee
[tag]:java,spring,springboot,activemq
**说明acitveMQ版本为5.9.1springboot版本为2.0.3**<br/> **说明acitveMQ版本为5.9.1springboot版本为2.0.3**<br/>
## 一. 下载安装windows ## 一. 下载安装windows
&emsp;&emsp;官方下载地址:[点我跳转](http://activemq.apache.org/download-archives.html),选择windows安装包下载,然后解压解压后运行bin目录下的**activemq.bat**启动服务,无报错即可启动成功。默认管理地址为:[localhost:8161/admin](localhost:8161/admin),默认管理员账号密码为**admin**/**admin**。 &emsp;&emsp;官方下载地址:[点我跳转](http://activemq.apache.org/download-archives.html),选择windows安装包下载,然后解压解压后运行bin目录下的**activemq.bat**启动服务,无报错即可启动成功。默认管理地址为:[localhost:8161/admin](localhost:8161/admin),默认管理员账号密码为**admin**/**admin**。

View File

@ -1,4 +1,8 @@
[id]: 83e5d570d6c111e8aa858b6a40460626 [id]:2018-09-06
[type]:javaee
[tag]:java,spring,activemq
&emsp;&emsp;单个MQ节点总是不可靠的一旦该节点出现故障MQ服务就不可用了势必会产生较大的损失。这里记录activeMQ如何开启主从备份一旦master主节点故障slave从节点立即提供服务实现原理是运行多个MQ使用同一个持久化数据源这里以jdbc数据源为例。同一时间只有一个节点节点A能够抢到数据库的表锁其他节点进入阻塞状态一旦A发生错误崩溃其他节点就会重新获取表锁获取到锁的节点成为master其他节点为slave如果节点A重新启动也将成为slave。 &emsp;&emsp;单个MQ节点总是不可靠的一旦该节点出现故障MQ服务就不可用了势必会产生较大的损失。这里记录activeMQ如何开启主从备份一旦master主节点故障slave从节点立即提供服务实现原理是运行多个MQ使用同一个持久化数据源这里以jdbc数据源为例。同一时间只有一个节点节点A能够抢到数据库的表锁其他节点进入阻塞状态一旦A发生错误崩溃其他节点就会重新获取表锁获取到锁的节点成为master其他节点为slave如果节点A重新启动也将成为slave。
主从备份解决了单节点故障的问题但是同一时间提供服务的只有一个master显然是不能面对数据量的增长所以需要一种横向拓展的集群方式来解决面临的问题。 主从备份解决了单节点故障的问题但是同一时间提供服务的只有一个master显然是不能面对数据量的增长所以需要一种横向拓展的集群方式来解决面临的问题。

View File

@ -1,4 +1,7 @@
[id]: 876b52b0d6c111e8aa858b6a40460626 [id]:2018-09-10
[type]:javaee
[tag]:java,spring,springboot,mybatis,读写分离
&emsp;&emsp;近日工作任务较轻,有空学习学习技术,遂来研究如果实现读写分离。这里用博客记录下过程,一方面可备日后查看,同时也能分享给大家(网上的资料真的大都是抄来抄去,,还不带格式的,看的真心难受)。 &emsp;&emsp;近日工作任务较轻,有空学习学习技术,遂来研究如果实现读写分离。这里用博客记录下过程,一方面可备日后查看,同时也能分享给大家(网上的资料真的大都是抄来抄去,,还不带格式的,看的真心难受)。
[完整代码](https://github.com/FleyX/demo-project/tree/master/dxfl) [完整代码](https://github.com/FleyX/demo-project/tree/master/dxfl)

View File

@ -1,4 +1,7 @@
[id]: 88926d90d6c111e8aa858b6a40460626 [id]:2018-09-20
[type]:软件
[tag]:git,crlf,lf
&emsp;&emsp;项目组最近加了一个新功能到代码中使用flyway记录数据库版本变更该工具会记录每次数据库结构的修改并生成sql文件存在指定目录上当然必须用它来变更数据库外部的变更它是无法感知的然后每次启动时flyway会检查使用的数据库和当前项目代码中的sql变更版本是否一致一致正常启动不一致中如果是数据库落后将会更新数据库这样能够保证代码在任何地方运行数据库都是一致的),否则就报错了。数据库中有一张表记录版本信息,如下图: &emsp;&emsp;项目组最近加了一个新功能到代码中使用flyway记录数据库版本变更该工具会记录每次数据库结构的修改并生成sql文件存在指定目录上当然必须用它来变更数据库外部的变更它是无法感知的然后每次启动时flyway会检查使用的数据库和当前项目代码中的sql变更版本是否一致一致正常启动不一致中如果是数据库落后将会更新数据库这样能够保证代码在任何地方运行数据库都是一致的),否则就报错了。数据库中有一张表记录版本信息,如下图:
![版本记录](./picFolder/版本记录.PNG),同时本地代码中也有一个文件夹保存每次操作的sql语句如下图 ![版本记录](./picFolder/版本记录.PNG),同时本地代码中也有一个文件夹保存每次操作的sql语句如下图

View File

@ -1,4 +1,7 @@
[id]: 8940d600d6c111e8aa858b6a40460626 [id]:2018-09-22
[type]:java
[tag]:java,reflect,excel,hssfworksheet
## 一、背景 ## 一、背景
&emsp;&emsp;最近在java上做了一个EXCEL的导出功能写了一个通用类在这里分享分享该类支持多sheet且无需手动进行复杂的类型转换只需提供三个参数即可 &emsp;&emsp;最近在java上做了一个EXCEL的导出功能写了一个通用类在这里分享分享该类支持多sheet且无需手动进行复杂的类型转换只需提供三个参数即可

View File

@ -1,4 +1,7 @@
[id]: 8b08c4c0d6c111e8aa858b6a40460626 [id]:2018-09-30
[type]:java
[tag]:java,正则,pattern
##一、背景 ##一、背景
&emsp;&emsp;今天领导让我写几个正则表达式来对密码做强度验证,听到写正则表达式内心是这样的感觉(哈哈,三分钟搞定,今天又可以打鱼了)。需求如下:密码组成只能是**数字****字母****英文可见半角符号**然后需要如下4个表达式: &emsp;&emsp;今天领导让我写几个正则表达式来对密码做强度验证,听到写正则表达式内心是这样的感觉(哈哈,三分钟搞定,今天又可以打鱼了)。需求如下:密码组成只能是**数字****字母****英文可见半角符号**然后需要如下4个表达式:

View File

@ -1,4 +1,7 @@
[id]: 8c5ac030d6c111e8aa858b6a40460626 [id]:2018-10-01
[type]:项目
[tag]:node,vue,element-ui,axios,koa,redis,mysql
&emsp;&emsp;毕业才刚刚两个多月而已,现在想想大学生活是那么的遥不可及,感觉已经过了好久好久,社会了两个月才明白学校的好啊。。。额,扯远了,自从毕业开始就想找个时间写下毕设的记录总结,结果找了好久好久到今天才开始动笔。 &emsp;&emsp;毕业才刚刚两个多月而已,现在想想大学生活是那么的遥不可及,感觉已经过了好久好久,社会了两个月才明白学校的好啊。。。额,扯远了,自从毕业开始就想找个时间写下毕设的记录总结,结果找了好久好久到今天才开始动笔。
&emsp;&emsp;我的毕业设计题目是:教学辅助系统的设计与实现,,是不是很俗。。。至于为啥是这个题目呢,完全是被导师坑了。。。。。 &emsp;&emsp;我的毕业设计题目是:教学辅助系统的设计与实现,,是不是很俗。。。至于为啥是这个题目呢,完全是被导师坑了。。。。。

View File

@ -1,4 +1,7 @@
[id]: 8fdce210d6c111e8aa858b6a40460626 [id]:2018-10-02
[type]:数据库
[tag]:acid,sql,分布式,事务
## 前言 ## 前言
&emsp;&emsp;分布式事务是企业集成中的一个技术难点,也是每一个分布式系统架构中都会涉及到的一个东西,特别是在微服务架构中,几乎是无法避免的。 &emsp;&emsp;分布式事务是企业集成中的一个技术难点,也是每一个分布式系统架构中都会涉及到的一个东西,特别是在微服务架构中,几乎是无法避免的。

View File

@ -1,4 +1,7 @@
[id]: 912d2fd0d6c111e8aa858b6a40460626 [id]:2018-10-03
[type]:数据库
[tag]:acid,sql,分布式,事务
## 一、 数据库事务四大特性ACID ## 一、 数据库事务四大特性ACID
### 1、 原子性Atomicity ### 1、 原子性Atomicity

View File

@ -1,4 +1,7 @@
[id]: 92887a10d6c111e8aa858b6a40460626 [id]:2018-08-04
[type]:软件
[tag]:vmware,vps,nat,ubuntu
## 1、wmware设置 ## 1、wmware设置
&emsp;&emsp;这篇记录下nat网络模式下虚拟机与主机的相互ping通。首先使用wmware建立一个ubuntu虚拟机网络模式选择nat模式。然后点击虚拟网络编辑 &emsp;&emsp;这篇记录下nat网络模式下虚拟机与主机的相互ping通。首先使用wmware建立一个ubuntu虚拟机网络模式选择nat模式。然后点击虚拟网络编辑