国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁(yè) > news >正文

買(mǎi)cms做網(wǎng)站seo推廣軟件品牌

買(mǎi)cms做網(wǎng)站,seo推廣軟件品牌,有趣的網(wǎng)站名稱(chēng),遼寧建設(shè)工程信息介紹: SSM相信大家都不陌生,在spring boot出現(xiàn)之前,SSM一直是Java在web開(kāi)發(fā)中的老大哥?,F(xiàn)在雖說(shuō)有了spring boot能自動(dòng)整合第三方框架了,但是現(xiàn)在市面上任然有很多老項(xiàng)目是基于SSM技術(shù)的。因此,能熟練掌握SSM進(jìn)行開(kāi)發(fā)…

介紹:

SSM相信大家都不陌生,在spring boot出現(xiàn)之前,SSM一直是Java在web開(kāi)發(fā)中的老大哥?,F(xiàn)在雖說(shuō)有了spring boot能自動(dòng)整合第三方框架了,但是現(xiàn)在市面上任然有很多老項(xiàng)目是基于SSM技術(shù)的。因此,能熟練掌握SSM進(jìn)行開(kāi)發(fā)也是非常重要的。對(duì)于新的項(xiàng)目,我當(dāng)然是推薦直接用spring boot,但是對(duì)于像SSM技術(shù)的項(xiàng)目,我們必須也能夠熟練上手。(雖說(shuō)現(xiàn)在電動(dòng)車(chē)很方便,但我們也要會(huì)騎自行車(chē))

SSM(Spring+SpringMVC+MyBatis)是一種經(jīng)典的Java Web開(kāi)發(fā)框架組合?,F(xiàn)在的spring boot框架可以看作是SSM的進(jìn)一步整合。

整合SSM:


本次使用到的版本為Java8、spring5.3.7

創(chuàng)建一個(gè)maven項(xiàng)目,并將項(xiàng)目添加為WEB項(xiàng)目。(可以在創(chuàng)建項(xiàng)目時(shí)直接選定模板,也可以先創(chuàng)建一個(gè)普通的maven項(xiàng)目,再將maven項(xiàng)目設(shè)置為web項(xiàng)目)

項(xiàng)目的目錄結(jié)果如下:

引入一些基礎(chǔ)的maven依賴(lài):

<dependencies><!-- tomcat相關(guān)依賴(lài) --><dependency><groupId>org.apache.tomcat.embed</groupId><artifactId>tomcat-embed-core</artifactId><version>9.0.73</version></dependency><!-- 如果需要JSP支持,還需要添加以下依賴(lài) --><dependency><groupId>org.apache.tomcat.embed</groupId><artifactId>tomcat-embed-jasper</artifactId><version>9.0.73</version></dependency><!-- https://mvnrepository.com/artifact/org.mybatis/mybatis --><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.11</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>5.3.7</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>5.3.7</version></dependency><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper</artifactId><version>5.3.2</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.20</version></dependency><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>4.0.1</version></dependency><!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.48</version></dependency><!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring --><dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>2.1.0</version></dependency><!-- https://mvnrepository.com/artifact/com.alibaba/druid --><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.2.20</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version></dependency></dependencies>

先創(chuàng)建一個(gè)spring配置類(lèi),用來(lái)掃描整合項(xiàng)目路徑:

@Configuration
@ComponentScan("com.zq.ssmdemo")public class SpringConfig {}

接下來(lái)就是重點(diǎn)了,我們要在項(xiàng)目中創(chuàng)建一個(gè)tomcat容器

(當(dāng)然,你也可以使用本地的tomcat部署,效果都是一樣的。spring boot的內(nèi)部也是內(nèi)嵌了一個(gè)tomcat)。我們?cè)趍aven坐標(biāo)中已經(jīng)引入了tomcat的依賴(lài)了(注意版本的差異。tomcat版本過(guò)高的話就要升級(jí)jdk的版本。我目前時(shí)jdk8,使用tomcat9)

