20 skills found
getActivity / StudioPluginsAndroid Studio 精品插件合集,不在于多只在于精
alibaba / JsonLube为了高效地将Json对象转化成Java bean对象,传统上我们是在运行是利用反射来实现。但是在移动平台上,面对复杂的Json,采用反射的方式往往性能比较差,为了追求极致的性能,我们可以采用Android原生的Json库进行解析。但是面对一个复杂的大Json,基于原生Json库去手动解析工作量太大,且容易出错。JsonLube是为此而设计的。JsonLube会在编译期自动生成Json解析代码,用户使用方式简单,但是却能收获原生解析的性能。
caijiahao / SpringMvcPlusMongo慕课网 首页 实战 路径 猿问 手记 登录 注册 11.11 Python 手记 \ 史上最全,最详idea搭建springdata+mongoDB+maven+springmvc 史上最全,最详idea搭建springdata+mongoDB+maven+springmvc 原创 2016-10-21 10:54:297759浏览2评论 作为IT届的小弟,本篇作为本人的第一篇手记,还希望各位大牛多多指点,以下均为个人学习所得,如有错误,敬请指正。本着服务IT小白的原则,该手记比较详细。由于最近使用postgre开发大型项目,发现了关系型数据库的弊端及查询效率之慢,苦心钻研之下,对nosql的mongoDB从无知到有了初步了解。 项目环境:win10+IntelliJ IDEA2016+maven3.3.9+MongoDB 3.2+JDK1.7+spring4.1.7 推荐网站(适合学习各种知识的基础):http://www.runoob.com/ mongo安装请参考http://www.runoob.com/mongodb/mongodb-window-install.html 由于最近osChina的maven仓库挂掉,推荐大家使用阿里的镜像,速度快的飞起 maven配置:<localRepository>F:\.m2\repository</localRepository> <mirrors> <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors> 这里不实用idea自带maven插件,改用3.3.9 图片描述 项目结构:图片描述 这里dao与mongoDao分别为mongoDB的两种查询方式: dao为JPA的查询方式(请参考springdataJPA) mongoDao使用mongoTemplate,类似于关系型数据库使用的jdbcTemplate 不罗嗦,上代码 先看配置文件 spring-context.xm为最基本的spring配置 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!--扫描service包嗲所有使用注解的类型--> <context:component-scan base-package="com.lida.mongo"/> <!-- 导入mongodb的配置文件 --> <import resource="spring-mongo.xml" /> <!-- 开启注解 --> <context:annotation-config /> </beans> spring-web.xml为springmvc的基本配置 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> <!--配置springmvc--> <!--1.开启springmvc注解模式--> <!--简化配置: (1)主动注册DefaultAnnotationHandlerMapping,AnnotationMethodHandlerAdapter (2)提供一系列功能:数据绑定,数字和日期的format @NumberFormt @DataTimeFormat,xml json默认的读写支持--> <mvc:annotation-driven/> <!--servlet-mapping--> <!--2静态资源默认的servlet配置,(1)允许对静态资源的处理:js,gif (2)允许使用“/”做整体映射--> <!-- 容器默认的DefaultServletHandler处理 所有静态内容与无RequestMapping处理的URL--> <mvc:default-servlet-handler/> <!--3:配置jsp 显示viewResolver--> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/views/"/> <property name="suffix" value=".jsp"/> </bean> <!-- 4自动扫描且只扫描@Controller --> <context:component-scan base-package="com.lida.mongo.controller" /> <!-- 定义无需Controller的url<->view直接映射 --> <mvc:view-controller path="/" view-name="redirect:/goMongo/list"/> </beans> spring-mongo.xml为mongo配置 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mongo="http://www.springframework.org/schema/data/mongo" 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.xsd http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd"> <!-- 加载mongodb的属性配置文件 --> <context:property-placeholder location="classpath:mongo.properties" /> <!-- spring连接mongodb数据库的配置 --> <mongo:mongo-client replica-set="${mongo.hostport}" id="mongo"> <mongo:client-options connections-per-host="${mongo.connectionsPerHost}" threads-allowed-to-block-for-connection-multiplier="${mongo.threadsAllowedToBlockForConnectionMultiplier}" connect-timeout="${mongo.connectTimeout}" max-wait-time="${mongo.maxWaitTime}" socket-timeout="${mongo.socketTimeout}"/> </mongo:mongo-client> <!-- mongo的工厂,通过它来取得mongo实例,dbname为mongodb的数据库名,没有的话会自动创建 --> <mongo:db-factory id="mongoDbFactory" dbname="mongoLida" mongo-ref="mongo" /> <!-- 只要使用这个调用相应的方法操作 --> <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" /> </bean> <!-- mongodb bean的仓库目录,会自动扫描扩展了MongoRepository接口的接口进行注入 --> <mongo:repositories base-package="com.lida.mongo" /> </beans> mongo.properties #mongoDB连接配置 mongo.hostport=127.0.0.1:27017 mongo.connectionsPerHost=8 mongo.threadsAllowedToBlockForConnectionMultiplier=4 #连接超时时间 mongo.connectTimeout=1000 #等待时间 mongo.maxWaitTime=1500 #Socket超时时间 mongo.socketTimeout=1500 pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.liad</groupId> <artifactId>mongo</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>mongo Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <!--使用junit4,注解的方式测试--> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <!--日志--> <!--日志 slf4j,log4j,logback,common-logging--> <!--slf4j是规范/接口--> <!--log4j,logback,common-logging是日志实现 本项目使用slf4j + logback --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.12</version> </dependency> <!--实现slf4j并整合--> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.1.1</version> </dependency> <!--数据库相关--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.22</version> <!--maven工作范围 驱动在真正工作的时候使用,故生命周期改为runtime--> <scope>runtime</scope> </dependency> <!--servlet web相关--> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> </dependency> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.5.4</version> </dependency> <!--spring--> <!--spring核心--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>4.1.7.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>4.1.7.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.1.7.RELEASE</version> </dependency> <!--spring dao--> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-mongodb</artifactId> <version>1.8.0.RELEASE</version> </dependency> <dependency> <groupId>org.mongodb</groupId> <artifactId>mongo-java-driver</artifactId> <version>3.2.2</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>4.1.7.RELEASE</version> </dependency> <!--spring web--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>4.1.7.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>4.1.7.RELEASE</version> </dependency> <!--spring test--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>4.1.7.RELEASE</version> </dependency> <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> <version>3.2.2</version> </dependency> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.3.2</version> </dependency> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>1.10</version> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-framework-bom</artifactId> <version>${spring.version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache-core</artifactId> <version>2.6.9</version> </dependency> </dependencies> </dependencyManagement> <build> <finalName>mongo</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </build> </project> 两个实体类: /** * Created by DuLida on 2016/10/20. */ public class Address { private String city; private String street; private int num; public Address() { } public Address(String city, String street, int num) { this.city = city; this.street = street; this.num = num; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getStreet() { return street; } public void setStreet(String street) { this.street = street; } public int getNum() { return num; } public void setNum(int num) { this.num = num; } @Override public String toString() { return "Address{" + "city='" + city + '\'' + ", street='" + street + '\'' + ", num=" + num + '}'; } } /** * Created by DuLida on 2016/10/20. */ @Document(collection="person") public class Person implements Serializable { @Id private ObjectId id; private String name; private int age; private Address address; public Person() { } public Person( String name, int age, Address address) { this.name = name; this.age = age; this.address = address; } public ObjectId getId() { return id; } public void setId(ObjectId id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public Address getAddress() { return address; } public void setAddress(Address address) { this.address = address; } @Override public String toString() { return "Person{" + "id=" + id + ", name='" + name + '\'' + ", age=" + age + ", address=" + address + '}'; } } JPA的dao,注意这里只要继承MongoRepository不用写注解spring就能认识这是个Repository,MongoRepository提供了基本的增删改查,不用实现便可直接调用,例如testMongo的personDao.save(persons); public interface PersonDao extends MongoRepository<Person, ObjectId> { @Query(value = "{'age' : {'$gte' : ?0, '$lte' : ?1}, 'name':?2 }",fields="{ 'name' : 1, 'age' : 1}") List<Person> findByAge(int age1, int age2, String name); } mongoTemplate的dao /** * Created by DuLida on 2016/10/21. */ public interface PersonMongoDao { List<Person> findAll(); void insertPerson(Person user); void removePerson(String userName); void updatePerson(); List<Person> findForRequery(String userName); } @Repository("personMongoImpl") public class PersonMongoImpl implements PersonMongoDao { @Resource private MongoTemplate mongoTemplate; @Override public List<Person> findAll() { return mongoTemplate.findAll(Person.class,"person"); } @Override public void insertPerson(Person person) { mongoTemplate.insert(person,"person"); } @Override public void removePerson(String userName) { mongoTemplate.remove(Query.query(Criteria.where("name").is(userName)),"person"); } @Override public void updatePerson() { mongoTemplate.updateMulti(Query.query(Criteria.where("age").gt(3).lte(5)), Update.update("age",3),"person"); } @Override public List<Person> findForRequery(String userName) { return mongoTemplate.find(Query.query(Criteria.where("name").is(userName)),Person.class); } } JPA查询的测试类: /** * Created by DuLida on 2016/10/20. */ @RunWith(SpringJUnit4ClassRunner.class) //告诉junit spring配置文件 @ContextConfiguration({"classpath:spring/spring-context.xml","classpath:spring/spring-mongo.xml"}) public class PersonDaoTest { @Resource private PersonDao personDao; /*先往数据库中插入10个person*/ @Test public void testMongo() { List<Person> persons = new ArrayList<Person>(); for (int i = 0; i < 10; i++) { persons.add(new Person("name"+i,i,new Address("石家庄","裕华路",i))); } personDao.save(persons); } @Test public void findMongo() { System.out.println(personDao.findByAge(2,8,"name6")); } } mongoTemplate查询的测试类 /** * Created by DuLida on 2016/10/21. */ @RunWith(SpringJUnit4ClassRunner.class) //告诉junit spring配置文件 @ContextConfiguration({"classpath:spring/spring-context.xml","classpath:spring/spring-mongo.xml"}) public class MongoTemplateTest { @Resource private PersonMongoImpl personMongo; @Test public void testMongoTemplate() { //personMongo.insertPerson(new Person("wukong",24,new Address("石家庄","鑫达路",20))); //personMongo.removePerson("name3"); //personMongo.updatePerson(); //System.out.println(personMongo.findAll()); System.out.println(personMongo.findForRequery("wukong")); } } 注意测试前请先通过testMongo()向数据库中插入数据。 项目源码Git地址,仅供学习使用:https://github.com/dreamSmile/mongo.git 参考资料http://docs.spring.io/spring-data/mongodb/docs/current/reference/html/ 本文原创发布于慕课网 ,转载请注明出处,谢谢合作! 相关标签:JAVAMongoDB 时间丶思考 天才小驴 你好小Song 陈词滥调1 4 人推荐 收藏 相关阅读 JAVA第三季1-9(模拟借书系统)作业 用pkp类,players类,playgame类三步教你写扑克牌游戏 Java入门第三季习题,简易扑克牌游戏 java学习第二季哒哒租车系统 Java入门第二季第六章练习题 请登录后,发表评论 评论(Enter+Ctrl) 全部评论2条 你好小Song2F 多数据源如何配置, 比如多个mongodb数据库再加mysql 1天前回复赞同0 时间丶思考 回复 你好小Song: 41分钟前 就在加一个datasource就行啊,原来mysql的datasource怎么加,现在就怎么加上就行,加上直接用。 回复 你好小Song1F 参考一下, 学习了. 2天前回复赞同0 时间丶思考 JAVA开发工程师 情劫难逃。 3篇手记 3推荐 作者的热门手记 神奇的Canvas贝塞尔曲线画心,程序员的表白 1021浏览18推荐3评论 深入探究setTimeout 和setInterval 44浏览1推荐0评论 网站首页企业合作人才招聘联系我们合作专区关于我们讲师招募常见问题意见反馈友情链接 Copyright © 2016 imooc.com All Rights Reserved | 京ICP备 13046642号-2
xcesco / KriptonA Java/Kotlin library for Android platform, to manage bean's persistence in SQLite, SharedPreferences, JSON, XML, Properties, Yaml, CBOR.
dschulten / Hydra JavaAnnotate your Java beans and serialize them as json-ld with hydra
kordamp / Json LibJSON-lib is a java library for transforming beans, maps, collections, java arrays and XML to JSON and back again to beans and DynaBeans.
linsage / Java2jsonA simple plugin for converting Java bean to JSON in IntelliJ IDEA
relvaner / Tools4j ValidatorValidation Framework. Useful for Java Swing applications or any kind of data validation with special prerequisites. Easy to perform validation of the popular Java data types without Java Beans concept. Constraints storable in JSON format. Dynamic validation and simple business rules approach.
svanimpe / Reminders JavaeeReminders, a complete Java EE 7 RESTful webservice example including JPA, Bean Validation, JAX-RS, JSON, CDI, JUnit, Mockito, Arquillian and Maven. HTML5, jQuery and Twitter Bootstrap are used for the front-end.
genghaizhou / Json Tool PluginJava Bean To Json or Json-Schema
wecaterpillar / Java Diff KnifeJava数据对比 Diff Util for Java Bean, Collection(List/Map), Tree & Json
wuzhenlin135 / GenerateJsonToJavaBean根据接口自动生成javabean
xiwc / Json.to.beanConvert json string to java bean.
https-github-com-Rama24 / Peretesan.This XML file does not appear to have any style information associated with it. The document tree is shown below. <xsd:schema xmlns="http://www.springframework.org/schema/mvc" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:tool="http://www.springframework.org/schema/tool" targetNamespace="http://www.springframework.org/schema/mvc" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xsd:import namespace="http://www.springframework.org/schema/beans" schemaLocation="https://www.springframework.org/schema/beans/spring-beans-4.3.xsd"/> <xsd:import namespace="http://www.springframework.org/schema/tool" schemaLocation="https://www.springframework.org/schema/tool/spring-tool-4.3.xsd"/> <xsd:element name="annotation-driven"> <xsd:annotation> <xsd:documentation source="java:org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"> <![CDATA[ Configures the annotation-driven Spring MVC Controller programming model. Note that this tag works in Web MVC only, not in Portlet MVC! See org.springframework.web.servlet.config.annotation.EnableWebMvc javadoc for details on code-based alternatives to enabling annotation-driven Spring MVC support. ]]> </xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:all minOccurs="0"> <xsd:element name="path-matching" minOccurs="0"> <xsd:annotation> <xsd:documentation> <![CDATA[ Configures the path matching part of the Spring MVC Controller programming model. Like annotation-driven, code-based alternatives are also documented in EnableWebMvc javadoc. ]]> </xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:attribute name="suffix-pattern" type="xsd:boolean"> <xsd:annotation> <xsd:documentation> <![CDATA[ Whether to use suffix pattern match (".*") when matching patterns to requests. If enabled a method mapped to "/users" also matches to "/users.*". The default value is true. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="trailing-slash" type="xsd:boolean"> <xsd:annotation> <xsd:documentation> <![CDATA[ Whether to match to URLs irrespective of the presence of a trailing slash. If enabled a method mapped to "/users" also matches to "/users/". The default value is true. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="registered-suffixes-only" type="xsd:boolean"> <xsd:annotation> <xsd:documentation> <![CDATA[ Whether suffix pattern matching should work only against path extensions explicitly registered when you configure content negotiation. This is generally recommended to reduce ambiguity and to avoid issues such as when a "." appears in the path for other reasons. The default value is false. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="path-helper" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ The bean name of the UrlPathHelper to use for resolution of lookup paths. Use this to override the default UrlPathHelper with a custom subclass, or to share common UrlPathHelper settings across multiple HandlerMappings and MethodNameResolvers. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="path-matcher" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ The bean name of the PathMatcher implementation to use for matching URL paths against registered URL patterns. Default is AntPathMatcher. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> </xsd:element> <xsd:element name="message-converters" minOccurs="0"> <xsd:annotation> <xsd:documentation> <![CDATA[ Configures one or more HttpMessageConverter types to use for converting @RequestBody method parameters and @ResponseBody method return values. Using this configuration element is optional. HttpMessageConverter registrations provided here will take precedence over HttpMessageConverter types registered by default. Also see the register-defaults attribute if you want to turn off default registrations entirely. ]]> </xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:sequence> <xsd:choice maxOccurs="unbounded"> <xsd:element ref="beans:bean"> <xsd:annotation> <xsd:documentation> <![CDATA[ An HttpMessageConverter bean definition. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element ref="beans:ref"> <xsd:annotation> <xsd:documentation> <![CDATA[ A reference to an HttpMessageConverter bean. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> </xsd:choice> </xsd:sequence> <xsd:attribute name="register-defaults" type="xsd:boolean" default="true"> <xsd:annotation> <xsd:documentation> <![CDATA[ Whether or not default HttpMessageConverter registrations should be added in addition to the ones provided within this element. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> </xsd:element> <xsd:element name="argument-resolvers" minOccurs="0"> <xsd:annotation> <xsd:documentation> <![CDATA[ Configures HandlerMethodArgumentResolver types to support custom controller method argument types. Using this option does not override the built-in support for resolving handler method arguments. To customize the built-in support for argument resolution configure RequestMappingHandlerAdapter directly. ]]> </xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:choice minOccurs="1" maxOccurs="unbounded"> <xsd:element ref="beans:bean" minOccurs="0" maxOccurs="unbounded"> <xsd:annotation> <xsd:documentation> <![CDATA[ The HandlerMethodArgumentResolver (or WebArgumentResolver for backwards compatibility) bean definition. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element ref="beans:ref" minOccurs="0" maxOccurs="unbounded"> <xsd:annotation> <xsd:documentation> <![CDATA[ A reference to a HandlerMethodArgumentResolver bean definition. ]]> </xsd:documentation> <xsd:appinfo> <tool:annotation kind="ref"> <tool:expected-type type="java:org.springframework.web.method.support.HandlerMethodArgumentResolver"/> </tool:annotation> </xsd:appinfo> </xsd:annotation> </xsd:element> </xsd:choice> </xsd:complexType> </xsd:element> <xsd:element name="return-value-handlers" minOccurs="0"> <xsd:annotation> <xsd:documentation> <![CDATA[ Configures HandlerMethodReturnValueHandler types to support custom controller method return value handling. Using this option does not override the built-in support for handling return values. To customize the built-in support for handling return values configure RequestMappingHandlerAdapter directly. ]]> </xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:choice minOccurs="1" maxOccurs="unbounded"> <xsd:element ref="beans:bean" minOccurs="0" maxOccurs="unbounded"> <xsd:annotation> <xsd:documentation> <![CDATA[ The HandlerMethodReturnValueHandler bean definition. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element ref="beans:ref" minOccurs="0" maxOccurs="unbounded"> <xsd:annotation> <xsd:documentation> <![CDATA[ A reference to a HandlerMethodReturnValueHandler bean definition. ]]> </xsd:documentation> <xsd:appinfo> <tool:annotation kind="ref"> <tool:expected-type type="java:org.springframework.web.method.support.HandlerMethodReturnValueHandler"/> </tool:annotation> </xsd:appinfo> </xsd:annotation> </xsd:element> </xsd:choice> </xsd:complexType> </xsd:element> <xsd:element name="async-support" minOccurs="0"> <xsd:annotation> <xsd:documentation> <![CDATA[ Configure options for asynchronous request processing. ]]> </xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:all minOccurs="0"> <xsd:element name="callable-interceptors" minOccurs="0"> <xsd:annotation> <xsd:documentation> <![CDATA[ The ordered set of interceptors that intercept the lifecycle of concurrently executed requests, which start after a controller returns a java.util.concurrent.Callable. ]]> </xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:sequence> <xsd:element ref="beans:bean" minOccurs="1" maxOccurs="unbounded"> <xsd:annotation> <xsd:documentation> <![CDATA[ Registers a CallableProcessingInterceptor. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="deferred-result-interceptors" minOccurs="0"> <xsd:annotation> <xsd:documentation> <![CDATA[ The ordered set of interceptors that intercept the lifecycle of concurrently executed requests, which start after a controller returns a DeferredResult. ]]> </xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:sequence> <xsd:element ref="beans:bean" minOccurs="1" maxOccurs="unbounded"> <xsd:annotation> <xsd:documentation> <![CDATA[ Registers a DeferredResultProcessingInterceptor. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:all> <xsd:attribute name="task-executor" type="xsd:string"> <xsd:annotation> <xsd:documentation source="java:org.springframework.core.task.AsyncTaskExecutor"> <![CDATA[ The bean name of a default AsyncTaskExecutor to use when a controller method returns a {@link Callable}. Controller methods can override this default on a per-request basis by returning an AsyncTask. By default, a SimpleAsyncTaskExecutor is used which does not re-use threads and is not recommended for production. ]]> </xsd:documentation> <xsd:appinfo> <tool:annotation kind="ref"> <tool:expected-type type="java:org.springframework.core.task.AsyncTaskExecutor"/> </tool:annotation> </xsd:appinfo> </xsd:annotation> </xsd:attribute> <xsd:attribute name="default-timeout" type="xsd:long"> <xsd:annotation> <xsd:documentation> <![CDATA[ Specify the amount of time, in milliseconds, before asynchronous request handling times out. In Servlet 3, the timeout begins after the main request processing thread has exited and ends when the request is dispatched again for further processing of the concurrently produced result. If this value is not set, the default timeout of the underlying implementation is used, e.g. 10 seconds on Tomcat with Servlet 3. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> </xsd:element> </xsd:all> <xsd:attribute name="conversion-service" type="xsd:string"> <xsd:annotation> <xsd:documentation source="java:org.springframework.core.convert.ConversionService"> <![CDATA[ The bean name of the ConversionService that is to be used for type conversion during field binding. This attribute is not required, and only needs to be specified if custom converters need to be configured. If not specified, a default FormattingConversionService is registered with converters to/from common value types. ]]> </xsd:documentation> <xsd:appinfo> <tool:annotation kind="ref"> <tool:expected-type type="java:org.springframework.core.convert.ConversionService"/> </tool:annotation> </xsd:appinfo> </xsd:annotation> </xsd:attribute> <xsd:attribute name="validator" type="xsd:string"> <xsd:annotation> <xsd:documentation source="java:org.springframework.validation.Validator"> <![CDATA[ The bean name of the Validator that is to be used to validate Controller model objects. This attribute is not required, and only needs to be specified if a custom Validator needs to be configured. If not specified, JSR-303 validation will be installed if a JSR-303 provider is present on the classpath. ]]> </xsd:documentation> <xsd:appinfo> <tool:annotation kind="ref"> <tool:expected-type type="java:org.springframework.validation.Validator"/> </tool:annotation> </xsd:appinfo> </xsd:annotation> </xsd:attribute> <xsd:attribute name="content-negotiation-manager" type="xsd:string"> <xsd:annotation> <xsd:documentation source="java:org.springframework.web.accept.ContentNegotiationManager"> <![CDATA[ The bean name of a ContentNegotiationManager that is to be used to determine requested media types. If not specified, a default ContentNegotiationManager is configured that checks the request path extension first and the "Accept" header second where path extensions such as ".json", ".xml", ".atom", and ".rss" are recognized if Jackson, JAXB2, or the Rome libraries are available. As a fallback option, the path extension is also used to perform a lookup through the ServletContext and the Java Activation Framework (if available). ]]> </xsd:documentation> <xsd:appinfo> <tool:annotation kind="ref"> <tool:expected-type type="java:org.springframework.web.accept.ContentNegotiationManager"/> </tool:annotation> </xsd:appinfo> </xsd:annotation> </xsd:attribute> <xsd:attribute name="message-codes-resolver" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ The bean name of a MessageCodesResolver to use to build message codes from data binding and validation error codes. This attribute is not required. If not specified the DefaultMessageCodesResolver is used. ]]> </xsd:documentation> <xsd:appinfo> <tool:annotation kind="ref"> <tool:expected-type type="java:org.springframework.validation.MessageCodesResolver"/> </tool:annotation> </xsd:appinfo> </xsd:annotation> </xsd:attribute> <xsd:attribute name="enable-matrix-variables" type="xsd:boolean"> <xsd:annotation> <xsd:documentation> <![CDATA[ Matrix variables can appear in any path segment, each matrix variable separated with a ";" (semicolon). For example "/cars;color=red;year=2012". By default, they're removed from the URL. If this property is set to true, matrix variables are not removed from the URL, and the request mapping pattern must use URI variable in path segments where matrix variables are expected. For example "/{cars}". Matrix variables can then be injected into a controller method with @MatrixVariable. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="ignore-default-model-on-redirect" type="xsd:boolean"> <xsd:annotation> <xsd:documentation> <![CDATA[ By default, the content of the "default" model is used both during rendering and redirect scenarios. Alternatively a controller method can declare a RedirectAttributes argument and use it to provide attributes for a redirect. Setting this flag to true ensures the "default" model is never used in a redirect scenario even if a RedirectAttributes argument is not declared. Setting it to false means the "default" model may be used in a redirect if the controller method doesn't declare a RedirectAttributes argument. The default setting is false but new applications should consider setting it to true. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> </xsd:element> <xsd:complexType name="content-version-strategy"> <xsd:annotation> <xsd:documentation source="org.springframework.web.servlet.resource.ContentVersionStrategy"> <![CDATA[ A VersionStrategy that calculates an Hex MD5 hashes from the content of the resource and appends it to the file name, e.g. "styles/main-e36d2e05253c6c7085a91522ce43a0b4.css". ]]> </xsd:documentation> </xsd:annotation> <xsd:attribute name="patterns" type="xsd:string" use="required"/> </xsd:complexType> <xsd:complexType name="fixed-version-strategy"> <xsd:annotation> <xsd:documentation source="org.springframework.web.servlet.resource.FixedVersionStrategy"> <![CDATA[ A VersionStrategy that relies on a fixed version applied as a request path prefix, e.g. reduced SHA, version name, release date, etc. ]]> </xsd:documentation> </xsd:annotation> <xsd:attribute name="version" type="xsd:string" use="required"/> <xsd:attribute name="patterns" type="xsd:string" use="required"/> </xsd:complexType> <xsd:complexType name="resource-version-strategy"> <xsd:annotation> <xsd:documentation source="org.springframework.web.servlet.resource.VersionStrategy"> <![CDATA[ A strategy for extracting and embedding a resource version in its URL path. ]]> </xsd:documentation> </xsd:annotation> <xsd:choice minOccurs="1" maxOccurs="1"> <xsd:element ref="beans:bean"> <xsd:annotation> <xsd:documentation source="org.springframework.web.servlet.resource.VersionStrategy"> <![CDATA[ A VersionStrategy bean definition. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element ref="beans:ref"> <xsd:annotation> <xsd:documentation source="org.springframework.web.servlet.resource.VersionStrategy"> <![CDATA[ A reference to a VersionStrategy bean. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> </xsd:choice> <xsd:attribute name="patterns" type="xsd:string" use="required"/> </xsd:complexType> <xsd:complexType name="version-resolver"> <xsd:annotation> <xsd:documentation source="org.springframework.web.servlet.resource.VersionResourceResolver"> <![CDATA[ Resolves request paths containing a version string that can be used as part of an HTTP caching strategy in which a resource is cached with a far future date (e.g. 1 year) and cached until the version, and therefore the URL, is changed. ]]> </xsd:documentation> </xsd:annotation> <xsd:choice maxOccurs="unbounded"> <xsd:element type="content-version-strategy" name="content-version-strategy"/> <xsd:element type="fixed-version-strategy" name="fixed-version-strategy"/> <xsd:element type="resource-version-strategy" name="version-strategy"/> </xsd:choice> </xsd:complexType> <xsd:complexType name="resource-resolvers"> <xsd:annotation> <xsd:documentation source="org.springframework.web.servlet.resource.ResourceResolver"> <![CDATA[ A list of ResourceResolver beans definition and references. A ResourceResolver provides mechanisms for resolving an incoming request to an actual Resource and for obtaining the public URL path that clients should use when requesting the resource. ]]> </xsd:documentation> </xsd:annotation> <xsd:sequence> <xsd:choice maxOccurs="unbounded"> <xsd:element type="version-resolver" name="version-resolver"/> <xsd:element ref="beans:bean"> <xsd:annotation> <xsd:documentation source="org.springframework.web.servlet.resource.ResourceResolver"> <![CDATA[ A ResourceResolver bean definition. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element ref="beans:ref"> <xsd:annotation> <xsd:documentation source="org.springframework.web.servlet.resource.ResourceResolver"> <![CDATA[ A reference to a ResourceResolver bean. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> </xsd:choice> </xsd:sequence> </xsd:complexType> <xsd:complexType name="resource-transformers"> <xsd:annotation> <xsd:documentation source="org.springframework.web.servlet.resource.ResourceTransformer"> <![CDATA[ A list of ResourceTransformer beans definition and references. A ResourceTransformer provides mechanisms for transforming the content of a resource. ]]> </xsd:documentation> </xsd:annotation> <xsd:sequence> <xsd:choice maxOccurs="unbounded"> <xsd:element ref="beans:bean"> <xsd:annotation> <xsd:documentation source="org.springframework.web.servlet.resource.ResourceTransformer"> <![CDATA[ A ResourceTransformer bean definition. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element ref="beans:ref"> <xsd:annotation> <xsd:documentation source="org.springframework.web.servlet.resource.ResourceTransformer"> <![CDATA[ A reference to a ResourceTransformer bean. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> </xsd:choice> </xsd:sequence> </xsd:complexType> <xsd:complexType name="resource-chain"> <xsd:annotation> <xsd:documentation source="org.springframework.web.servlet.config.annotation.ResourceChainRegistration"> <![CDATA[ Assists with the registration of resource resolvers and transformers. Unless set to "false", the auto-registration adds default Resolvers (a PathResourceResolver) and Transformers (CssLinkResourceTransformer, if a VersionResourceResolver has been manually registered). The resource-cache attribute sets whether to cache the result of resource resolution/transformation; setting this to "true" is recommended for production (and "false" for development). A custom Cache can be configured if a CacheManager is provided as a bean reference in the "cache-manager" attribute, and the cache name provided in the "cache-name" attribute. ]]> </xsd:documentation> </xsd:annotation> <xsd:sequence> <xsd:element name="resolvers" type="resource-resolvers" minOccurs="0" maxOccurs="1"/> <xsd:element name="transformers" type="resource-transformers" minOccurs="0" maxOccurs="1"/> </xsd:sequence> <xsd:attribute name="resource-cache" type="xsd:boolean" use="required"> <xsd:annotation> <xsd:documentation> <![CDATA[ Whether the resource chain should cache resource resolution. Note that the resource content itself won't be cached, but rather Resource instances. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="auto-registration" type="xsd:boolean" default="true" use="optional"> <xsd:annotation> <xsd:documentation> <![CDATA[ Whether to register automatically ResourceResolvers and ResourceTransformers. Setting this property to "false" means that it gives developers full control over the registration process. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="cache-manager" type="xsd:string" use="optional"> <xsd:annotation> <xsd:documentation> <![CDATA[ The name of the Cache Manager to cache resource resolution. By default, a ConcurrentCacheMap will be used. Since Resources aren't serializable and can be dependent on the application host, one should not use a distributed cache but rather an in-memory cache. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="cache-name" type="xsd:string" use="optional"> <xsd:annotation> <xsd:documentation> <![CDATA[ The cache name to use in the configured cache manager. Will use "spring-resource-chain-cache" by default. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> <xsd:complexType name="cache-control"> <xsd:annotation> <xsd:documentation source="org.springframework.web.cache.CacheControl"> <![CDATA[ Generates "Cache-Control" HTTP response headers. ]]> </xsd:documentation> </xsd:annotation> <xsd:attribute name="must-revalidate" type="xsd:boolean" use="optional"> <xsd:annotation> <xsd:documentation> <![CDATA[ Adds a "must-revalidate" directive in the Cache-Control header. This indicates that caches should revalidate the cached response when it's become stale. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="no-cache" type="xsd:boolean" use="optional"> <xsd:annotation> <xsd:documentation> <![CDATA[ Adds a "no-cache" directive in the Cache-Control header. This indicates that caches should always revalidate cached response with the server. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="no-store" type="xsd:boolean" use="optional"> <xsd:annotation> <xsd:documentation> <![CDATA[ Adds a "no-store" directive in the Cache-Control header. This indicates that caches should never cache the response. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="no-transform" type="xsd:boolean" use="optional"> <xsd:annotation> <xsd:documentation> <![CDATA[ Adds a "no-transform" directive in the Cache-Control header. This indicates that caches should never transform (i.e. compress, optimize) the response content. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="cache-public" type="xsd:boolean" use="optional"> <xsd:annotation> <xsd:documentation> <![CDATA[ Adds a "public" directive in the Cache-Control header. This indicates that any cache MAY store the response. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="cache-private" type="xsd:boolean" use="optional"> <xsd:annotation> <xsd:documentation> <![CDATA[ Adds a "private" directive in the Cache-Control header. This indicates that the response is intended for a single user and may not be stored by shared caches. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="proxy-revalidate" type="xsd:boolean" use="optional"> <xsd:annotation> <xsd:documentation> <![CDATA[ Adds a "proxy-revalidate" directive in the Cache-Control header. This directive has the same meaning as the "must-revalidate" directive, except it only applies to shared caches. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="max-age" type="xsd:int" use="optional"> <xsd:annotation> <xsd:documentation> <![CDATA[ Adds a "max-age" directive in the Cache-Control header. This indicates that the response should be cached for the given number of seconds. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="s-maxage" type="xsd:int" use="optional"> <xsd:annotation> <xsd:documentation> <![CDATA[ Adds a "s-maxage" directive in the Cache-Control header. This directive has the same meaning as the "max-age" directive, except it only applies to shared caches. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="stale-while-revalidate" type="xsd:int" use="optional"> <xsd:annotation> <xsd:documentation> <![CDATA[ Adds a "stale-while-revalidate" directive in the Cache-Control header. This indicates that caches may serve the response after it becomes stale up to the given number of seconds. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="stale-if-error" type="xsd:int" use="optional"> <xsd:annotation> <xsd:documentation> <![CDATA[ Adds a "stale-if-error" directive in the Cache-Control header. When an error is encountered, a cached stale response may be used for the given number of seconds. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> <xsd:element name="resources"> <xsd:annotation> <xsd:documentation source="java:org.springframework.web.servlet.resource.ResourceHttpRequestHandler"> <![CDATA[ Configures a handler for serving static resources such as images, js, and, css files with cache headers optimized for efficient loading in a web browser. Allows resources to be served out of any path that is reachable via Spring's Resource handling. ]]> </xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:sequence> <xsd:element name="cache-control" type="cache-control" minOccurs="0" maxOccurs="1"/> <xsd:element name="resource-chain" type="resource-chain" minOccurs="0" maxOccurs="1"/> </xsd:sequence> <xsd:attribute name="mapping" use="required" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ The URL mapping pattern within the current Servlet context to use for serving resources from this handler, such as "/resources/**" ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="location" use="required" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ The resource location from which to serve static content, specified at a Spring Resource pattern. Each location must point to a valid directory. Multiple locations may be specified as a comma-separated list, and the locations will be checked for a given resource in the order specified. For example, a value of "/, classpath:/META-INF/public-web-resources/" will allow resources to be served both from the web app root and from any JAR on the classpath that contains a /META-INF/public-web-resources/ directory, with resources in the web app root taking precedence. For URL-based resources (e.g. files, HTTP URLs, etc) this property supports a special prefix to indicate the charset associated with the URL so that relative paths appended to it can be encoded correctly, e.g. "[charset=Windows-31J]https://example.org/path". ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="cache-period" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ Specifies the cache period for the resources served by this resource handler, in seconds. The default is to not send any cache headers but rather to rely on last-modified timestamps only. Set this to 0 in order to send cache headers that prevent caching, or to a positive number of seconds in order to send cache headers with the given max-age value. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="order" type="xsd:token"> <xsd:annotation> <xsd:documentation> <![CDATA[ Specifies the order of the HandlerMapping for the resource handler. The default order is Ordered.LOWEST_PRECEDENCE - 1. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> </xsd:element> <xsd:element name="default-servlet-handler"> <xsd:annotation> <xsd:documentation source="java:org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler"> <![CDATA[ Configures a handler for serving static resources by forwarding to the Servlet container's default Servlet. Use of this handler allows using a "/" mapping with the DispatcherServlet while still utilizing the Servlet container to serve static resources. This handler will forward all requests to the default Servlet. Therefore it is important that it remains last in the order of all other URL HandlerMappings. That will be the case if you use the "annotation-driven" element or alternatively if you are setting up your customized HandlerMapping instance be sure to set its "order" property to a value lower than that of the DefaultServletHttpRequestHandler, which is Integer.MAX_VALUE. ]]> </xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:attribute name="default-servlet-name" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ The name of the default Servlet to forward to for static resource requests. The handler will try to autodetect the container's default Servlet at startup time using a list of known names. If the default Servlet cannot be detected because of using an unknown container or because it has been manually configured, the servlet name must be set explicitly. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> </xsd:element> <xsd:element name="interceptors"> <xsd:annotation> <xsd:documentation> <![CDATA[ The ordered set of interceptors that intercept HTTP Servlet Requests handled by Controllers. Interceptors allow requests to be pre/post processed before/after handling. Each interceptor must implement the org.springframework.web.servlet.HandlerInterceptor or org.springframework.web.context.request.WebRequestInterceptor interface. The interceptors in this set are automatically detected by every registered HandlerMapping. The URI paths each interceptor applies to are configurable. ]]> </xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:choice maxOccurs="unbounded"> <xsd:choice> <xsd:element ref="beans:bean"> <xsd:annotation> <xsd:documentation> <![CDATA[ Registers an interceptor that intercepts every request regardless of its URI path.. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element ref="beans:ref"> <xsd:annotation> <xsd:documentation> <![CDATA[ Registers an interceptor that intercepts every request regardless of its URI path.. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> </xsd:choice> <xsd:element name="interceptor"> <xsd:annotation> <xsd:documentation source="java:org.springframework.web.servlet.handler.MappedInterceptor"> <![CDATA[ Registers an interceptor that interceptors requests sent to one or more URI paths. ]]> </xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:sequence> <xsd:element name="mapping" maxOccurs="unbounded"> <xsd:complexType> <xsd:attribute name="path" type="xsd:string" use="required"> <xsd:annotation> <xsd:documentation> <![CDATA[ A path into the application intercepted by this interceptor. Exact path mapping URIs (such as "/myPath") are supported as well as Ant-stype path patterns (such as /myPath/**). ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> </xsd:element> <xsd:element name="exclude-mapping" minOccurs="0" maxOccurs="unbounded"> <xsd:complexType> <xsd:attribute name="path" type="xsd:string" use="required"> <xsd:annotation> <xsd:documentation> <![CDATA[ A path into the application that should not be intercepted by this interceptor. Exact path mapping URIs (such as "/admin") are supported as well as Ant-stype path patterns (such as /admin/**). ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> </xsd:element> <xsd:choice> <xsd:element ref="beans:bean"> <xsd:annotation> <xsd:documentation> <![CDATA[ The interceptor's bean definition. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element ref="beans:ref"> <xsd:annotation> <xsd:documentation> <![CDATA[ A reference to an interceptor bean. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> </xsd:choice> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:choice> <xsd:attribute name="path-matcher" type="xsd:string"> <xsd:annotation> <xsd:documentation source="java:org.springframework.util.PathMatcher"> <![CDATA[ The bean name of a PathMatcher implementation to use with nested interceptors. This is an optional, advanced property required only if using custom PathMatcher implementations that support mapping metadata other than the Ant path patterns supported by default. ]]> </xsd:documentation> <xsd:appinfo> <tool:annotation kind="ref"> <tool:expected-type type="java:org.springframework.util.PathMatcher"/> </tool:annotation> </xsd:appinfo> </xsd:annotation> </xsd:attribute> </xsd:complexType> </xsd:element> <xsd:element name="view-controller"> <xsd:annotation> <xsd:documentation source="java:org.springframework.web.servlet.mvc.ParameterizableViewController"> <![CDATA[ Map a simple (logic-less) view controller to a specific URL path (or pattern) in order to render a response with a pre-configured status code and view. ]]> </xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:attribute name="path" type="xsd:string" use="required"> <xsd:annotation> <xsd:documentation> <![CDATA[ The URL path (or pattern) the controller is mapped to. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="view-name" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ Set the view name to return. Optional. If not specified, the view controller will return null as the view name in which case the configured RequestToViewNameTranslator will select the view name. The DefaultRequestToViewNameTranslator for example translates "/foo/bar" to "foo/bar". ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="status-code" type="xsd:int"> <xsd:annotation> <xsd:documentation> <![CDATA[ Set the status code to set on the response. Optional. If not set the response status will be 200 (OK). ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> </xsd:element> <xsd:element name="redirect-view-controller"> <xsd:annotation> <xsd:documentation source="java:org.springframework.web.servlet.mvc.ParameterizableViewController"> <![CDATA[ Map a simple (logic-less) view controller to the given URL path (or pattern) in order to redirect to another URL. ]]> </xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:attribute name="path" type="xsd:string" use="required"> <xsd:annotation> <xsd:documentation> <![CDATA[ The URL path (or pattern) the controller is mapped to. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="redirect-url" type="xsd:string" use="required"> <xsd:annotation> <xsd:documentation> <![CDATA[ By default, the redirect URL is expected to be relative to the current ServletContext, i.e. as relative to the web application root. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="status-code" type="xsd:int"> <xsd:annotation> <xsd:documentation> <![CDATA[ Set the specific redirect 3xx status code to use. If not set, org.springframework.web.servlet.view.RedirectView will select MOVED_TEMPORARILY (302) by default. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="context-relative" type="xsd:boolean"> <xsd:annotation> <xsd:documentation> <![CDATA[ Whether to interpret a given redirect URL that starts with a slash ("/") as relative to the current ServletContext, i.e. as relative to the web application root. The default is "true". ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="keep-query-params" type="xsd:boolean"> <xsd:annotation> <xsd:documentation> <![CDATA[ Whether to propagate the query parameters of the current request through to the target redirect URL. The default is "false". ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> </xsd:element> <xsd:element name="status-controller"> <xsd:annotation> <xsd:documentation source="java:org.springframework.web.servlet.mvc.ParameterizableViewController"> <![CDATA[ Map a simple (logic-less) controller to the given URL path (or pattern) in order to sets the response status to the given code without rendering a body. ]]> </xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:attribute name="path" type="xsd:string" use="required"> <xsd:annotation> <xsd:documentation> <![CDATA[ The URL path (or pattern) the controller is mapped to. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="status-code" type="xsd:int" use="required"> <xsd:annotation> <xsd:documentation> <![CDATA[ The status code to set on the response. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> </xsd:element> <xsd:complexType name="contentNegotiationType"> <xsd:all> <xsd:element name="default-views" minOccurs="0"> <xsd:complexType> <xsd:sequence> <xsd:choice maxOccurs="unbounded"> <xsd:element ref="beans:bean"> <xsd:annotation> <xsd:documentation> <![CDATA[ A bean definition for an org.springframework.web.servlet.View class. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element ref="beans:ref"> <xsd:annotation> <xsd:documentation> <![CDATA[ A reference to a bean for an org.springframework.web.servlet.View class. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> </xsd:choice> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:all> <xsd:attribute name="use-not-acceptable" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ Indicate whether a 406 Not Acceptable status code should be returned if no suitable view can be found. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> <xsd:complexType name="urlViewResolverType"> <xsd:attribute name="prefix" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ The prefix that gets prepended to view names when building a URL. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="suffix" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ The suffix that gets appended to view names when building a URL. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="cache-views" type="xsd:boolean"> <xsd:annotation> <xsd:documentation> <![CDATA[ Enable or disable thew caching of resolved views. Default is "true": caching is enabled. Disable this only for debugging and development. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="view-class" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ The view class that should be used to create views. Configure this if you want to provide a custom View implementation, typically a ub-class of the expected View type. ]]> </xsd:documentation> <xsd:appinfo> <tool:annotation kind="ref"> <tool:expected-type type="java:java.lang.Class"/> </tool:annotation> </xsd:appinfo> </xsd:annotation> </xsd:attribute> <xsd:attribute name="view-names" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ Set the view names (or name patterns) that can be handled by this view resolver. View names can contain simple wildcards such that 'my*', '*Report' and '*Repo*' will all match the view name 'myReport'. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> <xsd:element name="view-resolvers"> <xsd:annotation> <xsd:documentation> <![CDATA[ Configure a chain of ViewResolver instances to resolve view names returned from controllers into actual view instances to use for rendering. All registered resolvers are wrapped in a single (composite) ViewResolver with its order property set to 0 so that other external resolvers may be ordere ]]> <![CDATA[ d before or after it. When content negotiation is enabled the order property is set to highest priority instead with the ContentNegotiatingViewResolver encapsulating all other registered view resolver instances. That way the resolvers registered through the MVC namespace form self-encapsulated resolver chain. ]]> </xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:choice minOccurs="1" maxOccurs="unbounded"> <xsd:element name="content-negotiation" type="contentNegotiationType"> <xsd:annotation> <xsd:documentation> <![CDATA[ Registers a ContentNegotiatingViewResolver with the list of all other registered ViewResolver instances used to set its "viewResolvers" property. See the javadoc of ContentNegotiatingViewResolver for more details. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element name="jsp" type="urlViewResolverType"> <xsd:annotation> <xsd:documentation> <![CDATA[ Register an InternalResourceViewResolver bean for JSP rendering. By default, "/WEB-INF/" is registered as a view name prefix and ".jsp" as a suffix. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element name="tiles" type="urlViewResolverType"> <xsd:annotation> <xsd:documentation> <![CDATA[ Register a TilesViewResolver based on Tiles 3.x. To configure Tiles you must also add a top-level <mvc:tiles-configurer> element or declare a TilesConfigurer bean. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element name="freemarker" type="urlViewResolverType"> <xsd:annotation> <xsd:documentation> <![CDATA[ Register a FreeMarkerViewResolver. By default, ".ftl" is configured as a view name suffix. To configure FreeMarker you must also add a top-level <mvc:freemarker-configurer> element or declare a FreeMarkerConfigurer bean. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element name="groovy" type="urlViewResolverType"> <xsd:annotation> <xsd:documentation> <![CDATA[ Register a GroovyMarkupViewResolver. By default, ".tpl" is configured as a view name suffix. To configure the Groovy markup template engine you must also add a top-level <mvc:groovy-configurer> element or declare a GroovyMarkupConfigurer bean. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element name="script-template" type="urlViewResolverType"> <xsd:annotation> <xsd:documentation> <![CDATA[ Register a ScriptTemplateViewResolver. To configure the Script engine you must also add a top-level <mvc:script-template-configurer> element or declare a ScriptTemplateConfigurer bean. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element name="bean-name" maxOccurs="1"> <xsd:annotation> <xsd:documentation> <![CDATA[ Register a BeanNameViewResolver bean. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element ref="beans:bean"> <xsd:annotation> <xsd:documentation> <![CDATA[ Register a ViewResolver as a direct bean declaration. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element ref="beans:ref"> <xsd:annotation> <xsd:documentation> <![CDATA[ Register a ViewResolver through references to an existing bean declaration. ]]> </xsd:documentation> </xsd:annotation> </xsd:element> </xsd:choice> <xsd:attribute name="order" type="xsd:int"> <xsd:annotation> <xsd:documentation> <![CDATA[ ViewResolver's registered through this element are encapsulated in an instance of org.springframework.web.servlet.view.ViewResolverComposite and follow the order of registration. This attribute determines the order of the ViewResolverComposite itself relative to any additional ViewResolver's (not registered through this element) present in the Spring configuration By default this property is not set, which means the resolver is ordered at Ordered.LOWEST_PRECEDENCE unless content negotiation is enabled in which case the order (if not set explicitly) is changed to Ordered.HIGHEST_PRECEDENCE. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> </xsd:element> <xsd:element name="tiles-configurer"> <xsd:annotation> <xsd:documentation> <![CDATA[ Configure Tiles 3.x by registering a TilesConfigurer bean. This is a shortcut alternative to declaring a TilesConfigurer bean directly. ]]> </xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:sequence> <xsd:element name="definitions" minOccurs="0" maxOccurs="unbounded"> <xsd:complexType> <xsd:attribute name="location" type="xsd:string" use="required"> <xsd:annotation> <xsd:documentation> <![CDATA[ The location of a file containing Tiles definitions (or a Spring resource pattern). If no Tiles definitions are registerd, then "/WEB-INF/tiles.xml" is expected to exists. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> </xsd:element> </xsd:sequence> <xsd:attribute name="check-refresh" type="xsd:boolean"> <xsd:annotation> <xsd:documentation> <![CDATA[ Whether to check Tiles definition files for a refresh at runtime. Default is "false". ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="validate-definitions" type="xsd:boolean"> <xsd:annotation> <xsd:documentation> <![CDATA[ Whether to validate the Tiles XML definitions. Default is "true". ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="definitions-factory" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ The Tiles DefinitionsFactory class to use. Default is Tiles' default. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="preparer-factory" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ The Tiles PreparerFactory class to use. Default is Tiles' default. Consider "org.springframework.web.servlet.view.tiles3.SimpleSpringPreparerFactory" or "org.springframework.web.servlet.view.tiles3.SpringBeanPreparerFactory" (see javadoc). ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> </xsd:element> <xsd:element name="freemarker-configurer"> <xsd:annotation> <xsd:documentation> <![CDATA[ Configure FreeMarker for view resolution by registering a FreeMarkerConfigurer bean. This is a shortcut alternative to declaring a FreeMarkerConfigurer bean directly. ]]> </xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:sequence> <xsd:element name="template-loader-path" minOccurs="0" maxOccurs="unbounded"> <xsd:complexType> <xsd:attribute name="location" type="xsd:string" use="required"> <xsd:annotation> <xsd:documentation> <![CDATA[ The location of a FreeMarker template loader path (or a Spring resource pattern). ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="groovy-configurer"> <xsd:annotation> <xsd:documentation> <![CDATA[ Configure the Groovy markup template engine for view resolution by registering a GroovyMarkupConfigurer bean. This is a shortcut alternative to declaring a GroovyMarkupConfigurer bean directly. ]]> </xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:attribute name="auto-indent" type="xsd:boolean"> <xsd:annotation> <xsd:documentation> <![CDATA[ Whether you want the template engine to render indents automatically. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="cache-templates" type="xsd:boolean"> <xsd:annotation> <xsd:documentation> <![CDATA[ If enabled templates are compiled once for each source (URL or File). It is recommended to keep this flag to true unless you are in development mode and want automatic reloading of templates. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="resource-loader-path" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ The Groovy markup template engine resource loader path via a Spring resource location. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> </xsd:element> <xsd:element name="script-template-configurer"> <xsd:annotation> <xsd:documentation> <![CDATA[ Configure the script engine for view resolution by registering a ScriptTemplateConfigurer bean. This is a shortcut alternative to declaring a ScriptTemplateConfigurer bean directly. ]]> </xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:sequence> <xsd:element name="script" minOccurs="0" maxOccurs="unbounded"> <xsd:complexType> <xsd:attribute name="location" type="xsd:string" use="required"> <xsd:annotation> <xsd:documentation> <![CDATA[ The location of the script to be loaded by the script engine (library or user provided). ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> </xsd:element> </xsd:sequence> <xsd:attribute name="engine-name" type="xsd:string" use="required"> <xsd:annotation> <xsd:documentation> <![CDATA[ The script engine name to use by the view. The script engine must implement Invocable. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="render-object" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ The object where belong the render function. For example, in order to call Mustache.render(), renderObject should be set to Mustache and renderFunction to render. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="render-function" type="xsd:string" use="required"> <xsd:annotation> <xsd:documentation> <![CDATA[ Set the render function name. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="content-type" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ Set the content type to use for the response (text/html by default). ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="charset" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ Set the charset used to read script and template files (UTF-8 by default). ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="resource-loader-path" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ The script engine resource loader path via a Spring resource location. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="shared-engine" type="xsd:boolean"> <xsd:annotation> <xsd:documentation> <![CDATA[ When set to false, use thread-local ScriptEngine instances instead of one single shared instance. This flag should be set to false for those using non thread-safe script engines with templating libraries not designed for concurrency, like Handlebars or React running on Nashorn for example. In this case, Java 8u60 or greater is required due to this bug: https://bugs.openjdk.java.net/browse/JDK-8076099. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> </xsd:element> <xsd:element name="cors"> <xsd:annotation> <xsd:documentation> <![CDATA[ Configure cross origin requests processing. ]]> </xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:sequence> <xsd:element name="mapping" minOccurs="1" maxOccurs="unbounded"> <xsd:annotation> <xsd:documentation> <![CDATA[ Enable cross origin requests processing on the specified path pattern. By default, all origins, GET HEAD POST methods, all headers and credentials are allowed and max age is set to 30 minutes. ]]> </xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:attribute name="path" type="xsd:string" use="required"> <xsd:annotation> <xsd:documentation> <![CDATA[ A path into the application that should handle CORS requests. Exact path mapping URIs (such as "/admin") are supported as well as Ant-stype path patterns (such as /admin/**). ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="allowed-origins" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ Comma-separated list of origins to allow, e.g. "https://domain1.com, https://domain2.com". The special value "*" allows all domains (default). Note that CORS checks use values from "Forwarded" (RFC 7239), "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" headers, if present, in order to reflect the client-originated address. Consider using the ForwardedHeaderFilter in order to choose from a central place whether to extract and use such headers, or whether to discard them. See the Spring Framework reference for more on this filter. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="allowed-methods" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ Comma-separated list of HTTP methods to allow, e.g. "GET, POST". The special value "*" allows all method. By default GET, HEAD and POST methods are allowed. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="allowed-headers" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ Comma-separated list of headers that a pre-flight request can list as allowed for use during an actual request. The special value of "*" allows actual requests to send any header (default). ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="exposed-headers" type="xsd:string"> <xsd:annotation> <xsd:documentation> <![CDATA[ Comma-separated list of response headers other than simple headers (i.e. Cache-Control, Content-Language, Content-Type, Expires, Last-Modified, Pragma) that an actual response might have and can be exposed. Empty by default. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="allow-credentials" type="xsd:boolean"> <xsd:annotation> <xsd:documentation> <![CDATA[ Whether user credentials are supported (true by default). ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="max-age" type="xsd:long"> <xsd:annotation> <xsd:documentation> <![CDATA[ How long, in seconds, the response from a pre-flight request can be cached by clients. 1800 seconds (30 minutes) by default. ]]> </xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema>
mokhtar6847 / Springboot Mobile Redis在线创建方式 网址:https://start.spring.io/ 图片 然后创建Controller、Mapper、Service包 图片 SpringBoot整合Redis 引入Redis依赖 <!--SpringBoot与Redis整合依赖--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> 完整pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.cyb</groupId> <artifactId>chenyb-mobile-redis</artifactId> <version>0.0.1-SNAPSHOT</version> <name>chenyb-mobile-redis</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.projectreactor</groupId> <artifactId>reactor-test</artifactId> <scope>test</scope> </dependency> <!--SpringBoot与Redis整合依赖--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> 设置Redis的Template 图片 RedisConfig.java package com.cyb.mobile.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; /** * @ClassName:RedisConfig * @Description:Redis配置类 * @Author:chenyb * @Date:2020/8/16 11:48 下午 * @Versiion:1.0 */ @Configuration //当前类为配置类 public class RedisConfig { @Bean //redisTemplate注入到Spring容器 public RedisTemplate<String,String> redisTemplate(RedisConnectionFactory factory){ RedisTemplate<String,String> redisTemplate=new RedisTemplate<>(); RedisSerializer<String> redisSerializer = new StringRedisSerializer(); redisTemplate.setConnectionFactory(factory); //key序列化 redisTemplate.setKeySerializer(redisSerializer); //value序列化 redisTemplate.setValueSerializer(redisSerializer); //value hashmap序列化 redisTemplate.setHashKeySerializer(redisSerializer); //key hashmap序列化 redisTemplate.setHashValueSerializer(redisSerializer); return redisTemplate; } } 设置Redis连接信息 图片 # 连接的那个数据库 spring.redis.database=0 # redis服务的ip地址 spring.redis.host=192.168.199.142 # redis端口号 spring.redis.port=6379 # redis的密码,没设置过密码,可为空 spring.redis.password=12345678 Redis工具类 redisTemplate API opsForValue ==》String opsForSet ==》Set opsForHash ==》hash opsForZset ==》SortSet opsForList ==》list队列 RedisUtils.java 图片 package com.cyb.mobile.utils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.*; import org.springframework.stereotype.Service; import java.io.Serializable; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; /** * @ClassName:RedisUtils * @Description:Redis工具类 * @Author:chenyb * @Date:2020/8/17 12:05 上午 * @Versiion:1.0 */ @Service public class RedisUtils { @Autowired private RedisTemplate redisTemplate; private static double size = Math.pow(2, 32); /** * 写入缓存 * * @param key * @param offset 位 8Bit=1Byte * @return */ public boolean setBit(String key, long offset, boolean isShow) { boolean result = false; try { ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue(); operations.setBit(key, offset, isShow); result = true; } catch (Exception e) { e.printStackTrace(); } return result; } /** * 写入缓存 * * @param key * @param offset * @return */ public boolean getBit(String key, long offset) { boolean result = false; try { ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue(); result = operations.getBit(key, offset); } catch (Exception e) { e.printStackTrace(); } return result; } /** * 写入缓存 * * @param key * @param value * @return */ public boolean set(final String key, Object value) { boolean result = false; try { ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue(); operations.set(key, value); result = true; } catch (Exception e) { e.printStackTrace(); } return result; } /** * 写入缓存设置时效时间 * * @param key * @param value * @return */ public boolean set(final String key, Object value, Long expireTime) { boolean result = false; try { ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue(); operations.set(key, value); redisTemplate.expire(key, expireTime, TimeUnit.SECONDS); result = true; } catch (Exception e) { e.printStackTrace(); } return result; } /** * 批量删除对应的value * * @param keys */ public void remove(final String... keys) { for (String key : keys) { remove(key); } } /** * 删除对应的value * * @param key */ public void remove(final String key) { if (exists(key)) { redisTemplate.delete(key); } } /** * 判断缓存中是否有对应的value * * @param key * @return */ public boolean exists(final String key) { return redisTemplate.hasKey(key); } /** * 读取缓存 * * @param key * @return */ public Object get(final String key) { Object result = null; ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue(); result = operations.get(key); return result; } /** * 哈希 添加 * * @param key * @param hashKey * @param value */ public void hmSet(String key, Object hashKey, Object value) { HashOperations<String, Object, Object> hash = redisTemplate.opsForHash(); hash.put(key, hashKey, value); } /** * 哈希获取数据 * * @param key * @param hashKey * @return */ public Object hmGet(String key, Object hashKey) { HashOperations<String, Object, Object> hash = redisTemplate.opsForHash(); return hash.get(key, hashKey); } /** * 列表添加 * * @param k * @param v */ public void lPush(String k, Object v) { ListOperations<String, Object> list = redisTemplate.opsForList(); list.rightPush(k, v); } /** * 列表获取 * * @param k * @param l * @param l1 * @return */ public List<Object> lRange(String k, long l, long l1) { ListOperations<String, Object> list = redisTemplate.opsForList(); return list.range(k, l, l1); } /** * 集合添加 * * @param key * @param value */ public void add(String key, Object value) { SetOperations<String, Object> set = redisTemplate.opsForSet(); set.add(key, value); } /** * 集合获取 * * @param key * @return */ public Set<Object> setMembers(String key) { SetOperations<String, Object> set = redisTemplate.opsForSet(); return set.members(key); } /** * 有序集合添加 * * @param key * @param value * @param scoure */ public void zAdd(String key, Object value, double scoure) { ZSetOperations<String, Object> zset = redisTemplate.opsForZSet(); zset.add(key, value, scoure); } /** * 有序集合获取 * * @param key * @param scoure * @param scoure1 * @return */ public Set<Object> rangeByScore(String key, double scoure, double scoure1) { ZSetOperations<String, Object> zset = redisTemplate.opsForZSet(); redisTemplate.opsForValue(); return zset.rangeByScore(key, scoure, scoure1); } //第一次加载的时候将数据加载到redis中 public void saveDataToRedis(String name) { double index = Math.abs(name.hashCode() % size); long indexLong = new Double(index).longValue(); boolean availableUsers = setBit("availableUsers", indexLong, true); } //第一次加载的时候将数据加载到redis中 public boolean getDataToRedis(String name) { double index = Math.abs(name.hashCode() % size); long indexLong = new Double(index).longValue(); return getBit("availableUsers", indexLong); } /** * 有序集合获取排名 * * @param key 集合名称 * @param value 值 */ public Long zRank(String key, Object value) { ZSetOperations<String, Object> zset = redisTemplate.opsForZSet(); return zset.rank(key,value); } /** * 有序集合获取排名 * * @param key */ public Set<ZSetOperations.TypedTuple<Object>> zRankWithScore(String key, long start,long end) { ZSetOperations<String, Object> zset = redisTemplate.opsForZSet(); Set<ZSetOperations.TypedTuple<Object>> ret = zset.rangeWithScores(key,start,end); return ret; } /** * 有序集合添加 * * @param key * @param value */ public Double zSetScore(String key, Object value) { ZSetOperations<String, Object> zset = redisTemplate.opsForZSet(); return zset.score(key,value); } /** * 有序集合添加分数 * * @param key * @param value * @param scoure */ public void incrementScore(String key, Object value, double scoure) { ZSetOperations<String, Object> zset = redisTemplate.opsForZSet(); zset.incrementScore(key, value, scoure); } /** * 有序集合获取排名 * * @param key */ public Set<ZSetOperations.TypedTuple<Object>> reverseZRankWithScore(String key, long start,long end) { ZSetOperations<String, Object> zset = redisTemplate.opsForZSet(); Set<ZSetOperations.TypedTuple<Object>> ret = zset.reverseRangeByScoreWithScores(key,start,end); return ret; } /** * 有序集合获取排名 * * @param key */ public Set<ZSetOperations.TypedTuple<Object>> reverseZRankWithRank(String key, long start, long end) { ZSetOperations<String, Object> zset = redisTemplate.opsForZSet(); Set<ZSetOperations.TypedTuple<Object>> ret = zset.reverseRangeWithScores(key, start, end); return ret; } } 控制层 图片 RedisController.java package com.cyb.mobile.controller; import com.cyb.mobile.utils.RedisUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * @ClassName:TestController * @Description:Redis控制器 * @Author:chenyb * @Date:2020/8/17 12:07 上午 * @Versiion:1.0 */ @RestController public class RedisController { @Autowired private RedisUtils redisUtils; @RequestMapping("setAndGet") public String test(String k,String v){ redisUtils.set(k,v); return (String) redisUtils.get(k); } } 测试 图片 SpringBoot整合Mybatis 添加依赖 <!--mybatis依赖--> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.3</version> </dependency> <!--mysql驱动--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!--druid--> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.23</version> </dependency> 完整pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.cyb</groupId> <artifactId>chenyb-mobile-redis</artifactId> <version>0.0.1-SNAPSHOT</version> <name>chenyb-mobile-redis</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.projectreactor</groupId> <artifactId>reactor-test</artifactId> <scope>test</scope> </dependency> <!--SpringBoot与Redis整合依赖--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <!--mybatis依赖--> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.3</version> </dependency> <!--mysql驱动--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!--druid--> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.23</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> 设置配置文件 application.properties # 连接的那个数据库 spring.redis.database=0 # redis服务的ip地址 spring.redis.host=192.168.199.142 # redis端口号 spring.redis.port=6379 # redis的密码,没设置过密码,可为空 spring.redis.password=12345678 # 端口号 server.port=8081 # ========================数据库相关配置===================== spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/nba?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai spring.datasource.username=root spring.datasource.password=root # 使用阿里巴巴druid数据源,默认使用自带 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource #开启控制台打印sql mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl # mybatis 下划线转驼峰配置,两者都可以 # mybatis.configuration.mapUnderscoreToCamelCase=true mybatis.configuration.map-underscore-to-camel-case=true # 配置扫描 mybatis.mapper-locations=classpath:mapper/*.xml # 实体类所在的包别名 mybatis.type-aliases-package=com.cyb.mobile.domain 启动类上添加扫描路径 图片 NbaPlayer.java(实体类) 图片 NbaPlayerMapper.xml 图片 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.cyb.mobile.mapper.NbaPlayerMapper"> <select id="ListNbaPlayer" resultType="NbaPlayer"> SELECT * FROM nba_player </select> </mapper> NbaPlayerMapper.java 图片 NbaPlayerService.java 图片 NbaPlayerServiceImpl.java 图片 控制器(Controller) 图片 测试 图片 redis作为mybatis缓存 用户第一次访问的时候获取数据库的值,再次访问时直接从缓存中获取数据 设置缓存过期时间 练手项目,学习强化,点击这里 代码演示 添加FastJSON依赖 <!--fastjson依赖--> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.73</version> </dependency> ~ @RequestMapping("test") public Object test(){ //step1 先从redis中取 String strJson=(String) redisUtils.get("nbaPlayerCache"); if (strJson==null){ System.out.println("从db取值"); // step2如果拿不到则从DB取值 List<NbaPlayer> listNbaPlayer=nbaPlayerService.ListNbaPlayer(); // step3 DB非空情况刷新redis值 if (listNbaPlayer!=null){ redisUtils.set("nbaPlayerCache", JSON.toJSONString(listNbaPlayer)); return listNbaPlayer; } return null; }else { System.out.println("从redis缓存取值"); return JSONObject.parseArray(strJson,NbaPlayer.class); } } 注意 项目8080是对外端口(向外部暴露的端口),区别于内部进程号,查内部端口用ps -ef|grep port,查外部端口用lsof -i:port 图片 图片 压测工具 上面我们已经SpringBoot整合Redis和Mybatis,但是无法知道具体QPS多少,此时我们可以使用压测工具来测压,参考: https://www.cnblogs.com/chenyanbin/p/13332068.html
TheFreeOne / Java Bean To Ts Interface推荐用json2ts之类的插件 ------ IDEA插件 A InteliJ IDEA Plugin - Converte the java bean that receives json in the springboot project to the typescript interface
yunmengjiuzhang / LogXixi用于Android环境,java环境的log打印,可打印任何类型数据,根据android项目环境debug环境自动打开,release环境自动关闭android环境log打印,规范bean对象,json,xml对应log,crash捕捉,disk存储 log crash,回放disk数据
xlate / Jsonapi RvpJSON API server implementation in Java using JAX-RS, Bean Validation, and Java Persistence (JPA)
hoteia / Scribe MappingAdd-on for Scribe project : pojo/bean to map JSON datas with your favorite JSON processor Java library, like Jackson.
QBBILL / Json2sql Sql2Bean将json字符串转化为insert语句后使用jdbcTemplate插入数据库,主键自增 根据sql查询元数据生成bean的java文件