package com.wzx.gmall.dao;
import com.wzx.gmall.bean.Course;
import org.apache.ibatis.annotations.*;
import java.util.List;
@Mapper
public interface CourseDao {
// 查询所有
@Select("select * from course")
List findAll();
//添加
@Insert("insert into course values('006','王梓旭',50)")
int addCourse(Course course);
//修改
@Update("update course set cname='刘浩' , tid=50 where cid='006' ")
int updateCourse(Course course);
//删除
@Delete("delete from course where cid='006'")
int deleteCourse(String id);
}
package com.wzx.gmall.service.serviceImpl;
import com.wzx.gmall.bean.Course;
import com.wzx.gmall.bean.User;
import com.wzx.gmall.config.RedisConfig;
import com.wzx.gmall.dao.CourseDao;
import com.wzx.gmall.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;
@Service
public class CourseServiceImpl implements CourseService {
@Autowired
CourseDao courseDao;
//从spring容器中获取RedisTemplate实例
@Autowired
private RedisTemplate redisTemplate;
@Override
public List findAll() {
List all = courseDao.findAll();
ValueOperations valueOperations = redisTemplate.opsForValue();
valueOperations.set("1" ,all.toString());
//设置过期时间
redisTemplate.expire("1" ,60, TimeUnit.SECONDS);
return all;
}
@Override
public int addCourse(Course course) {
int i = courseDao.addCourse(course);
if(i==1){
ValueOperations valueOperations = redisTemplate.opsForValue();
List all = courseDao.findAll();
valueOperations.set("1", all.toString());
}
return i;
}
@Override
public int updateCourse(Course course) {
int i = courseDao.updateCourse(course);
if(i==1){
ValueOperations valueOperations = redisTemplate.opsForValue();
List all = courseDao.findAll();
valueOperations.set("1", all.toString());
}
return i;
}
@Override
public int deleteCourse(String cid) {
int i = courseDao.deleteCourse(cid);
if(i==1){
ValueOperations valueOperations = redisTemplate.opsForValue();
List all = courseDao.findAll();
valueOperations.set("1", all.toString());
}
return i;
}
@Override
public void setUser() {
User user =new User();
user.setName("wzx");
user.setAge(18);
user.setHigh(175);
ValueOperations valueOperations = redisTemplate.opsForValue();
valueOperations.set("wzx", user);
//设置过期时间
redisTemplate.expire("1" ,60, TimeUnit.SECONDS);
}
@Override
public String getUser() {
ValueOperations valueOperations = redisTemplate.opsForValue();
Object wzx = valueOperations.get("wzx");
return wzx.toString();
}
}
6 controller
package com.wzx.gmall.controller;
import com.wzx.gmall.bean.Course;
import com.wzx.gmall.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@Slf4j
@CacheConfig
@RestController
public class CourseController {
@Autowired
CourseService courseService;
@RequestMapping("add")
public int addCourse(){
System.out.println("新政数据");
Course course = new Course();
return courseService.addCourse(course);
}
@Cacheable(cacheNames = "find")
@RequestMapping("find")
public List findAll(){
System.out.println("查询所有数据");
return courseService.findAll();
}
@RequestMapping("delete")
public int delete(){
System.out.println("删除数据");
return courseService.deleteCourse("006");
}
@RequestMapping("update")
public int update(){
System.out.println("更新数据");
Course course = new Course();
return courseService.updateCourse(course);
}
@RequestMapping("wzx")
public void user() throws InterruptedException {
System.out.println("哈哈我来了:");
courseService.setUser();
Thread.sleep(5);
String user = courseService.getUser();
System.out.println(user);
}
}
pom.xml
4.0.0com.wzx.gmallgmall2023-logger0.0.1-SNAPSHOTgmall2023-loggerDemo project for Spring Boot1.8UTF-8UTF-82.4.13.4.21.3.0org.springframework.bootspring-boot-starter-weborg.springframework.kafkaspring-kafkaorg.projectlomboklomboktrueorg.springframework.bootspring-boot-starter-testtestorg.springframework.kafkaspring-kafka-testtestorg.xmlunitxmlunit-coreorg.scala-langscala-reflect2.10.3compiletk.mybatismapper-spring-boot-starter2.1.4org.mybatismybatis${mybatis.version}org.mybatismybatis-spring${mybatis.spring.version}junitjunitorg.springframework.bootspring-boot-starter-cacheorg.springframework.bootspring-boot-starter-data-redisorg.springframework.bootspring-boot-testorg.springframework.bootspring-boot-testorg.springframework.bootspring-boot-dependencies${spring-boot.version}pomimportorg.apache.maven.pluginsmaven-compiler-plugin3.8.11.81.8UTF-8org.springframework.bootspring-boot-maven-plugin2.4.1com.wzx.gmall.Gmall2023LoggerApplicationrepackagerepackage
Android中的Toast是一种简易的消息提示框,toast提示框不能被用户点击,toast会根据用户设置的显示时间后自动消失。
创建Toast
两个方法创建Toast
makeText(Context context, int resId, int duration)
参数:context是toast显示在
angular.identiy 描述: 返回它第一参数的函数. 此函数多用于函数是编程. 使用方法: angular.identity(value); 参数详解: Param Type Details value
*
to be returned. 返回值: 传入的value 实例代码:
<!DOCTYPE HTML>
Hierarchical Queries
If a table contains hierarchical data, then you can select rows in a hierarchical order using the hierarchical query clause:
hierarchical_query_clause::=
start with condi
初次接触到socket网络编程,也参考了网络上众前辈的文章。尝试自己也写了一下,记录下过程吧:
服务端:(接收客户端消息并把它们打印出来)
public class SocketServer {
private List<Socket> socketList = new ArrayList<Socket>();
public s