日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

SpringBoot集成SSM、Dubbo、Redis、JSP的案例小結及思路講解

瀏覽:46日期:2023-03-08 10:28:47
目錄1.思路講解2.案例分析2.1 接口工程2.2 服務提供者2.3 服務消費者2.4 啟動測試!!!1.思路講解

這個案例其實就是SpringBoot集成SSM、Dubbo、Redis、JSP,看起來集成了一大堆,感覺挺麻煩的,但實際上并不是很麻煩,下面我來說一下我的思路:

接口工程:存放實體bean和業務接口

服務提供者:它是一個SpringBoot框架web項目,集成MyBatis、Redis

1)pom文件中添加依賴:MyBatis、MySQL驅動、Dubbo、zookeeper、redis、接口工程。

2)配置springboot核心配置文件(連接數據庫、連接redis、dubbo、內嵌tomcat)

服務消費者:它也是一個SpringBoot框架web項目,集成JSP、Dubbo

2)配置springboot核心配置文件(dubbo、內嵌tomcat、視圖解析器)

1)pom文件中添加依賴:Dubbo、zookeeper、接口工程、解析jsp頁面的依賴。

文章比較長,因為代碼比較多,大家一定要有這個耐心去看完,相信我講的還是有點用的!!!

2.案例分析

SpringBoot集成SSM、Dubbo、Redis、JSP的案例小結及思路講解

SpringBoot集成SSM、Dubbo、Redis、JSP的案例小結及思路講解

SpringBoot集成SSM、Dubbo、Redis、JSP的案例小結及思路講解

這里SpringBoot集成MyBatis,我用的是MyBatis逆向工程來直接生成的實體bean、dao、mapper,所以這里首先給出MyBatis逆向工程的配置文件。

這個文件主要是負責生成你項目中的實體bean、dao、mapper,那么再加上集成dubbo的情況下,我們的實體bean是需要放在接口工程中的,而dao、mapper則需要放在服務提供者中,所以在MyBatis逆向工程的配置文件中,需要將實體bean的生成位置改為第一個接口工程的絕對路徑。數據庫這里的表結構和數據,我就不再給出了,大家自行創建一下就可以了。

<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE generatorConfigurationPUBLIC '-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN''http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd'><generatorConfiguration><!-- 指定連接數據庫的 JDBC 驅動包所在位置,指定到你本機的完整路徑 --><classPathEntry location='E:mysql-connector-java-5.1.9.jar'/><!-- 配置 table 表信息內容體,targetRuntime 指定采用 MyBatis3 的版本 --><context targetRuntime='MyBatis3'> <!-- 抑制生成注釋,由于生成的注釋都是英文的,可以不讓它生成 --> <commentGenerator><property name='suppressAllComments' value='true'/> </commentGenerator> <!-- 配置數據庫連接信息 --> <jdbcConnection driverClass='com.mysql.jdbc.Driver' connectionURL='jdbc:mysql://localhost:3306/springboot' userId='root' password='12345678'> </jdbcConnection> <!-- 生成 entity 類,targetPackage 指定 entity 類的包名, targetProject指定生成的 entity 放在 IDEA 的哪個工程下面--> <javaModelGenerator targetPackage='com.szh.springboot.entity'targetProject='D:BaiduNetdiskDownload014-springboot-ssm-dubbo-interfacesrcmainjava'><property name='enableSubPackages' value='false'/><property name='trimStrings' value='false'/> </javaModelGenerator> <!-- 生成 MyBatis 的 Mapper.xml 文件,targetPackage 指定 mapper.xml 文件的包名, targetProject 指定生成的 mapper.xml 放在 IDEA 的哪個工程下面 --> <sqlMapGenerator targetPackage='com.szh.springboot.mapper' targetProject='src/main/java'><property name='enableSubPackages' value='false'/> </sqlMapGenerator> <!-- 生成 MyBatis 的 Mapper 接口類文件,targetPackage 指定 Mapper 接口類的包名, targetProject 指定生成的 Mapper 接口放在 IDEA 的哪個工程下面 --> <javaClientGenerator type='XMLMAPPER' targetPackage='com.szh.springboot.mapper' targetProject='src/main/java'><property name='enableSubPackages' value='false'/> </javaClientGenerator> <!-- 數據庫表名及對應的 Java 模型類名 --> <table tableName='t_student' domainObjectName='Student' enableCountByExample='false' enableUpdateByExample='false' enableDeleteByExample='false' enableSelectByExample='false' selectByExampleQueryId='false'/></context></generatorConfiguration>2.1 接口工程

