作业一:
首先按照视频中的指导添加依赖。注意后续还会有相应依赖添加。
创建相应package。com.imooc下创建miaosha,miaosha下分别创建controller、dao、domain、service,其中domain下创建redis。java下创建resources,在它下创建application.properties,继续在它下创造package名为templates,于templates下创建hello.html。在controller下创建class为SampleController,dao下创建interface为UserDao,domain下创建class为User,redis下创建class为BasePrefix、OderKey、RedisConfig、RedisPoolFactory、RedisService、UserKey,创建interface为KeyPerfix,service下创建class为UserService,miaosha下创建class为MainApplication。
配置好配置文件。配置application.properties。需要在其中相应添加spring.thymeleaf、mybatis、spring.datasource、redis配置。
于MainApplication中创建主函数。SampleController中使用userService、redisService,编写方法,有home()、error()、dbGet()、dbTx()、redisGet()、redisSet()。UserService中使用userDao,编写getById()、tx()方法。接口UserDao中编写getById()、insert()方法。User中创建对象id、name,自动生成对应get()、set()方法。接口KeyPerfix中编写expireSeconds()、getPrefix()方法。BasePrefix需要implements接口KeyPrefix,编写expireSeconds()、getPrefix()、BasePrefix(String prefix)、BasePrefix(int expireSeconds,String prefix)方法。RedisConfig新建对象host、poolMaxTotal、poolMaxTdlle、poolMaxWait、port、timeout、password,自动生成其对应的get()、set()方法。RedisPoolFactory中调用redisConfig。RedisService中调用jedisPool、redisConfig,编写get(Prefix prefix,String key,Classclazz)、stringToBean(String str)、JedisPoolFactory()、beanToString(T value)、stringToBean(String str,Classclazz)、get(String key,T value)方法。OrderKey需要extends的BasePrefix,编写OrderKey(int expireSeconds,String prefix)方法。UserKey同样extends的BasePrefix,编写UserKey(String prefix)方法,并使用getById、getByName。
作业一
最新推荐文章于 2023-04-08 18:26:19 发布