完成10个工程的代码
This commit is contained in:
@ -0,0 +1,12 @@
|
||||
package com.xncoding.pos;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,249 @@
|
||||
package com.xncoding.pos.common.dao.entity;
|
||||
|
||||
import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotations.TableName;
|
||||
import com.baomidou.mybatisplus.enums.IdType;
|
||||
import com.baomidou.mybatisplus.annotations.TableId;
|
||||
import com.baomidou.mybatisplus.activerecord.Model;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 后台管理用户表
|
||||
*
|
||||
* @author 熊能
|
||||
* @version 1.0
|
||||
* @since 2018/01/02
|
||||
*/
|
||||
@TableName(value = "t_user")
|
||||
public class User extends Model<User> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value="id", type= IdType.AUTO)
|
||||
private Integer id;
|
||||
/**
|
||||
* 账号
|
||||
*/
|
||||
private String username;
|
||||
/**
|
||||
* 名字
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
/**
|
||||
* md5密码盐
|
||||
*/
|
||||
private String salt;
|
||||
/**
|
||||
* 联系电话
|
||||
*/
|
||||
private String phone;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String tips;
|
||||
/**
|
||||
* 状态 1:正常 2:禁用
|
||||
*/
|
||||
private Integer state;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createdTime;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updatedTime;
|
||||
|
||||
/**
|
||||
* 获取 主键ID.
|
||||
*
|
||||
* @return 主键ID.
|
||||
*/
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 主键ID.
|
||||
*
|
||||
* @param id 主键ID.
|
||||
*/
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 账号.
|
||||
*
|
||||
* @return 账号.
|
||||
*/
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 账号.
|
||||
*
|
||||
* @param username 账号.
|
||||
*/
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 名字.
|
||||
*
|
||||
* @return 名字.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 名字.
|
||||
*
|
||||
* @param name 名字.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 密码.
|
||||
*
|
||||
* @return 密码.
|
||||
*/
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 密码.
|
||||
*
|
||||
* @param password 密码.
|
||||
*/
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 md5密码盐.
|
||||
*
|
||||
* @return md5密码盐.
|
||||
*/
|
||||
public String getSalt() {
|
||||
return salt;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 md5密码盐.
|
||||
*
|
||||
* @param salt md5密码盐.
|
||||
*/
|
||||
public void setSalt(String salt) {
|
||||
this.salt = salt;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 联系电话.
|
||||
*
|
||||
* @return 联系电话.
|
||||
*/
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 联系电话.
|
||||
*
|
||||
* @param phone 联系电话.
|
||||
*/
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 备注.
|
||||
*
|
||||
* @return 备注.
|
||||
*/
|
||||
public String getTips() {
|
||||
return tips;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 备注.
|
||||
*
|
||||
* @param tips 备注.
|
||||
*/
|
||||
public void setTips(String tips) {
|
||||
this.tips = tips;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 状态 1:正常 2:禁用.
|
||||
*
|
||||
* @return 状态 1:正常 2:禁用.
|
||||
*/
|
||||
public Integer getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 状态 1:正常 2:禁用.
|
||||
*
|
||||
* @param state 状态 1:正常 2:禁用.
|
||||
*/
|
||||
public void setState(Integer state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 创建时间.
|
||||
*
|
||||
* @return 创建时间.
|
||||
*/
|
||||
public Date getCreatedTime() {
|
||||
return createdTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 创建时间.
|
||||
*
|
||||
* @param createdTime 创建时间.
|
||||
*/
|
||||
public void setCreatedTime(Date createdTime) {
|
||||
this.createdTime = createdTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 更新时间.
|
||||
*
|
||||
* @return 更新时间.
|
||||
*/
|
||||
public Date getUpdatedTime() {
|
||||
return updatedTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 更新时间.
|
||||
*
|
||||
* @param updatedTime 更新时间.
|
||||
*/
|
||||
public void setUpdatedTime(Date updatedTime) {
|
||||
this.updatedTime = updatedTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Serializable pkVal() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package com.xncoding.pos.common.dao.repository;
|
||||
|
||||
import com.xncoding.pos.common.dao.entity.User;
|
||||
import com.baomidou.mybatisplus.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* 后台管理用户表 Mapper
|
||||
*
|
||||
* @author 熊能
|
||||
* @version 1.0
|
||||
* @since 2018/01/02
|
||||
*/
|
||||
public interface UserMapper extends BaseMapper<User> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
package com.xncoding.pos.config;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
|
||||
import com.xncoding.pos.config.properties.DruidProperties;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* MybatisPlus配置
|
||||
*
|
||||
* @author xiongneng
|
||||
* @since 2017/5/20 21:58
|
||||
*/
|
||||
@Configuration
|
||||
@EnableTransactionManagement(order = 2)
|
||||
@MapperScan(basePackages = {
|
||||
"com.xncoding.pos.common.dao.repository",
|
||||
"com.xncoding.pos.dao.repository"})
|
||||
public class MybatisPlusConfig {
|
||||
|
||||
@Resource
|
||||
private DruidProperties druidProperties;
|
||||
|
||||
/**
|
||||
* 单数据源连接池配置
|
||||
*/
|
||||
@Bean
|
||||
public DruidDataSource singleDatasource() {
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
druidProperties.config(dataSource);
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* mybatis-plus分页插件
|
||||
*/
|
||||
@Bean
|
||||
public PaginationInterceptor paginationInterceptor() {
|
||||
return new PaginationInterceptor();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,249 @@
|
||||
package com.xncoding.pos.config.properties;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* <p>数据库数据源配置</p>
|
||||
* <p>说明:这个类中包含了许多默认配置,若这些配置符合您的情况,您可以不用管,若不符合,建议不要修改本类,建议直接在"application.yml"中配置即可</p>
|
||||
*
|
||||
* @author xiongneng
|
||||
* @since 2017-05-21 11:18
|
||||
*/
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "spring.datasource")
|
||||
public class DruidProperties {
|
||||
|
||||
private String url;
|
||||
|
||||
private String username;
|
||||
|
||||
private String password;
|
||||
|
||||
private String driverClassName = "com.mysql.cj.jdbc.Driver";
|
||||
|
||||
private Integer initialSize = 10;
|
||||
|
||||
private Integer minIdle = 3;
|
||||
|
||||
private Integer maxActive = 60;
|
||||
|
||||
private Integer maxWait = 60000;
|
||||
|
||||
private Boolean removeAbandoned = true;
|
||||
|
||||
private Integer removeAbandonedTimeout = 180;
|
||||
|
||||
private Integer timeBetweenEvictionRunsMillis = 60000;
|
||||
|
||||
private Integer minEvictableIdleTimeMillis = 300000;
|
||||
|
||||
private String validationQuery = "SELECT 'x'";
|
||||
|
||||
private Boolean testWhileIdle = true;
|
||||
|
||||
private Boolean testOnBorrow = false;
|
||||
|
||||
private Boolean testOnReturn = false;
|
||||
|
||||
private Boolean poolPreparedStatements = true;
|
||||
|
||||
private Integer maxPoolPreparedStatementPerConnectionSize = 50;
|
||||
|
||||
private String filters = "stat";
|
||||
|
||||
public void config(DruidDataSource dataSource) {
|
||||
dataSource.setDbType(JdbcConstants.MYSQL);
|
||||
dataSource.setUrl(url);
|
||||
dataSource.setUsername(username);
|
||||
dataSource.setPassword(password);
|
||||
dataSource.setDriverClassName(driverClassName);
|
||||
dataSource.setInitialSize(initialSize); // 定义初始连接数
|
||||
dataSource.setMinIdle(minIdle); // 最小空闲
|
||||
dataSource.setMaxActive(maxActive); // 定义最大连接数
|
||||
dataSource.setMaxWait(maxWait); // 获取连接等待超时的时间
|
||||
dataSource.setRemoveAbandoned(removeAbandoned); // 超过时间限制是否回收
|
||||
dataSource.setRemoveAbandonedTimeout(removeAbandonedTimeout); // 超过时间限制多长
|
||||
|
||||
// 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
|
||||
dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
|
||||
// 配置一个连接在池中最小生存的时间,单位是毫秒
|
||||
dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
|
||||
// 用来检测连接是否有效的sql,要求是一个查询语句
|
||||
dataSource.setValidationQuery(validationQuery);
|
||||
// 申请连接的时候检测
|
||||
dataSource.setTestWhileIdle(testWhileIdle);
|
||||
// 申请连接时执行validationQuery检测连接是否有效,配置为true会降低性能
|
||||
dataSource.setTestOnBorrow(testOnBorrow);
|
||||
// 归还连接时执行validationQuery检测连接是否有效,配置为true会降低性能
|
||||
dataSource.setTestOnReturn(testOnReturn);
|
||||
// 打开PSCache,并且指定每个连接上PSCache的大小
|
||||
dataSource.setPoolPreparedStatements(poolPreparedStatements);
|
||||
dataSource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
|
||||
// 属性类型是字符串,通过别名的方式配置扩展插件,常用的插件有:
|
||||
// 监控统计用的filter:stat
|
||||
// 日志用的filter:log4j
|
||||
// 防御SQL注入的filter:wall
|
||||
try {
|
||||
dataSource.setFilters(filters);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getDriverClassName() {
|
||||
return driverClassName;
|
||||
}
|
||||
|
||||
public void setDriverClassName(String driverClassName) {
|
||||
this.driverClassName = driverClassName;
|
||||
}
|
||||
|
||||
public Integer getInitialSize() {
|
||||
return initialSize;
|
||||
}
|
||||
|
||||
public void setInitialSize(Integer initialSize) {
|
||||
this.initialSize = initialSize;
|
||||
}
|
||||
|
||||
public Integer getMinIdle() {
|
||||
return minIdle;
|
||||
}
|
||||
|
||||
public void setMinIdle(Integer minIdle) {
|
||||
this.minIdle = minIdle;
|
||||
}
|
||||
|
||||
public Integer getMaxActive() {
|
||||
return maxActive;
|
||||
}
|
||||
|
||||
public void setMaxActive(Integer maxActive) {
|
||||
this.maxActive = maxActive;
|
||||
}
|
||||
|
||||
public Integer getMaxWait() {
|
||||
return maxWait;
|
||||
}
|
||||
|
||||
public void setMaxWait(Integer maxWait) {
|
||||
this.maxWait = maxWait;
|
||||
}
|
||||
|
||||
public Integer getTimeBetweenEvictionRunsMillis() {
|
||||
return timeBetweenEvictionRunsMillis;
|
||||
}
|
||||
|
||||
public void setTimeBetweenEvictionRunsMillis(Integer timeBetweenEvictionRunsMillis) {
|
||||
this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
|
||||
}
|
||||
|
||||
public Integer getMinEvictableIdleTimeMillis() {
|
||||
return minEvictableIdleTimeMillis;
|
||||
}
|
||||
|
||||
public void setMinEvictableIdleTimeMillis(Integer minEvictableIdleTimeMillis) {
|
||||
this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
|
||||
}
|
||||
|
||||
public String getValidationQuery() {
|
||||
return validationQuery;
|
||||
}
|
||||
|
||||
public void setValidationQuery(String validationQuery) {
|
||||
this.validationQuery = validationQuery;
|
||||
}
|
||||
|
||||
public Boolean getTestWhileIdle() {
|
||||
return testWhileIdle;
|
||||
}
|
||||
|
||||
public void setTestWhileIdle(Boolean testWhileIdle) {
|
||||
this.testWhileIdle = testWhileIdle;
|
||||
}
|
||||
|
||||
public Boolean getTestOnBorrow() {
|
||||
return testOnBorrow;
|
||||
}
|
||||
|
||||
public void setTestOnBorrow(Boolean testOnBorrow) {
|
||||
this.testOnBorrow = testOnBorrow;
|
||||
}
|
||||
|
||||
public Boolean getTestOnReturn() {
|
||||
return testOnReturn;
|
||||
}
|
||||
|
||||
public void setTestOnReturn(Boolean testOnReturn) {
|
||||
this.testOnReturn = testOnReturn;
|
||||
}
|
||||
|
||||
public Boolean getPoolPreparedStatements() {
|
||||
return poolPreparedStatements;
|
||||
}
|
||||
|
||||
public void setPoolPreparedStatements(Boolean poolPreparedStatements) {
|
||||
this.poolPreparedStatements = poolPreparedStatements;
|
||||
}
|
||||
|
||||
public Integer getMaxPoolPreparedStatementPerConnectionSize() {
|
||||
return maxPoolPreparedStatementPerConnectionSize;
|
||||
}
|
||||
|
||||
public void setMaxPoolPreparedStatementPerConnectionSize(Integer maxPoolPreparedStatementPerConnectionSize) {
|
||||
this.maxPoolPreparedStatementPerConnectionSize = maxPoolPreparedStatementPerConnectionSize;
|
||||
}
|
||||
|
||||
public String getFilters() {
|
||||
return filters;
|
||||
}
|
||||
|
||||
public void setFilters(String filters) {
|
||||
this.filters = filters;
|
||||
}
|
||||
|
||||
public Boolean getRemoveAbandoned() {
|
||||
return removeAbandoned;
|
||||
}
|
||||
|
||||
public void setRemoveAbandoned(Boolean removeAbandoned) {
|
||||
this.removeAbandoned = removeAbandoned;
|
||||
}
|
||||
|
||||
public Integer getRemoveAbandonedTimeout() {
|
||||
return removeAbandonedTimeout;
|
||||
}
|
||||
|
||||
public void setRemoveAbandonedTimeout(Integer removeAbandonedTimeout) {
|
||||
this.removeAbandonedTimeout = removeAbandonedTimeout;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
package com.xncoding.pos.service;
|
||||
|
||||
import com.xncoding.pos.common.dao.entity.User;
|
||||
import com.xncoding.pos.common.dao.repository.UserMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 后台用户管理
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
|
||||
/**
|
||||
* 通过ID查找用户
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public User findById(Integer id) {
|
||||
return userMapper.selectById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用户
|
||||
* @param user
|
||||
*/
|
||||
public void insertUser(User user) {
|
||||
userMapper.insert(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户
|
||||
* @param user
|
||||
*/
|
||||
public void updateUser(User user) {
|
||||
userMapper.updateById(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
* @param id
|
||||
*/
|
||||
public void deleteUser(Integer id) {
|
||||
userMapper.deleteById(id);
|
||||
}
|
||||
|
||||
}
|
||||
70
springboot-mybatis/src/main/resources/application.yml
Normal file
70
springboot-mybatis/src/main/resources/application.yml
Normal file
@ -0,0 +1,70 @@
|
||||
##########################################################
|
||||
################## 所有profile共有的配置 #################
|
||||
##########################################################
|
||||
|
||||
################### spring配置 ###################
|
||||
spring:
|
||||
profiles:
|
||||
active: dev
|
||||
|
||||
################### mybatis-plus配置 ###################
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath*:com/xncoding/pos/dao/repository/mapping/*.xml
|
||||
typeAliasesPackage: >
|
||||
com.xncoding.pos.common.dao.entity
|
||||
global-config:
|
||||
id-type: 0 # 0:数据库ID自增 1:用户输入id 2:全局唯一id(IdWorker) 3:全局唯一ID(uuid)
|
||||
db-column-underline: false
|
||||
refresh-mapper: true
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
cache-enabled: true #配置的缓存的全局开关
|
||||
lazyLoadingEnabled: true #延时加载的开关
|
||||
multipleResultSetsEnabled: true #开启的话,延时加载一个属性时会加载该对象全部属性,否则按需加载属性
|
||||
|
||||
logging:
|
||||
level:
|
||||
org.springframework.web.servlet: ERROR
|
||||
|
||||
---
|
||||
|
||||
#####################################################################
|
||||
######################## 开发环境profile ##########################
|
||||
#####################################################################
|
||||
spring:
|
||||
profiles: dev
|
||||
datasource:
|
||||
url: jdbc:mysql://123.207.66.156:3306/pos?useSSL=false&autoReconnect=true&tinyInt1isBit=false&useUnicode=true&characterEncoding=utf8
|
||||
username: root
|
||||
password: ******
|
||||
thymeleaf:
|
||||
cache: false
|
||||
|
||||
logging:
|
||||
level:
|
||||
ROOT: INFO
|
||||
com:
|
||||
xncoding: DEBUG
|
||||
file: E:/logs/app.log
|
||||
|
||||
---
|
||||
|
||||
#####################################################################
|
||||
######################## 测试环境profile ##########################
|
||||
#####################################################################
|
||||
|
||||
spring:
|
||||
profiles: test
|
||||
datasource:
|
||||
url: jdbc:mysql://123.207.66.156:3306/pos?useSSL=false&autoReconnect=true&tinyInt1isBit=false&useUnicode=true&characterEncoding=utf8
|
||||
username: root
|
||||
password: ******
|
||||
thymeleaf:
|
||||
cache: false
|
||||
|
||||
logging:
|
||||
level:
|
||||
ROOT: INFO
|
||||
com:
|
||||
xncoding: DEBUG
|
||||
file: /var/logs/app.log
|
||||
23
springboot-mybatis/src/main/resources/banner.txt
Normal file
23
springboot-mybatis/src/main/resources/banner.txt
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
_____ _______ _____ _____
|
||||
/\ \ /::\ \ /\ \ /\ \
|
||||
/::\____\ /::::\ \ /::\____\ /::\ \
|
||||
/:::/ / /::::::\ \ /:::/ / /::::\ \
|
||||
/:::/ / /::::::::\ \ /:::/ / /::::::\ \
|
||||
/:::/ / /:::/~~\:::\ \ /:::/ / /:::/\:::\ \
|
||||
/:::/ / /:::/ \:::\ \ /:::/____/ /:::/__\:::\ \
|
||||
/:::/ / /:::/ / \:::\ \ |::| | /::::\ \:::\ \
|
||||
/:::/ / /:::/____/ \:::\____\ |::| | _____ /::::::\ \:::\ \
|
||||
/:::/ / |:::| | |:::| | |::| | /\ \ /:::/\:::\ \:::\ \
|
||||
/:::/____/ |:::|____| |:::| | |::| | /::\____\/:::/__\:::\ \:::\____\
|
||||
\:::\ \ \:::\ \ /:::/ / |::| | /:::/ /\:::\ \:::\ \::/ /
|
||||
\:::\ \ \:::\ \ /:::/ / |::| | /:::/ / \:::\ \:::\ \/____/
|
||||
\:::\ \ \:::\ /:::/ / |::|____|/:::/ / \:::\ \:::\ \
|
||||
\:::\ \ \:::\__/:::/ / |:::::::::::/ / \:::\ \:::\____\
|
||||
\:::\ \ \::::::::/ / \::::::::::/____/ \:::\ \::/ /
|
||||
\:::\ \ \::::::/ / ~~~~~~~~~~ \:::\ \/____/
|
||||
\:::\ \ \::::/ / \:::\ \
|
||||
\:::\____\ \::/____/ \:::\____\
|
||||
\::/ / ~~ \::/ /
|
||||
\/____/ \/____/
|
||||
|
||||
24
springboot-mybatis/src/main/resources/sql/schema.sql
Normal file
24
springboot-mybatis/src/main/resources/sql/schema.sql
Normal file
@ -0,0 +1,24 @@
|
||||
# -------------------------------------以下业务表开始-------------------------------------------
|
||||
# CREATE DATABASE IF NOT EXISTS pos default charset utf8 COLLATE utf8_general_ci;
|
||||
# SET FOREIGN_KEY_CHECKS=0;
|
||||
# USE pos;
|
||||
|
||||
# -------------------------------------以下用户管理表开始-------------------------------------------
|
||||
|
||||
-- 后台管理用户表
|
||||
DROP TABLE IF EXISTS `t_user`;
|
||||
CREATE TABLE `t_user` (
|
||||
`id` INT(11) PRIMARY KEY AUTO_INCREMENT COMMENT '主键ID',
|
||||
`username` VARCHAR(32) NOT NULL COMMENT '账号',
|
||||
`name` VARCHAR(16) DEFAULT '' COMMENT '名字',
|
||||
`password` VARCHAR(128) DEFAULT '' COMMENT '密码',
|
||||
`salt` VARCHAR(64) DEFAULT '' COMMENT 'md5密码盐',
|
||||
`phone` VARCHAR(32) DEFAULT '' COMMENT '联系电话',
|
||||
`tips` VARCHAR(255) COMMENT '备注',
|
||||
`state` TINYINT(1) DEFAULT 1 COMMENT '状态 1:正常 2:禁用',
|
||||
`created_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updated_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间'
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='后台管理用户表';
|
||||
INSERT INTO `t_user` VALUES (1,'admin','系统管理员','123456','www', '17890908889', '系统管理员', 1, '2017-12-12 09:46:12', '2017-12-12 09:46:12');
|
||||
INSERT INTO `t_user` VALUES (2,'aix','张三','123456','eee', '17859569358', '', 1, '2017-12-12 09:46:12', '2017-12-12 09:46:12');
|
||||
|
||||
@ -0,0 +1,56 @@
|
||||
package com.xncoding.pos;
|
||||
|
||||
import com.xncoding.pos.common.dao.entity.User;
|
||||
import com.xncoding.pos.service.UserService;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
/**
|
||||
* 测试
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class ApplicationTests {
|
||||
private static final Logger log = LoggerFactory.getLogger(ApplicationTests.class);
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
/**
|
||||
* 测试增删改查
|
||||
*/
|
||||
@Test
|
||||
public void test() {
|
||||
User user = new User();
|
||||
user.setUsername("xiaoxx");
|
||||
user.setName("小星星");
|
||||
user.setPassword("222222");
|
||||
user.setPhone("13890907676");
|
||||
userService.insertUser(user);
|
||||
|
||||
User user1 = userService.findById(user.getId());
|
||||
assertThat(user1.getUsername(), is("xiaoxx"));
|
||||
assertThat(user1.getName(), is("小星星"));
|
||||
|
||||
user1.setPassword("888888");
|
||||
userService.updateUser(user1);
|
||||
User user2 = userService.findById(user.getId());
|
||||
assertThat(user2.getPassword(), is("888888"));
|
||||
|
||||
userService.deleteUser(user.getId());
|
||||
|
||||
User user3 = userService.findById(user.getId());
|
||||
assertThat(user3, nullValue());
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user