<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
先附上測試的資料庫
DROP TABLE IF EXISTS `user`; CREATE TABLE `user` ( `id` int(5) NOT NULL AUTO_INCREMENT, `name` varchar(10) COLLATE utf8_bin DEFAULT NULL, `password` varchar(10) COLLATE utf8_bin DEFAULT NULL, `remark` varchar(50) COLLATE utf8_bin DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; -- ---------------------------- -- Records of user -- ---------------------------- INSERT INTO `user` VALUES ('1', 'zhangsan', '123456', null); INSERT INTO `user` VALUES ('2', 'lisi', '123', null); INSERT INTO `user` VALUES ('3', 'wangan', '456', null); INSERT INTO `user` VALUES ('4', 'xinxi', '000', null);
點選next後出現如下填寫GroupId和ArtifactId在點選next直至finish
在main下新建java和resources目錄如下並將java目錄標記為Sources Root,resources標記為Resources Root
在java下新建如下包package
注:如果引入所有(spring和hibernate)依賴則在struts.xml中的對應action的類class就會找不到
<dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-core</artifactId> <version>2.5.1</version> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-json-plugin</artifactId> <version>2.5.1</version> <scope>compile</scope> </dependency>
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>Archetype Created Web Application</display-name> <!--Hibernate Open Session in View Filte --> <!-- <filter> <filter-name>hibernateFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> singleSession預設為true,若設為false則等於沒用OpenSessionInView <init-param> <param-name>singleSession</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <url-pattern>/*</url-pattern> </filter-mapping> --> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <!-- Struts。xml的組態檔 --> <!-- 所有匹配*.action的請求都由struts2處理 --> <constant name="struts.action.extension" value="action,," /> <!-- 是否啟用開發模式 --> <constant name="struts.devMode" value="true" /> <package name="default" extends="struts-default" namespace="/"> <!-- 如果不指定method,那麼預設方法是execute--> <!--name:Action類的名字,具有唯一性,頁面上通過name來存取Action類 --> <action name="test" class="com.well.liu.action.TestAction" method="test"> <!-- 設定結果集 :name屬性的值一定要與execute方法的返回值一致--> <result name="test">test.jsp</result> </action> </package> </struts>
package com.well.liu.action; import com.opensymphony.xwork2.ActionSupport; public class TestAction extends ActionSupport { public String test(){ System.out.println("測試struts2"); return "test"; } }
點選如下圖
點選+號找到Local
接下來修改名字,選擇Deployment點選+號,選擇ssh:war exploded,另外Application context填寫的如果是ssh,那麼存取的時候就是localhost:8080/ssh,部署結束。
啟動後預設存取的是index.jsp頁面,可以存取http://localhost:8080/ssh/test
如果頁面亂碼在頭部加上<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>3.0.6.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>3.0.6.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>3.0.6.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>3.0.6.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>3.0.6.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>3.0.6.RELEASE</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.8.4</version> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-spring-plugin</artifactId> <version>2.5.1</version> </dependency>
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring.xml</param-value> </context-param>
spring.xml檔案
<?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:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:amq="http://activemq.apache.org/schema/core" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd"> <bean id="test" class="com.well.liu.action.TestAction"> </bean> </beans>
如果你的spring.xml檔案uri地址出錯,解決點選選單欄“File”→“Settings”→“Languages&Frameworks”
將之前的struts.xml中的<action name="test" class="com.well.liu.action.TestAction" method="test">class改為"test",也就是說與spring.xml中bean的id相對應,然後執行即可
<dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>3.6.5.Final</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.34</version> </dependency> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.4</version> </dependency>
找到所需連線的資料庫
依次填寫如下即可
右鍵點選專案新增support支援
找到Hibernate並且打勾新增 import database schema打勾 含義:匯入資料庫模式
填寫如下資訊(資料來源、實體生成包model位置、勾選需要生成的實體、勾選右下角最下面的兩個按鈕)即可生成實體和對映檔案
spring.xml檔案
<?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:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:amq="http://activemq.apache.org/schema/core" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/user?characterEncoding=utf-8" /> <property name="username" value="root" /> <property name="password" value="root" /> </bean> <!--SessionFactory設定--> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" destroy-method="destroy"> <property name="dataSource" ref="dataSource"/> <property name="mappingResources"> <list> <value>com/well/liu/model/UserEntity.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop> <prop key="hibernate.show_sql">false</prop> </props> <bean id="userDao" class="com.well.liu.dao.UserDao"> <property name="sessionFactory" ref="sessionFactory"></property> <bean id="test" class="com.well.liu.action.TestAction"> <property name="userService" ref="userService"></property> <bean id="userService" class="com.well.liu.service.impl.UserServiceImpl"> <property name="userDao" ref="userDao"></property> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> <!-- 定義事務通知 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <!-- 定義方法的過濾規則 --> <tx:attributes> <!-- 所有方法都使用事務 --> <tx:method name="*" propagation="REQUIRED"/> </tx:attributes> </tx:advice> <!-- 定義AOP設定 --> <aop:config> <!-- 定義一個切入點 --> <aop:pointcut expression="execution (* com.well.liu.service.*.*(..))" id="services"/> <!-- 對切入點和事務的通知,進行適配 --> <aop:advisor advice-ref="txAdvice" pointcut-ref="services"/> </aop:config> </beans>
在包dao下新建UserDao
package com.well.liu.dao; import com.well.liu.model.UserEntity; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; public class UserDao extends HibernateDaoSupport { public UserEntity getUser(int id){ return this.getHibernateTemplate().get(UserEntity.class,id); } }
在包service下新建UserService
package com.well.liu.service; import com.well.liu.model.UserEntity; public interface UserService { public UserEntity getUser(int id); }
在包impl下新建UserServiceImpl
package com.well.liu.service.impl; import com.well.liu.dao.UserDao; import com.well.liu.model.UserEntity; import com.well.liu.service.UserService; public class UserServiceImpl implements UserService { private UserDao userDao; public UserDao getUserDao() { return userDao; } public void setUserDao(UserDao userDao) { this.userDao = userDao; @Override public UserEntity getUser(int id) { UserEntity userEntity = userDao.getUser(id); return userEntity; }
TestAction類
package com.well.liu.action; import com.opensymphony.xwork2.ActionSupport; import com.well.liu.model.UserEntity; import com.well.liu.service.UserService; public class TestAction extends ActionSupport { private UserService userService; public UserService getUserService() { return userService; } public void setUserService(UserService userService) { this.userService = userService; public String test(){ UserEntity userEntity = userService.getUser(1); System.out.println(userEntity); return "test"; }
啟動後會報如下錯誤
在網上找了資料將classpath改成classpath*、在pom中增加設定都還是同樣的問題
最後將UserEntity.hbm.xml移動到resources下啟動成功後後存取http://localhost:8080/ssh/test,出現地址則成功
到此這篇關於idea搭建ssh框架(超詳細)的文章就介紹到這了,更多相關idea搭建ssh框架內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45