MyBatis逆向工程生成的實體bean。

package com.szh.springboot.entity; import java.io.Serializable; public class Student implements Serializable { private Integer id; private String name; private Integer age; //getter and setter}

接口服務,其中有兩個方法。

package com.szh.springboot.service; import com.szh.springboot.entity.Student; /** * */public interface StudentService { Student queryStudentById(Integer id); Integer queryAllStudentCount();}2.2 服務提供者

SpringBoot核心配置文件

# 配置內嵌tomcat端口號和上下文根server.port=8081server.servlet.context-path=/ # 設置連接數據庫的信息spring.datasource.driver-class-name=com.mysql.jdbc.Driverspring.datasource.url=jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8spring.datasource.username=rootspring.datasource.password=12345678 # 設置dubbospring.application.name=015-springboot-ssm-dubbo-providerspring.dubbo.server=truespring.dubbo.registry=zookeeper://localhost:2181 # 設置redisspring.redis.host=localhostspring.redis.port=6379

MyBatis逆向工程生成的dao接口和對應的mapper映射文件(這里就做一個簡單的案例,所以只用到了 selectByPrimaryKey、queryAllStudentCount 這兩個方法)

package com.szh.springboot.mapper; import com.szh.springboot.entity.Student; public interface StudentMapper { int deleteByPrimaryKey(Integer id); int insert(Student record); int insertSelective(Student record); Student selectByPrimaryKey(Integer id); int updateByPrimaryKeySelective(Student record); int updateByPrimaryKey(Student record); Integer queryAllStudentCount(); }

<?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.szh.springboot.mapper.StudentMapper'> <resultMap type='com.szh.springboot.entity.Student'> <id column='id' jdbcType='INTEGER' property='id' /> <result column='name' jdbcType='VARCHAR' property='name' /> <result column='age' jdbcType='INTEGER' property='age' /> </resultMap> <sql id='Base_Column_List'> id, name, age </sql> <select parameterType='java.lang.Integer' resultMap='BaseResultMap'> select <include refid='Base_Column_List' /> from t_student where id = #{id,jdbcType=INTEGER} </select> <delete parameterType='java.lang.Integer'> delete from t_student where id = #{id,jdbcType=INTEGER} </delete> <insert parameterType='com.szh.springboot.entity.Student'> insert into t_student (id, name, age ) values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER} ) </insert> <insert parameterType='com.szh.springboot.entity.Student'> insert into t_student <trim prefix='(' suffix=')' suffixOverrides=','> <if test='id != null'>id, </if> <if test='name != null'>name, </if> <if test='age != null'>age, </if> </trim> <trim prefix='values (' suffix=')' suffixOverrides=','> <if test='id != null'>#{id,jdbcType=INTEGER}, </if> <if test='name != null'>#{name,jdbcType=VARCHAR}, </if> <if test='age != null'>#{age,jdbcType=INTEGER}, </if> </trim> </insert> <update parameterType='com.szh.springboot.entity.Student'> update t_student <set> <if test='name != null'>name = #{name,jdbcType=VARCHAR}, </if> <if test='age != null'>age = #{age,jdbcType=INTEGER}, </if> </set> where id = #{id,jdbcType=INTEGER} </update> <update parameterType='com.szh.springboot.entity.Student'> update t_student set name = #{name,jdbcType=VARCHAR}, age = #{age,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER} </update> <select resultType='java.lang.Integer'> select count(*) from t_student </select></mapper>

對接口工程中接口方法的實現,其中包括注入數據庫持久層、注入redis模板類對象。

package com.szh.springboot.service.impl; import com.alibaba.dubbo.config.annotation.Service;import com.szh.springboot.entity.Student;import com.szh.springboot.mapper.StudentMapper;import com.szh.springboot.service.StudentService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.data.redis.core.RedisTemplate;import org.springframework.stereotype.Component; import java.util.concurrent.TimeUnit; /** * */@Component@Service(interfaceClass = StudentService.class,version = '1.0.0',timeout = 15000)public class StudentServiceImpl implements StudentService { @Autowired private StudentMapper studentMapper; @Autowired private RedisTemplate<Object,Object> redisTemplate; @Override public Student queryStudentById(Integer id) {return studentMapper.selectByPrimaryKey(id); } @Override public Integer queryAllStudentCount() { //首先去redis緩存中查詢,如果有:直接使用;如果沒有,去數據庫中查詢并存放到redis緩存中Integer allStudentCount= (Integer) redisTemplate.opsForValue().get('allStudentCount'); //判斷是否有值if (allStudentCount==null) { //此時為空,則去數據庫中查詢 allStudentCount=studentMapper.queryAllStudentCount(); //并存放到redis緩存中 redisTemplate.opsForValue().set('allStudentCount',allStudentCount,30, TimeUnit.SECONDS);}return allStudentCount; } }

pom文件

<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId></dependency> <dependency> <groupId>com.alibaba.spring.boot</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <version>2.0.0</version></dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.4.6</version> <exclusions><exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId></exclusion> </exclusions></dependency><dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</artifactId> <version>0.4</version></dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.4</version></dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.9</version></dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId></dependency> <!-- 接口工程 --><dependency> <groupId>com.szh.springboot</groupId> <artifactId>014-springboot-ssm-dubbo-interface</artifactId> <version>1.0.0</version></dependency> </dependencies> <build> <resources> <resource><directory>src/main/java</directory><includes> <include>**/*.xml</include></includes> </resource></resources> <plugins> <plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId> </plugin> <!--mybatis 代碼自動生成插件--> <plugin><groupId>org.mybatis.generator</groupId><artifactId>mybatis-generator-maven-plugin</artifactId><version>1.3.7</version><configuration> <!--配置文件的位置--> <configurationFile>GeneratorMapper.xml</configurationFile> <verbose>true</verbose> <overwrite>true</overwrite></configuration> </plugin></plugins> </build>

SpringBoot項目啟動入口類

package com.szh.springboot; import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration;import org.mybatis.spring.annotation.MapperScan;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication@MapperScan(basePackages = 'com.szh.springboot.mapper')@EnableDubboConfigurationpublic class Application { public static void main(String[] args) {SpringApplication.run(Application.class, args); } }2.3 服務消費者

SpringBoot核心配置文件

# 配置內嵌tomcat端口號和上下文根server.port=8080server.servlet.context-path=/ # 設置dubbospring.application.name=016-springboot-ssm-dubbo-consumerspring.dubbo.registry=zookeeper://localhost:2181 # 配置視圖解析器spring.mvc.view.prefix=/spring.mvc.view.suffix=.jsp

定義控制層,其中有兩個請求方法

package com.szh.springboot.controller; import com.alibaba.dubbo.config.annotation.Reference;import com.szh.springboot.entity.Student;import com.szh.springboot.service.StudentService;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody; /** * */@Controllerpublic class StudentController { @Reference(interfaceClass = StudentService.class,version = '1.0.0',check = false) private StudentService studentService; @RequestMapping(value = '/student/detail/{id}') public String studentDetail(@PathVariable('id') Integer id,Model model) {Student student=studentService.queryStudentById(id);model.addAttribute('student',student);return 'studentDetail'; } @GetMapping(value = '/student/all/count') public @ResponseBody Object allStudentCount() {Integer allStudentCount=studentService.queryAllStudentCount();return '學生總人數為:' + allStudentCount; } }

pom文件

<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId></dependency> <dependency> <groupId>com.alibaba.spring.boot</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <version>2.0.0</version></dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.4.6</version> <exclusions><exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId></exclusion> </exclusions></dependency><dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</artifactId> <version>0.4</version></dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId></dependency> <!-- 接口工程 --><dependency> <groupId>com.szh.springboot</groupId> <artifactId>014-springboot-ssm-dubbo-interface</artifactId> <version>1.0.0</version></dependency> </dependencies> <build> <resources> <resource><directory>src/main/webapp</directory><targetPath>META-INF/resources</targetPath><includes> <include>*.*</include></includes> </resource></resources> <plugins> <plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId> </plugin></plugins> </build>

響應的jsp頁面、SpringBoot項目啟動入口類

<%@ page contentType='text/html;charset=utf-8' language='java' %><html><head> <title>$</title></head><body> <h3>學生信息</h3> <div>學生編號:${student.id}</div> <div>學生姓名:${student.name}</div> <div>學生年齡:${student.age}</div></body></html>

package com.szh.springboot; import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication@EnableDubboConfigurationpublic class Application { public static void main(String[] args) {SpringApplication.run(Application.class, args); } }2.4 啟動測試!!!

因為我們這個案例是SpringBoot集成SSM、Dubbo、Redis、JSP,同時使用注冊中心。所以啟動的步驟是:

啟動zookeeper注冊中心 zkServer.cmd(我這里為了考慮電腦性能,所以直接就在Windows上啟動了,推薦是在Linux上啟動) 啟動redis服務(redis-server.exe redis,windows.conf 、 redis-cli.exe -h 127.0.0.1 -p 6379) 啟動服務提供者(對應該工程的SpringBoot項目啟動入口類)啟動服務消費者(對應該工程的SpringBoot項目啟動入口類)

SpringBoot集成SSM、Dubbo、Redis、JSP的案例小結及思路講解

SpringBoot集成SSM、Dubbo、Redis、JSP的案例小結及思路講解

SpringBoot集成SSM、Dubbo、Redis、JSP的案例小結及思路講解

測試結果中,可以看到,第一個請求結果拿到了學生信息,第二個請求結果也查詢出了學生數量,而且我們開啟redis服務之后,可以看到發起第二個請求之后,redis緩存中已經有了這個 allStudentCount 數據,經過30秒之后,這個數據會被清除。

以上就是SpringBoot集成SSM、Dubbo、Redis、JSP的案例小結及思路講解的詳細內容,更多關于SpringBoot集成SSM、Dubbo、Redis、JSP的資料請關注好吧啦網其它相關文章!

標簽: Spring
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
久久久精品日韩| 国产亚洲精品美女久久| 91伊人久久| 欧美中文高清| 国产精品久久久久久久免费软件| 日韩**一区毛片| 蜜桃久久精品一区二区| 国产欧美日韩在线观看视频| 国产精品mv在线观看| 国产一区二区三区不卡视频网站| 国产66精品| 亚洲午夜电影| 男人的天堂亚洲一区| 久久亚洲美女| 国产欧美精品| 日本不良网站在线观看| 黄页网站一区| 国产精品一区二区三区美女| 成人在线丰满少妇av| 美女少妇全过程你懂的久久| 免费看精品久久片| 亚洲1区在线观看| 精品一区二区三区的国产在线观看| 欧美羞羞视频| 日本精品一区二区三区在线观看视频| 精品亚洲a∨一区二区三区18| 激情婷婷综合| 国产经典一区| 欧美精选一区二区三区| 91麻豆精品| 亚州av乱码久久精品蜜桃| 国产乱人伦精品一区| 一区在线免费观看| 国产精品毛片久久| 婷婷视频一区二区三区| 成人三级高清视频在线看| 国产一区日韩一区| 久久99影视| 日韩中文字幕麻豆| 欧美成a人国产精品高清乱码在线观看片在线观看久 | 久久亚洲专区| 老鸭窝一区二区久久精品| 亚洲精品黄色| 黄色精品网站| 成人日韩精品| 成人亚洲精品| 久久久91麻豆精品国产一区| 日韩高清不卡在线| 成人av动漫在线观看| 黄色在线观看www| 国产精品国产一区| 国产精品v日韩精品v欧美精品网站 | 亚洲精品乱码久久久久久蜜桃麻豆 | 国产探花在线精品| 婷婷成人av| 久久高清一区| 国产亚洲激情| 蜜臀av亚洲一区中文字幕| 亚洲欧美一区在线| 女人天堂亚洲aⅴ在线观看| 欧美午夜不卡| 日本大胆欧美人术艺术动态| 综合激情网站| 日韩av午夜在线观看| 久久精品99国产国产精| 欧美在线首页| 国产一区二区三区探花| 国产美女高潮在线观看| 日韩精品一区二区三区免费观看| 日韩中文首页| 精精国产xxxx视频在线野外| 亚洲一本视频| 日韩久久一区| 福利片在线一区二区| 久久五月天小说| 日韩成人午夜精品| 丰满少妇一区| 激情欧美一区二区三区| 一区久久精品| 国产精品最新自拍| 在线一区av| 久久夜色精品| 国产精品久一| 婷婷成人综合| 青草av.久久免费一区| 国产精选一区| 六月婷婷综合| 蜜臀av在线播放一区二区三区| 国产一级成人av| 成人看片网站| 日韩精品免费观看视频| 国产成人久久精品一区二区三区| 亚洲精品在线观看91| 麻豆国产精品777777在线| 亚洲少妇一区| 精品国产精品国产偷麻豆| 日韩制服丝袜先锋影音| 久久青青视频| 国产乱码精品一区二区三区亚洲人 | 国产午夜精品一区在线观看| 99久久精品网| 国产日韩一区| 在线一区二区三区视频| 久久九九精品| 国产一区二区三区四区二区| 亚洲婷婷丁香| 亚洲天堂久久| 色偷偷色偷偷色偷偷在线视频| 欧美精品国产| 蜜桃视频在线观看一区二区| 日韩欧美精品综合| 日韩在线观看中文字幕| 久久中文亚洲字幕| 国产传媒在线观看| 激情国产在线| 伊人久久视频| 日韩精品91| 亚洲黄色免费看| 久久精品一区二区国产| 国产精久久久| 先锋亚洲精品| 日韩极品在线观看| 丝袜美腿亚洲色图| 91精品二区| 伊人影院久久| 午夜久久福利| 久久免费黄色| 成人自拍av| 欧美日韩国产在线观看网站| 美女av在线免费看| 欧美日韩一区二区综合| 亚洲国产专区校园欧美| 不卡av一区二区| 视频一区在线播放| 欧美私人啪啪vps| 鲁大师精品99久久久| 国产不卡精品在线| 成人看片网站| 蜜桃久久av| 久久国际精品| 日韩啪啪电影网| 日韩综合精品| aa亚洲婷婷| 91精品一区| 日韩欧美综合| 噜噜噜躁狠狠躁狠狠精品视频 | 精品免费av在线| 亚洲精品91| 日本午夜精品久久久| 高清久久一区| 亚洲免费在线| 国产欧美日韩精品高清二区综合区 | 奇米狠狠一区二区三区| 精品久久久网| 99视频在线精品国自产拍免费观看| 日韩精品三级| 999国产精品视频| 91成人精品观看| 九九精品调教| 国产精品毛片视频| 一区免费在线| 精品欧美一区二区三区在线观看| 亚洲日产av中文字幕| 日韩不卡在线| 国产精品va视频| 日韩视频不卡| 亚洲三级欧美| 麻豆精品在线观看| 亚洲欧洲av| 午夜在线精品偷拍| 中文字幕系列一区| 999国产精品永久免费视频app| 在线成人直播| 欧美日一区二区三区在线观看国产免| 欧美三区不卡| 中文日韩在线| 欧美亚洲激情| 夜鲁夜鲁夜鲁视频在线播放| 国产伦精品一区二区三区视频| 欧美资源在线| 美女毛片一区二区三区四区 | 最新国产精品视频| 欧美在线亚洲综合一区| 国产二区精品| 亚洲午夜精品久久久久久app| 国产成人免费av一区二区午夜| 青青国产精品| 亚洲黄页一区| 韩日一区二区三区| 婷婷色综合网| 99国产精品| 午夜在线播放视频欧美| 日韩制服丝袜先锋影音| 亚洲免费一区三区| 亚洲bt欧美bt精品777| 久久精品97| av综合电影网站| 偷拍欧美精品| 亚洲精品一级| 久久精品福利|