java 内存数据库 sql_ssm+redis +Maven用于内存数据库 (No Sql)入门demo
最近一直是以自學的狀態,想把自己學習到的知識分享給大家 ,也是好久沒有寫博客了。廢話不多說 ,直接上代碼。
本次項目是 用maven 管理的.開發工具 eclipse
在pom.xml文件中,中關于redis的配置:
org.springframework.data
spring-data-redis
1.0.2.RELEASE
redis.clients
jedis
2.1.0
在 applicationContext.xml 中關于redis的配置,<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
在web.xml<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
Archetype Created Web Application
contextConfigLocation
classpath:spring-mybatis.xml,classpath:applicationContext.xml
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
true
encoding
UTF-8
encodingFilter
/*
org.springframework.web.context.ContextLoaderListener
org.springframework.web.util.IntrospectorCleanupListener
SpringMVC
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:spring-mvc.xml
1
true
SpringMVC
/
/index.jsp
由于是入門的很簡單的demo ,所以直接在 寫Controllerpackage com.basessm.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("redis")
public class RedisController {
@Autowired
private StringRedisTemplate redisTemplate;// redis操作模板
@RequestMapping("test1")
public void test1() {
redisTemplate.opsForValue().set("fruit3","apple3");
System.out.println("success1");
}
@RequestMapping("test2")
public void test2() {
redisTemplate.opsForValue().set("aliceWang","alice2");
String a = redisTemplate.opsForValue().get("aliceWang");
System.out.println("success2");
System.out.println("a:" + a);
}
}
這樣就已經完成了一個 很基礎,很簡單的 demo了,在運行項目之前一定要記得先把redis-server 啟動起來!
總結
以上是生活随笔為你收集整理的java 内存数据库 sql_ssm+redis +Maven用于内存数据库 (No Sql)入门demo的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java sqlserver ssl_拦
- 下一篇: java中 下列不合法的语句_在Java