springboot-mybatisplus-layui结构

springboot-mybatisplus-layui结构

分层结构如下所示
在这里插入图片描述

yml配置文件

spring:
  datasource:
    druid:
      driver-class-name: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://localhost:3306/springboot-mybatis-layui?useSSL=false&serverTimezone=UTC
      username: root
      password: 123456
      max-active: 20
      max-wait: 5000
      initial-size: 1
      filters: stat,log4j,wall
      validation-query: SELECT 'x'
      enable: true
      stat-view-servlet:
        enabled: true
        login-username: root
        login-password: 123456
        url-pattern: /druid/*

mybatis-plus:
  mapper-locations: classpath:mapper/*/*Mapper.xml
  global-config:
    db-config:
      id-type: auto
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

Mapper层

@Mapper
public interface UserMapper extends BaseMapper<User> {
}

@Mapper注释 + 继承BaseMapper<entity>

Service层

public interface UserService extends IService<User> {
}

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
}

Entity层

@Data
@ToString
@TableName("user")
@EqualsAndHashCode(callSuper = false)
public class User implements Serializable {
    private Integer id;
    private String userName;
    private Integer point;
    private String sex;
    private Integer score;
    private String city;
    private String signaure;
    private String occupation;
    private Integer wealth;


    @TableField(exist = false) //抽离表示不是数据库中的元素
    private Integer page=1;
    @TableField(exist = false)

    private Integer limit=10;
}

controller层

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

   //查询所有用户
    @RequestMapping("/listUser")
    public DataView getALllUser(User user){
        IPage<User> page=new Page<>(user.getPage(),user.getLimit());
//        List<User> list = userService.list();
        userService.page(page);
        return new DataView(page.getTotal(),page.getRecords());


    }
    @PutMapping("/deleteUser")
    public DataView deleteUser(User user){

        boolean b = userService.removeById(user.getId());
        DataView dataView=new DataView();
        if(b){
            dataView.setCode(200);
            dataView.setMsg("删除成功!");
        }else {
            dataView.setCode(500);
            dataView.setMsg("删除失败!");
        }
        return dataView;

    }

}

vo层

将数据分装成Layui可以解析的格式

@Data
@NoArgsConstructor
@AllArgsConstructor
public class DataView {
    private Integer code = 0;
    private String msg = "";
    private Long count = 0L;
    private Object data;

    public DataView(Long count,Object data){
        this.count=count;
        this.data=data;
    }
    public DataView(Object data){

        this.data=data;
    }
}

config层

@Configuration
@ConditionalOnClass(value = {PaginationInnerInterceptor.class})
public class MybatisPlusConfig {

    @Bean
    public PaginationInnerInterceptor paginationInnerInterceptor(){
        return new PaginationInnerInterceptor();
    }
}

配置分页

log4j.properties

log4j.rootLogger=DEBUG, stdout
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

放在resource层,与application.yml 同级

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
本项目使用 Spring Boot 搭建, 用于加深对 Spring Boot 与 Shiro 的学习, 项目特色是支持 restful 风格权限控制, 支持对同一 URL, 不同 HTTP Mehtod 的权限控制, 适用于更多的场景. 预览地址: http://ewt.186g.cn 默认管理员账号: admin, 密码: 123456. 普通用户账号: user, 密码: 123456. 为了不影响其他人的浏览体验, 请尽量不要进行删除类的敏感操作. admin 为超级管理员, 自动拥有全部权限. 系统特色 支持根据同 URL, 不同 HTTP Method 来校验权限, 更支持 restful 场景. 集成 OAuth2 登录, 且提供了接口易于拓展开发. 全局异常处理. 根据请求方式区分返回 json 数据还是错误页面. Logback MDC 支持, 将当前登录人和操作者 IP 加入日志中. JSR-303 数据校验 运行环境 JDK 1.8 MySQL 5.7 Redis 配置文件 打开 application.properties 修改 MySQL 和 Redis 连接信息. spring.redis.host=127.0.0.1 spring.redis.port=6379 spring.cache.type=redis spring.datasource.username=root spring.datasource.password=123456 spring.datasource.url=jdbc:mysql://127.0.0.1:3306/shiro_action?useSSL=false&characterEncoding=UTF8 启动项目 在完成了上述步骤后,找到 ShiroActionApplication 启动类, 启动即可. 启动后访问地址为:http://localhost:8080 , 用户名:admin, 密码:123456. 技术选型 前端 前端框架: Layui 后台模板: Z-Admin 后端 SpringBoot 2.2.3.RELEASE Shiro 1.4.0 Mybatis-Plus3.1.2 Druid 1.1.10 PageHelper 1.2.9 Shiro-Redis 3.2.3
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值