在课堂上我们现在正在学习如何构建Spring应用程序,即使spring没有直接参与,我们也学会了如何为DAO和服务层对象创建接口.
如果我错了请纠正我:DAO层非常抽象:它只包含CRUD操作并进一步用于读取数据.(即:获取所有对象,获取特定对象等)
服务层:包含用于创建事物和删除事物的服务,这是业务逻辑应该在的地方.
现在所有这一切在服务层都有意义; 除了"更新"对象.您是否只是将"更新"功能只保存在数据库中?或者你还需要在那里定义逻辑吗?这就是我的困惑所在,我的理解是Spring中的对象只是POJO的.那么谁验证了数据呢?
比方说,我有一个对象"孩子"有:Name,SurName,Gender,Photo,Birthdate
领域.我如何命名服务?或者你只是让控制器负责验证,这对我来说似乎不对.另一方面,将需要调用的每个setter委托给服务层似乎也不正确.
所以基本上:帮助我如何通过服务层定义保存对象.
我正在学习休眠,我遇到了一些问题.我正在读O'Reilly的"Harnessing Hibernate".他们使用ANT解释所有内容,但由于我想避免编写一个巨大的build.xml文件,我试图让它与IntelliJ一起工作.
我设法根据MySQL数据库中的DB表进行映射,并为其编写bean.它工作,但我找不到任何有关如何生成bean和SQL代码,或如何使用IntelliJ进行逆向工程的信息.我使用JBOSS Hibernate工具插件找到了大量关于Eclipse的教程,并且该网站声称这种生成代码的支持已经在IntelliJ的标准安装中.
我忘记了添加库等配置吗?我试图找到这个,但我现在绝望了.请不要建议我使用Eclipse,我需要IntelliJ作为我当前的角色.
在java课程中,每个人(或至少大多数人)似乎都有工作日食.他们似乎总是有一个工作的faces-config(一个可视的)和xhtml文件中的自动完成(用于facelets).虽然对于自动完成,我们在JSP上添加了*.xhtml文件.
看来这是我不太了解eclipse的一部分,而且因为我不知道为什么而且相当烦人.当我导入一个项目(Maven或现有)时,它总是没有方面而是java(1.5中甚至不是1.6),而它应该是一个webproject并且有facelets和动态web项目.
我可以改变这些方面吗?它似乎只是当我把java放到1.6,但尝试编辑动态Web模块版本从2.4到2.5(它是2.4的标准)而不会遇到一些麻烦.即使我刚刚制作了一个新的maven项目(在命令行中使用了archtype),我也无法对这些方面做出太多改变.
我究竟做错了什么?
你如何明确加载一个懒惰的对象/集合?到目前为止,我发现唯一的方法是在它仍然附加到会话时明确要求对象的getter/setter:ie
List < Account > accounts = Bank.getAccounts();
accounts.get(i).getAccountNumber();
Run Code Online (Sandbox Code Playgroud)
还有另一种不那么狡猾的方法吗?
我使用Spring btw,所以根据所调用的服务,我想加载不同的集合/ obkjects
我只想用请求参数发送我的下拉列表的值.在我的情况下
Kidscalcula_web/start.htm?klasid=myValueHere
Run Code Online (Sandbox Code Playgroud)
我知道这样做的方法,但这听起来非常不合理.如果我感到无聊,我可能会写一些jQuery来做一个帖子并发送参数为例.现在真的听起来像是一个非常糟糕的想法手动创建我的请求字符串,因为Spring负责这一点.那么我怎么能做一个简单的表单,只是将我的dropdownvalue发送给我的控制器?
只是我无法在任何地方找到一些如此微不足道的东西,你们其中一个人可能会很快帮助我.我认为控制器会像以下一样微不足道:
@RequestMapping(value = "post")
public String postIndex(@RequestParam("klasid") String klasid, HttpServletResponse response,
HttpServletRequest request) {
}
Run Code Online (Sandbox Code Playgroud)
但我真的找不到任何关于如何让JSP向我发送该值的示例.这可能与<form>taglib有关吗?
我需要以JSON Object的形式向我的服务器端发送一个ID数组.我正在使用一个下拉列表,其中可以选择多个值来对它们执行操作.
为了将它们放入数组中,我使用了:
var selectedArray = [];
var selectObj = document.getElementById('addedList');
var i=0;
var count=0;
for(i=0;i<selectObj.options.length;i++){
selectedArray[count] = selectObj.options[i].value;
count++;
}
Run Code Online (Sandbox Code Playgroud)
现在的问题是,我需要将这些ID发送到服务器.我一直想把它像JSON对象一样发送,因为它有可变数量的参数.据我所知,您可以将JS对象转换为JSON.
现在我有几个问题:
你能给我一个如何转换它的例子吗?似乎有一百万种方式,其中之一就是JSON.stringify(jsObj);.我的对象只包含一组值.据我所知,这将是一个例子:
{ array : ["value1","value2","value3"] }
Run Code Online (Sandbox Code Playgroud)
另一个问题是:如何使用jQuery发送它?我可以使用$ .getJSON将JSON对象发送到服务器吗?(这在引擎盖下使用$ .GET),还是我需要使用$ .POST?
现在我一直在尝试,但无法把它弄出来......
$ .getJSON代码
$.getJSON("removerequest.htm",{ ids: JSON.stringify(selectedArray) }, function(data){
$('#removerequestdiv').text('');
$('#removerequestdiv').append('<select name="addedList">');
for(var index in data){
$('#removerequestdiv').append('<option value="' + data[index].id + '">' + data[index].voornaam + data[index].familienaam + '</option>');
}
$('#removerequestdiv').append('</select>');
});
Run Code Online (Sandbox Code Playgroud) Parsing POMs
Discovered a new module be.howest:someproject someproject
Run Code Online (Sandbox Code Playgroud)
我第一次做哈德森工作似乎找到了一个新模块.好吧,没什么可担心的,但它似乎执行了两次,我真的不知道为什么.另一件事是:它给出了这个奇怪的错误(至少对我来说):
[WARNING] Removing: cobertura from forked lifecycle, to prevent recursive invocation.
[WARNING] Removing: findbugs from forked lifecycle, to prevent recursive invocation.
Run Code Online (Sandbox Code Playgroud)
对我来说,这似乎试图执行两次,但为什么要逃避我. 此外,它在构建下有一个模块,这是我不太熟悉的东西,但如果它没有做我的测试两次,我不会打扰太多(并认为它是正常的).
现在它正在运行两个阶段:clean和test.我将其更改为clean package,因为我在包生命周期中包含了javadoc,但没有任何改变.
试图让Spring的事务管理工作,但它并没有像我希望的那样.
在请求需要我的数据库的任何内容时,我收到异常:
DEBUG: org.springframework.orm.hibernate3.SessionFactoryUtils - Opening Hibernate Session
DEBUG: org.springframework.orm.hibernate3.SessionFactoryUtils - Opening Hibernate Session
DEBUG: org.hibernate.impl.SessionImpl - opened session at timestamp: 12897642913
DEBUG: org.springframework.orm.hibernate3.SessionFactoryUtils - Closing Hibernate Session
DEBUG: org.springframework.orm.hibernate3.SessionFactoryUtils - Closing Hibernate Session
14-nov-2010 20:51:31 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet mvc-dispatcher threw exception
org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
Run Code Online (Sandbox Code Playgroud)
我已经将我的属性移动到我的Spring上下文,看看是否有更好但没有.我的配置:
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:oxm="http://www.springframework.org/schema/oxm"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context …Run Code Online (Sandbox Code Playgroud) 我希望我的读取方法不使用事务,因为根本不需要它,我只用@Transactional标记我的创建/更新方法.但是我该怎么做?我有一个非常基本的配置Spring等...
SessionFactory注入我的DAO,在每个方法中我调用sessionFactory..的getCurrentSession()doQueryStuff();
但是,这会导致此错误:
org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
Run Code Online (Sandbox Code Playgroud)
如果你需要我的Spring配置:
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:oxm="http://www.springframework.org/schema/oxm"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/oxm
http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<context:annotation-config />
<context:component-scan base-package="be.howest.kidscalcula" />
<mvc:annotation-driven />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean id="myDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/kidscalcula" />
<property …Run Code Online (Sandbox Code Playgroud) 我知道有很多主题描述了这个话题,但我仍然无法决定选择什么.首先,我要你知道我去年是学生,可能会继续学习在几年里.但是,我正试图找到我最受益的东西.
去年我和RoR有过接触; 看到Ruby的squirky语法让我感到惊讶,Rails CoC和DRY原则让我梦想成真.我已经编写了一些脚本来在Ruby中生成sql语句,但这就是全部.
我被认为是一个java开发人员,因为他们称我为学校的java人,(不,我不认为自己很好,相反,每天我都意识到我还需要学习更多).现在,我已经自学了几种与java相关的技术.为了让我的工作更轻松,我选择了学习hibernate和maven.现在我们在Spring + Spring MVC中开发一个应用程序.
Grails最近引起了我的注意,因为它是基于这些技术构建的,并且使用类似于java的语言,并允许访问java类.
但是,我不确定最好的方法是什么.我应该首先挣扎于Ruby的古怪,并学习Rails吗?或者学习Grails首先会让我比学习RoR更有优势?
另外,就我所读到的而言,RoR会让我在市场上获得比Grails更大的优势; 但是如何得到一个可以使用RoR的"证明"?是否能够显示使用RoR制作的应用程序?
spring ×5
hibernate ×4
java ×3
transactions ×2
annotations ×1
architecture ×1
eclipse ×1
facets ×1
getjson ×1
grails ×1
groovy ×1
httprequest ×1
hudson ×1
javascript ×1
jquery ×1
json ×1
lazy-loading ×1
maven ×1
maven-2 ×1
ruby ×1
session ×1
spring-mvc ×1