public class TomcatConfig {public static void main(String[] args) {AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();applicationContext.register(SpringConfig.class);applicationContext.refresh();startTomcat(applicationContext);}static void   startTomcat(WebApplicationContext applicationContext){// 創(chuàng)建一個(gè)Tomcat實(shí)例Tomcat tomcat = new Tomcat();Server server = tomcat.getServer();Service service = server.findService("Tomcat");Connector connector = new Connector();connector.setPort(8080);Engine engine = new StandardEngine();engine.setDefaultHost("localhost");Host host = new StandardHost();host.setName("localhost");String contextPath = "";Context context = new StandardContext();context.setPath(contextPath);context.addLifecycleListener(new Tomcat.FixContextListener());host.addChild(context);engine.addChild(host);service.setContainer(engine);service.addConnector(connector);tomcat.addServlet(contextPath, "dispatcher", newDispatcherServlet(applicationContext));
//     設(shè)置默認(rèn)的Servletcontext.addServletMappingDecoded("/*", "dispatcher");try {tomcat.start();} catch (LifecycleException e) {e.printStackTrace();}}}

現(xiàn)在,這個(gè)項(xiàng)目就是一個(gè)springMVC項(xiàng)目了。我們可以創(chuàng)建一個(gè)controller,寫(xiě)一個(gè)映射路徑來(lái)檢驗(yàn)一下我們的代碼是否正確。

@RestController
@RequestMapping("/test")
public class TestController {@GetMapping("/hello")public String get() {System.out.println("hello,test!");return "hello,test!";}}

啟動(dòng)項(xiàng)目,(運(yùn)行TomcatConfig中的main方法)

訪問(wèn)我們定義的映射路徑:

可以看到能正確的訪問(wèn)到控制類(lèi)。

整合mybatis:

在resources資源目錄下新建整合mybatis的資源:

新建一個(gè)數(shù)據(jù)庫(kù)連接文件:

jdbc.driver= com.mysql.jdbc.Driver 
jdbc.url=jdbc:mysql://localhost:3306/bank
jdbc.username=root
jdbc.password=123456

新建一個(gè)mybatis的配置文件:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC"-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><settings><!-- 設(shè)置駝峰標(biāo)識(shí) --><setting name="mapUnderscoreToCamelCase" value="true"/><!-- 打印SQL語(yǔ)句 --><setting name="logImpl" value="STDOUT_LOGGING"/></settings><plugins><!-- 分頁(yè)插件 --><plugin interceptor="com.github.pagehelper.PageInterceptor"/></plugins><mappers><package name="com.zq.ssmdemo.mapper"/></mappers></configuration>

注意這兩個(gè)文件的位置:

配置mybatis的連接信息:

@PropertySource("classpath:jdbc.properties")
public class MybatisConfig {@Value("${jdbc.driver}")private String driver;@Value("${jdbc.url}")private String url;@Value("${jdbc.username}")private String username;@Value("${jdbc.password}")private String password;@Beanpublic DataSource dataSource(){DruidDataSource dataSource = new DruidDataSource();dataSource.setDriverClassName(driver);dataSource.setUrl(url);dataSource.setUsername(username);dataSource.setPassword(password);return dataSource;}@Beanpublic SqlSessionFactoryBean sqlSessionFactoryBean(){SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();sqlSessionFactoryBean.setDataSource(dataSource());//指定mybatis配置文件ClassPathResource classPathResource = new ClassPathResource("mybatis-config.xml");sqlSessionFactoryBean.setConfigLocation(classPathResource);return sqlSessionFactoryBean;}@Beanpublic MapperScannerConfigurer mapperScannerConfigurer(){MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();mapperScannerConfigurer.setBasePackage("com.zq.ssmdemo.mapper");return mapperScannerConfigurer;}}

在spring的配置類(lèi)中引入mybatis的配置類(lèi):

@Configuration
@ComponentScan("com.zq.ssmdemo")
@Import({MybatisConfig.class})
public class SpringConfig {}

現(xiàn)在,啟動(dòng)一下這個(gè)項(xiàng)目:

可以看到打印除了pageHelp插件的logo,而我們pageHelp插件是在mybatis的配置文件中配置的,所以,我們的mybatis配置文件是肯定被spring項(xiàng)目掃描到的。

現(xiàn)在,我們進(jìn)行一下簡(jiǎn)單的測(cè)試,看能否使用mybatis進(jìn)行數(shù)據(jù)庫(kù)的操作:

創(chuàng)建一個(gè)mapper接口,進(jìn)行測(cè)試:

public interface UsersMapper {// 查詢(xún)所有用戶(hù)
@Select("select * from users")List<Users> selectAll();
}

創(chuàng)建一個(gè)controller進(jìn)行測(cè)試:

@RestController
@RequestMapping("/user")
public class UserController {@Resourceprivate UsersMapper usersMapper;@GetMapping("/list")public Object add(){PageHelper.startPage(1, 2);List<Users> users = usersMapper.selectAll();PageInfo<Users> page = new PageInfo<>(users);System.out.println(page);return page;}}

輸出結(jié)果如下:

可以看到正確輸出了數(shù)據(jù)庫(kù)中的信息,表明我們能成功連接到數(shù)據(jù)庫(kù)。

http://m.aloenet.com.cn/news/39300.html

相關(guān)文章:

  • 香港外貿(mào)網(wǎng)站建設(shè)谷歌搜索引擎網(wǎng)址
  • 網(wǎng)站子頁(yè)怎么做如何能查到百度搜索排名
  • 北京大學(xué)學(xué)術(shù)學(xué)風(fēng)建設(shè)網(wǎng)站網(wǎng)站運(yùn)營(yíng)優(yōu)化培訓(xùn)
  • 做物流網(wǎng)站的圖片素材關(guān)鍵詞seo是什么意思
  • 縉云做網(wǎng)站廈門(mén)seo代理商
  • wordpress企業(yè)網(wǎng)站模板下載seo如何提升排名收錄
  • 網(wǎng)站建設(shè)與網(wǎng)頁(yè)設(shè)計(jì)今天高清視頻免費(fèi)播放
  • 鄭州網(wǎng)站推廣¥做下拉去118cr餐飲營(yíng)銷(xiāo)案例100例
  • 網(wǎng)站建設(shè)維護(hù)管理辦法外貿(mào)營(yíng)銷(xiāo)型網(wǎng)站制作公司
  • 北京網(wǎng)站建設(shè)企業(yè)網(wǎng)站制作蘇州網(wǎng)站關(guān)鍵字優(yōu)化
  • 茂名網(wǎng)站制作百度推廣后臺(tái)登錄頁(yè)面
  • 做振動(dòng)盤(pán)的企業(yè)網(wǎng)站中國(guó)軍事新聞最新消息
  • 網(wǎng)站建設(shè)程序源碼青島網(wǎng)站優(yōu)化公司
  • flash做ppt的模板下載網(wǎng)站有哪些西安網(wǎng)站開(kāi)發(fā)制作公司
  • 北京網(wǎng)站制作公司建站體驗(yàn)營(yíng)銷(xiāo)理論
  • 怎樣做網(wǎng)站-百度邯鄲今日頭條最新消息
  • 百度不收錄網(wǎng)站首頁(yè)女教師網(wǎng)課入侵錄屏冫
  • 企業(yè)做網(wǎng)站的申請(qǐng)報(bào)告廣州seo網(wǎng)絡(luò)推廣員
  • 離婚協(xié)議書(shū)模板 完整版海南seo代理加盟供應(yīng)商
  • 網(wǎng)站交互圖片怎么做的免費(fèi)搭建網(wǎng)站的軟件
  • 網(wǎng)站開(kāi)發(fā)維護(hù)求職信全球十大搜索引擎排名
  • 網(wǎng)站建設(shè)的最新技術(shù)寧波seo優(yōu)化公司
  • 網(wǎng)絡(luò)代理是干嘛的重慶seo扣費(fèi)
  • 廣州站桂平網(wǎng)絡(luò)推廣
  • 宿遷建設(shè)局網(wǎng)站win7系統(tǒng)優(yōu)化
  • 禪城網(wǎng)站建設(shè)多少錢(qián)網(wǎng)絡(luò)營(yíng)銷(xiāo)推廣策劃的步驟是什么
  • 高端營(yíng)銷(xiāo)網(wǎng)站泰州百度公司代理商
  • 代做ppt網(wǎng)站百度知道在線問(wèn)答
  • 網(wǎng)站靜態(tài)頁(yè)面網(wǎng)絡(luò)營(yíng)銷(xiāo)案例ppt
  • 鹽亭做網(wǎng)站采集站seo提高收錄