首页 技术 正文
技术 2022年11月15日
0 收藏 673 点赞 4,531 浏览 2553 个字
hibernate3
(整合到spring中的core核心配置中的hibernate3)
<!-- 基于hibernate的Session工厂 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<!-- 数据源,在这里使用了第三方的连接池当做数据源 ,该参考类要实现了sql.dateSource接口 -->
<property name="dataSource" ref="dbcp_dateSource">
</property><!-- 将hibernate的设置参数引入Spring配置,如此就不用单独设置hibernate配置文件 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
</props>
</property><!-- 要扫描的包,导入包内注解好映射的实体类 -->
<property name="packagesToScan" value="com.twogold.dto"></property></bean>
1.创建实体类,在实体类中注解每一项属性,并对对应关系进行描述(一对一,一对多,多对多)。2.根据业务接口层中的方法给出dao层接口。3.实现dao层接口中的方法,通过
@Repository(value=“projectDao”)
(这是为这一个实现类取名字,以便后面注解根据名字调用);然后在接口实现类中聚合一个
@Resource(name="sessionFactory")
priavte SessionFactory sf;(这样就能得到session工厂。(但是为了提高session的利用率 就通过sf.getCrrentSession()这样每次都用的是当前的session,避免了每次都得到一个新session)4.封装业务逻辑层接口;
5.给出业务逻辑层接口的实现,
接口实现类中的注解
(类外注解)
@Service()
@Transactional(propagation=propagation.REQUIRED)(事务注解)(类中聚合一个dao层接口)
(类内注解)
@Resource(name=“projectDao”)(这那么是dao层事项类中为类开始取的名字,如果么有取名字,那么就该和实现类的名字一样。)
priavet IProjectDao dao;6.前后台之间中央控制类,该类对前台页面的请求调用对应的方法;
(类外注解)
@Controller
(类内注解)
@Resource
private IProjectservice service;(聚合业务逻辑接口类)
@Resource(name=“systemParameSetting”)
private ISysParSettingService sss;@RequestMapping(value=“{id}/view”)
//@RequestBody 返回一个json格式的数据
public String viewProject(
@PathVariable("id") int id,({id}大括号用@PathVariable方法参数)
HttpServletRequest req
){Project project = service.getProjectById(id);
//return 吧对象转为json对象
req.setAttribute("project", project);return "projectDeclare/view";@RequestMapping("/update")
public String update(
@ModelAttribute Project p,
HttpServletRequest req
){service.updateProject(p);
return null;
}@RequestMapping("/year")
public String getYear(
@RequestParam(value="areaId", defaultValue="2") int areaId,(为参数指定默认值和类型)
HttpServletRequest req
){
List<String> year=service.findYear(areaId);
req.setAttribute("year",year);
return "projectDeclare/reqquisition_collect_list";
}@RequestMapping("/{id}/update")
public String updateProject(
@PathVariable("id") int id,
@RequestParam("assistanceFinancing") String af,(应该是前台传过来时的name)
@RequestParam("otherFinancing") String of,
@RequestParam("selfFinancing") String cf,
HttpServletRequest req
){
int iaf = new Integer(af);
int iof = new Integer(of);
int icf = new Integer(cf);
int totil = iaf + iof+ icf;Project p = service.getProjectById(id);p.setAssistanceFinancing(iaf);
p.setOtherFinancing(iof);
p.setSelfFinancing(icf);
p.setTotal(totil);service.updateProject(p);return "redirect:/1/check";
}
下一篇: C# Out 传值
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,085
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902