在SSM建筑物框架在图内容内加入Hibernate 可以吗?

现在好多公司都用SSM框架?【java吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:668,780贴子:
现在好多公司都用SSM框架?收藏
我想问下,我本人是学SSH框架的,发现现在好多公司都不招SSH的了,SSM框架到底比SSH好在什么地方,还有SSM框架都有哪些有点
兄弟连教育&拉勾网强强联合打造JavaEE.战狼班,Java培训后付费非贷款,入学兄弟连java战狼班,拉勾网战略合作,高起点出Java精英.
再学ssm就是了
感觉框架都差不多啊,不要纠结是ssh还是ssm,不要怂
楼主不看行情瞎入门 swing学了吗 现在百分之99都是swing
上手快,我工作了一年多以后才接触ssm,一个星期看看就能很方便使用了
M 比 H 简单,SQL语句自己写,而H的语句不行
都是差不多的!
框架简单,套呗
学个框架都能这么纠结?
struts2爆出过重大BUG
2017java学习来上市公司博为峰学java,入学即签就业协议,不就业不收费,查看java课程!java好学吗?java课程来博为峰学,java工程师就业年薪十几万!
换了一个就不行了?不都是做持久的
spring + hibernate + spring mvc 路过
登录百度帐号推荐应用在 SegmentFault,解决技术问题
每个月,我们帮助 1000 万的开发者解决各种各样的技术问题。并助力他们在技术能力、职业生涯、影响力上获得提升。
一线的工程师、著名开源项目的作者们,都在这里:
获取验证码
已有账号?
问题对人有帮助,内容完整,我也想知道答案
问题没有实际价值,缺少关键内容,没有改进余地
学完Javaweb阶段,可以直接上手ssm框架,然后用ssm框架做项目吗?ssh以后再去看,可以这样吗
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
完全没问题。Hibernate本身上手有些难度
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
可以,做项目都一通百通,大部分普通功能不会太复杂,以后具体技术具体研究往架构发展
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
感觉struts比spring好上手点。。个人感觉
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
我也是新手,现在在学ssh。不过struts1现在应该慢慢被springmvc取代,hibernate也慢慢被mb取代了。但是ssh也算经典框架了,我觉得还是有必要学学吧。所以我是打算学完ssh,再去学mb和springmvc
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
个人觉得ssm相对ssh上手简单,而且ssm在大多公司应用较多一些,另外ssh也需要去学习,了解它们的特性和区别,以及应用场景。
同步到新浪微博
分享到微博?
关闭理由:
删除理由:
忽略理由:
推广(招聘、广告、SEO 等)方面的内容
与已有问题重复(请编辑该提问指向已有相同问题)
答非所问,不符合答题要求
宜作评论而非答案
带有人身攻击、辱骂、仇恨等违反条款的内容
无法获得确切结果的问题
非开发直接相关的问题
非技术提问的讨论型问题
其他原因(请补充说明)
我要该,理由是:用户名:pangfc
文章数:286
评论数:92
访问量:236112
注册日期:
阅读量:1297
阅读量:3317
阅读量:586373
阅读量:472545
51CTO推荐博文
一 介绍在企业级应用中,保护数据的完整性是非常重要的一件事。因此不管应用的性能是多么的高、界面是多么的好看,如果在转账的过程中出现了意外导致用户的账号金额发生错误,那么这样的应用程序也是不可接受的数据库的事务管理可以有效地保护数据的完整性(PS:关于数据库的事务管理基础可以参考我以前写过的这篇文章:/385.html),但是原生态的事务操作需要写不少的代码,无疑是非常麻烦的。在使用了Spring框架的应用中,我们可以使用@Transactional 注解方便地进行事务操作,如事务的回滚等。接下来我将以SSM框架中的事务注解操作进行举例说明:二 测试项目的搭建(1)项目结构和用到的jar包: &(2)测试使用到的SQL文件:SET&FOREIGN_KEY_CHECKS=0;
--&----------------------------
--&Table&structure&for&user
--&----------------------------
DROP&TABLE&IF&EXISTS&`user`;
CREATE&TABLE&`user`&(
&&`id`&int(11)&NOT&NULL&AUTO_INCREMENT,
&&`name`&varchar(32)&DEFAULT&NULL,
&&`password`&varchar(64)&DEFAULT&NULL,
&&`email`&varchar(64)&DEFAULT&NULL,
&&`birthday`&date&DEFAULT&NULL,
&&`money`&decimal(15,2)&DEFAULT&NULL,
&&PRIMARY&KEY&(`id`)
)&ENGINE=InnoDB&AUTO_INCREMENT=4&DEFAULT&CHARSET=utf8;
--&----------------------------
--&Records&of&user
--&----------------------------
INSERT&INTO&`user`&VALUES&('1',&'admin',&'123456',&'',&'',&'1000.00');
INSERT&INTO&`user`&VALUES&('2',&'test',&'1234',&'',&'',&'2500.00');
INSERT&INTO&`user`&VALUES&('3',&'xxxx',&'xx',&'',&'',&'4000.00');(3)使用mybatis-generator结合Ant脚本快速自动生成Model、Mapper等文件:关于这方面可以参考我以前写过的一篇文章,这里就不多说了,传送门:(4)一些基础配置文件:i)web.xml:&web-app&xmlns="http://xmlns.jcp.org/xml/ns/javaee"
&&&&&&&&&xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
&&&&&&&&&xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
&&http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
&&&&&&&&&version="3.1"&
&context-param&
&param-name&contextConfigLocation&/param-name&
&param-value&
classpath:context/context.xml
&/param-value&
&/context-param&
&listener&
&listener-class&org.springframework.web.context.ContextLoaderListener&/listener-class&
&/listener&
&listener&
&listener-class&org.springframework.web.context.request.RequestContextListener&/listener-class&
&/listener&
&servlet-name&springmvc&/servlet-name&
&servlet-class&org.springframework.web.servlet.DispatcherServlet&/servlet-class&
&init-param&
&param-name&contextConfigLocation&/param-name&
&param-value&classpath:context/jsp-dispatcher.xml&/param-value&
&/init-param&
&load-on-startup&1&/load-on-startup&
&/servlet&
&servlet-mapping&
&servlet-name&springmvc&/servlet-name&
&url-pattern&*.html&/url-pattern&
&/servlet-mapping&
&filter-name&characterEncodingFilter&/filter-name&
&filter-class&org.springframework.web.filter.CharacterEncodingFilter&/filter-class&
&init-param&
&param-name&encoding&/param-name&
&param-value&UTF-8&/param-value&
&/init-param&
&filter-mapping&
&filter-name&characterEncodingFilter&/filter-name&
&url-pattern&/*&/url-pattern&
&/filter-mapping&
&/web-app&ii)jdbc配置文件jdbc.properties:master.jdbc.driverClassName=com.mysql.jdbc.Driver
master.jdbc.url=jdbc:mysql://127.0.0.1:3306/transaction
master.jdbc.username=root
master.jdbc.password=rootiii)context.xml:&?xml&version="1.0"&encoding="UTF-8"?&
&beans&xmlns="http://www.springframework.org/schema/beans"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans&
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
&&&&&&&&&&&&http://www.springframework.org/schema/jee&
&&&&&&&&&&&&http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
&&&&&&&&&&&&http://www.springframework.org/schema/aop&
&&&&&&&&&&&&http://www.springframework.org/schema/aop/spring-aop-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/cache&&
http://www.springframework.org/schema/cache/spring-cache-4.0.xsd&&
&&&&&&&&&&&&http://www.springframework.org/schema/tx&
&&&&&&&&&&&&http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"
xmlns:context="http://www.springframework.org/schema/context"&xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"&
&context:component-scan&base-package="cn.zifangsky.dao"
annotation-config="true"&/&
&context:component-scan&base-package="cn.zifangsky.manager"
annotation-config="true"&/&
&bean&id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&
&property&name="locations"&
&value&classpath:jdbc.properties&/value&
&/property&
&!--&配置数据源&--&
&bean&id="dataSource"&class="com.mchange.boPooledDataSource"
destroy-method="close"&
&property&name="driverClass"&
&value&${master.jdbc.driverClassName}&/value&
&/property&
&property&name="jdbcUrl"&
&value&${master.jdbc.url}&/value&
&/property&
&property&name="user"&
&value&${master.jdbc.username}&/value&
&/property&
&property&name="password"&
&value&${master.jdbc.password}&/value&
&/property&
&!--连接池中保留的最小连接数。&--&
&property&name="minPoolSize"&
&value&5&/value&
&/property&
&!--连接池中保留的最大连接数。Default:&15&--&
&property&name="maxPoolSize"&
&value&30&/value&
&/property&
&!--初始化时获取的连接数,取值应在minPoolSize与maxPoolSize之间。Default:&3&--&
&property&name="initialPoolSize"&
&value&10&/value&
&/property&
&!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default:&0&--&
&property&name="maxIdleTime"&
&value&60&/value&
&/property&
&!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default:&3&--&
&property&name="acquireIncrement"&
&value&5&/value&
&/property&
&!--JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements&属于单个&connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。&
如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default:&0&--&
&property&name="maxStatements"&
&value&0&/value&
&/property&
&!--每60秒检查所有连接池中的空闲连接。Default:&0&--&
&property&name="idleConnectionTestPeriod"&
&value&60&/value&
&/property&
&!--定义在从数据库获取新连接失败后重复尝试的次数。Default:&30&--&
&property&name="acquireRetryAttempts"&
&value&30&/value&
&/property&
&!--获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效&保留,并在下次调用&getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试&
获取连接失败后该数据源将申明已断开并永久关闭。Default:&false&--&
&property&name="breakAfterAcquireFailure"&
&value&true&/value&
&/property&
&!--因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的&时候都将校验其有效性。建议&使用idleConnectionTestPeriod或automaticTestTable&
等方法来提升连接测试的性能。Default:&false&--&
&property&name="testConnectionOnCheckout"&
&value&false&/value&
&/property&
&!--&SqlMap&setup&for&iBATIS&Database&Layer&--&
&bean&id="sqlSessionFactory"&class="org.mybatis.spring.SqlSessionFactoryBean"&
&property&name="configLocation"&value="classpath:context/sql-map-config.xml"&/&
&property&name="dataSource"&ref="dataSource"&/&
&bean&class="org.mybatis.spring.mapper.MapperScannerConfigurer"&
&property&name="basePackage"&value="cn.zifangsky.mapper"&/&
&property&name="sqlSessionFactoryBeanName"&value="sqlSessionFactory"&/&
&bean&id="sqlSessionTemplate"&class="org.mybatis.spring.SqlSessionTemplate"&
&constructor-arg&index="0"&ref="sqlSessionFactory"&/&
&!--&Transaction&manager&for&a&single&JDBC&DataSource&--&
&bean&id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&
&property&name="dataSource"&ref="dataSource"&/&
&!--&开启注解方式声明事务&--&
&tx:annotation-driven&transaction-manager="transactionManager"&/&
&/beans&在上面的配置中,使用了C3P0作为数据库连接池,同时定义了自动扫描注解,Mybatis相关配置以及申明式事务管理,如果对这些基础不太熟的话可以参考下我以前写过的一些文章iv)jsp-dispatcher.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:cache="http://www.springframework.org/schema/cache"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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/cache&&
&&&&&&&http://www.springframework.org/schema/cache/spring-cache-4.0.xsd&&
&&&&&&&http://www.springframework.org/schema/mvc&
&&&&&&&http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"
default-lazy-init="true"&
&mvc:annotation-driven&/&
&context:annotation-config&/&&&&!--&激活Bean中定义的注解&--&
&!--&启动自动扫描该包下所有的Bean(例如@Controller)&--&
&context:component-scan&base-package="cn.zifangsky.controller"
annotation-config="true"&/&
&!--&定义视图解析器&--&
class="org.springframework.web.servlet.view.InternalResourceViewResolver"&
&property&name="prefix"&
&value&/WEB-INF/jsp/&/value&
&/property&
&property&name="suffix"&
&value&.jsp&/value&
&/property&
&/beans&v)sql-map-config.xml:&?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&
&!--&全局的映射器启用或禁用缓存。&--&
&setting&name="cacheEnabled"&value="true"&/&
&!--&全局启用或禁用延迟加载&--&
&setting&name="lazyLoadingEnabled"&value="true"&/&
&!--&允许或不允许多种结果集从一个单独的语句中返回&--&
&setting&name="multipleResultSetsEnabled"&value="true"&/&
&!--&使用列标签代替列名&--&
&setting&name="useColumnLabel"&value="true"&/&
&!--&允许JDBC支持生成的键&--&
&setting&name="useGeneratedKeys"&value="false"&/&
&!--&配置默认的执行器&--&
&setting&name="defaultExecutorType"&value="SIMPLE"&/&
&!--&设置超时时间&--&
&setting&name="defaultStatementTimeout"&value="25000"&/&
&/settings&
&mapper&resource="sqlmaps/UserMapper.xml"&/&
&/mappers&
&/configuration&(5)测试搭建的项目环境:i)在UserManager.java接口中添加几个基本的接口:public&interface&UserManager&{
int&deleteByPrimaryKey(Integer&id);
int&insert(User&record);
int&insertSelective(User&record);
User&selectByPrimaryKey(Integer&id);
int&updateByPrimaryKeySelective(User&record);
int&updateByPrimaryKey(User&record);
}ii)UserManagerImpl.java:package&cn.zifangsky.manager.
import&java.math.BigD
import&javax.annotation.R
import&org.apache.ibatis.jdbc.RuntimeSqlE
import&org.springframework.stereotype.S
import&org.springframework.transaction.annotation.T
import&cn.zifangsky.manager.UserM
import&cn.zifangsky.mapper.UserM
import&cn.zifangsky.model.U
@Service(value="userManagerImpl")
public&class&UserManagerImpl&implements&UserManager{
@Resource(name="userMapper")
private&UserMapper&userM
public&int&deleteByPrimaryKey(Integer&id)&{
public&int&insert(User&record)&{
public&int&insertSelective(User&record)&{
public&User&selectByPrimaryKey(Integer&id)&{
return&userMapper.selectByPrimaryKey(id);
public&int&updateByPrimaryKeySelective(User&record)&{
public&int&updateByPrimaryKey(User&record)&{
}iii)UserController.java:package&cn.zifangsky.
import&java.math.BigD
import&javax.annotation.R
import&org.springframework.stereotype.C
import&org.springframework.web.bind.annotation.RequestM
import&org.springframework.web.bind.annotation.RequestP
import&cn.zifangsky.manager.UserM
import&cn.zifangsky.model.U
@Controller
public&class&UserController&{
@Resource(name&=&"userManagerImpl")
private&UserManager&userM
@RequestMapping(value&=&"/select")
public&String&user(@RequestParam(name&=&"userId",&required&=&false)&Integer&userId)&{
User&user&=&userManager.selectByPrimaryKey(userId);
System.out.println("用户名:&"&+&user.getName());
System.out.println("邮箱:&"&+&user.getEmail());
return&"success";
}iv)启动项目并进行测试:项目启动后访问:http://localhost:8090/TransactionDemo/select.html?userId=2 ,如果发现控制台中输出如下则说明测试环境已经搭建成功了:用户名:&test
邮箱:&三 使用@Transactional注解管理事务示例(1)在UserManager接口中添加一个如下方法:/**
&*&@param&sourceAccountId
&*&&&&&&&&&&&&源账户
&*&@param&targetAccountId
&*&&&&&&&&&&&&目标账户
&*&@param&amount
&*&&&&&&&&&&&&转账金额
void&transferMoney(Integer&sourceAccountId,&Integer&targetAccountId,&BigDecimal&amount);此方法目的是为了模拟转账操作(2)在UserManagerImpl实现类中添加对用的实现方法:@Transactional(rollbackFor=Exception.class)
public&void&transferMoney(Integer&sourceAccountId,&Integer&targetAccountId,&BigDecimal&amount)&{
User&sourceAccount&=&userMapper.selectByPrimaryKey(sourceAccountId);
User&targetAccount&=&userMapper.selectByPrimaryKey(targetAccountId);
BigDecimal&sourceMoney&=&sourceAccount.getMoney();
BigDecimal&targetMoney&=&targetAccount.getMoney();
//判断账户余额是否足够
pareTo(amount)&&&0){
sourceAccount.setMoney(sourceMoney.subtract(amount));
targetAccount.setMoney(targetMoney.add(amount));
//更新数据库
userMapper.updateByPrimaryKeySelective(sourceAccount);
throw&new&RuntimeSqlException("手动模拟转账时出现异常");
userMapper.updateByPrimaryKeySelective(targetAccount);
}可以看出,在这个方法上面申明了一个@Transactional,表明这个方法将要进行事务管理,同时需要说明的是rollbackFor参数定义了在出现了什么异常时进行事务的回滚,显然这里定义的就是所有的Exception都要进行事务回滚。与之相反的一个参数是norollbackFor,这里就不多说了。对于@Transactional注解我们不仅可以在一个方法上放置,而且可以在类上进行申明。如果在类级别上使用该注解,那么类中的所有公共方法都被事务化,否则就只有使用了@Transactional注解的公共方法才被事务化在这个方法中为了模拟转账出现异常,因此在第一个账户进行更新后就手动抛出了一个异常(3)在UserController类中添加一个模拟转账的方法:@RequestMapping(value&=&"/transfer")
public&String&transfer(@RequestParam(name&=&"account1")&Integer&account1,
@RequestParam(name&=&"account2")&Integer&account2,&@RequestParam(name&=&"amount")&Long&amount)&{
System.out.println("转账之前:");
System.out.println("账户一的资金:"&+&userManager.selectByPrimaryKey(account1).getMoney().longValue());
System.out.println("账户二的资金:"&+&userManager.selectByPrimaryKey(account2).getMoney().longValue());
userManager.transferMoney(account1,&account2,&BigDecimal.valueOf(amount));
System.out.println("转账之后:");
System.out.println("账户一的资金:"&+&userManager.selectByPrimaryKey(account1).getMoney().longValue());
System.out.println("账户二的资金:"&+&userManager.selectByPrimaryKey(account2).getMoney().longValue());
return&"success";
}(4)效果测试:项目运行后访问:http://localhost:8090/TransactionDemo/transfer.html?account1=1&account2=2&amount=500可以发现项目会进行保存,这时我们查看数据库中看看账户1和账户2中的金额有没有发生变化:可以看出,两者的金额都没有发生改变,说明事物的确进行了回滚。当然,有兴趣的同学可以把UserManagerImpl中那个 @Transactional &注解给去掉看看数据库中的这个金额在执行“转账”后又会不会发生改变?本文出自 “” 博客,请务必保留此出处
了这篇文章
类别:┆阅读(0)┆评论(0)在 SegmentFault,解决技术问题
每个月,我们帮助 1000 万的开发者解决各种各样的技术问题。并助力他们在技术能力、职业生涯、影响力上获得提升。
一线的工程师、著名开源项目的作者们,都在这里:
获取验证码
已有账号?
问题对人有帮助,内容完整,我也想知道答案
问题没有实际价值,缺少关键内容,没有改进余地
学完javaweb基础学习阶段(javase、servlet、jsp等等),现在学框架,可以先跳过struts2、hibernate即ssh,直接学spring、spring-mvc、mybatis(ssm)吗???
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
完全没问题啊,不过如果是为了理解MVC框架结构的话,还是可以看一下struts2,毕竟是个非常好的MVC框架,然后springmvc也是现在比较主流的;学习框架的目的是为了工作上更高效。但是框架都是对最基础的东西的封装,所以,不管学了多少框架方面的东西,千万不要丢下基础。
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
理论上没什么问题的,因为struts和spring没什么关系,你可以先学习spring的ioc aop,完了之后可以学习spring-mvc,这个时候就算你不学mybatis直接用Jdbc去做dao层,也不会影响一个java web项目的开发,当然你也可以学习了mybatis,然后重构你的dao层,现在用hibernate和struts的也慢慢变少了,主要是hibernate相对Mybatis来说,重量级不少,学习成本也高些,不过好处不用写sql,Struts最近经常爆漏洞,其实也没springmvc好用……个人觉得
分享到微博?
关闭理由:
删除理由:
忽略理由:
推广(招聘、广告、SEO 等)方面的内容
与已有问题重复(请编辑该提问指向已有相同问题)
答非所问,不符合答题要求
宜作评论而非答案
带有人身攻击、辱骂、仇恨等违反条款的内容
无法获得确切结果的问题
非开发直接相关的问题
非技术提问的讨论型问题
其他原因(请补充说明)
我要该,理由是:}

我要回帖

更多关于 axure的内部框架在哪 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信