2021-06-01总结

  1. spring boot 整合mysql和mybatis
    整合mysql 和shiro
    mysql:
    配置数据源
spring:
   datasource:
       url: jdbc:mysql://localhost:3306/hwx?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&autoReconnect=true&allowMultiQueries=true&useSSL=true&serverTimezone=GMT%2B8
    username: root
    password: 123456
    filters: wall,mergeStat
    type: com.alibaba.druid.pool.DruidDataSource
    druid:
      filters: stat,wall
      stat-view-servlet:
        enabled: true
        login-username: hwxadmin
        login-password: hwx001125
      web-stat-filter:
        enabled: true
        urlpattern: /*
        exclusions: '*.js,*.jgp,*.png,*.gif,*.css,*.ico,/druid/*'
      filter:
        slow-sql-millis: 1000
        logslowsql: true
        enabled: true

配置mybatis时,需要配置xml文件的扫描位置
只需要在yml文件中配置

mybatis-plus:
  mapper-locations: classpath:myBatis/*.xml

顶格即可

mybatis
配置mybatis的xml时,
插入用select标签,返回值为Integer,
查询用select标签,返回值为实体类

配置数据库和实体类的关系可以用resultMap标签
property为数据库返回的字段名,column为相对应的实体类的字段名

xml的映射接口mapper需要继承 BaseMapper< shirouser > ,这个shirouser为实体类

spring boot

1:
mapper接口需要@mapper注解否则会报找不到bean的错误,如果标注了注解还是报错,可以在启动类上添加一个扫描mapper的注解@MapperScan(basePackages = “com.demo.mapper”)

2:
server的impl需要添加@service的注解

3:
自己定义的工具类添加@Component注解
需要在工具类中使用其他工具类时,不能自己new,需要在wenconfig中添加@bean ,将其加入到spring ioc 或者

    private  static  bookmainmapper bookmainmapper;


    private  static  bookmainService bookmainService;

   @Autowired
   public void  setBookmainmapper(bookmainmapper bookmainmapper){
       bookdate.bookmainmapper=bookmainmapper;
   }

   @Autowired
   public  void setBookmainService(bookmainService bookmainService){
       bookdate.bookmainService=bookmainService;
   }
    public bookdate() {
    }

4:
配置类记得加上@Configuration注解

shiro:

配置shiroconfig:
自定义realm继承AuthorizingRealm接口,然后在webconfig中@bean,将其加入到spring ioc

然后将realm加入到DefaultWebSecurityManager,再将,DefaultWebSecurityManager加入到ShiroFilterFactoryBean即可

自定义的realm继承AuthorizingRealm,实现两个方法
1:
doGetAuthorizationInfo
这个方法用来做权限认证

2:
doGetAuthenticationInfo
这个方法用来做登录认证

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爷可是个天才

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值