小编mrj*_*per的帖子

如何在Spring MVC控制器类中访问自定义bean?

我是春天的新手所以请耐心等待.

我看着这个指南(http://java2t.com/233/using-spring3-jdbctemplate-rowmapper-to-return-list-of-records/).它在eclipse中使用"普通"java项目.我正在尝试使用动态Web项目来模拟示例,但我没有取得任何成功.

我的web.xml

<?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"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    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>StaffDirectory</display-name>

    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>    
</web-app>
Run Code Online (Sandbox Code Playgroud)

我的spring-servlet.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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan base-package="org.flinders.staff.directory" />

    <mvc:annotation-driven />
    <mvc:resources mapping="/resources/**" location="/resources/" />
    <mvc:view-controller path="/" view-name="index"  /> 

    <bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/test" />
        <property name="username" value="root" />
        <property name="password" value="PVHmg57bE4" />
    </bean>

    <bean …
Run Code Online (Sandbox Code Playgroud)

model-view-controller spring javabeans

4
推荐指数
1
解决办法
1万
查看次数

在IE11中没有清除cookie(cookie是通过Javascript写入document.cookie设置的)

所以我通过写入document.cookie 手动通过Javascript 手动设置了一些cookie ,并且它们写得很好.

我查了一下

console.log(document.cookie)
Run Code Online (Sandbox Code Playgroud)

我的问题是,即使我手动清除了我的历史记录

  • 互联网选项=>浏览历史记录=>删除(确保勾选"Cookie和其他网站数据")
  • 确保勾选"退出时删除浏览历史记录",并勾选"Cookie和其他网站数据"

document.cookie仍显示我手动创建的cookie值.

我试过的事情:

  • 关闭标签.手动清除我的历史.然后在新标签上重新打开我的页面
  • 完全关闭IE11.重新打开应用程序.然后在新选项卡上打开我的页面

我有什么想法可能做错了吗?

谢谢

PS.虽然我可以通过Javascript使我的cookie过期.我不能指望最终用户这样做.:)

javascript cookies internet-explorer internet-explorer-11

4
推荐指数
1
解决办法
590
查看次数

org.hibernate.AssertionFailure:未启用getGeneratedKeys()支持(使用Oracle11g)

我在桌子上做了一个"简单",它给出了这个错误.搜索网络没有帮助.

我认为它使用序列作为我的主键的源来连接到我.

你能帮忙吗?谢谢

代码我正在尝试运行(我突出显示了抛出错误的部分)

    EventInstance eventInstance = (EventInstance) sessionFactory.getCurrentSession().get(EventInstance.class, userEventRegistration.getEventInstance().getInstanceId());
    Student student = (Student) sessionFactory.getCurrentSession().get(Student.class, userEventRegistration.getStudent().getStudentId());
    EventRegistration eventRegistration = new EventRegistration();

    if (student == null) {
        student = new Student();
        student.setStudentId(userEventRegistration.getStudent().getStudentId());
    }

    student.setFamilyName(userEventRegistration.getStudent().getFamilyName());
    student.setGivenName(userEventRegistration.getStudent().getGivenName());
    student.setGender(userEventRegistration.getStudent().getGender());
    student.setEmail(userEventRegistration.getStudent().getEmail());
    student.setHomeCountry(userEventRegistration.getStudent().getHomeCountry());
    student.setCourse(userEventRegistration.getStudent().getCourse());
    student.setAccomodationName(userEventRegistration.getStudent().getAccomodationName());
    student.setAddress(userEventRegistration.getStudent().getAddress());
    student.setAddressCity(userEventRegistration.getStudent().getAddressCity());
    student.setContactPhone(userEventRegistration.getStudent().getContactPhone());
    student.setContactDetailsStatus(userEventRegistration.getStudent().getContactDetailsStatus());
    student.setContactDetailsDate(userEventRegistration.getStudent().getContactDetailsDate());
    student.setScholarships(userEventRegistration.getStudent().getScholarships());
    student.setDietaryRestrictions(userEventRegistration.getStudent().getDietaryRestrictions());
    student.setStudentComments(userEventRegistration.getStudent().getStudentComments());
    student.setInternalComments(userEventRegistration.getStudent().getInternalComments());

    eventRegistration.setEventInstance(eventInstance);
    eventRegistration.setStudent(student);
    eventRegistration.setAttended(userEventRegistration.getAttended());
    eventRegistration.setSubmitDateTime(new Date());
    eventRegistration.setAdditionalInfo(userEventRegistration.getAdditionalInfo());
    eventRegistration.setNumberAttending(userEventRegistration.getNumberAttending());
    eventRegistration.setArchiveDate(userEventRegistration.getArchiveDate());

    **sessionFactory.getCurrentSession().save(eventRegistration);**

    sessionFactory.getCurrentSession().getTransaction().commit();
Run Code Online (Sandbox Code Playgroud)

hibernate映射

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="com.myapps.issu.models.database.Event" table="events">
        <id name="eventId" column="event_id" type="integer" />

        <property name="eventName" …
Run Code Online (Sandbox Code Playgroud)

hibernate

3
推荐指数
1
解决办法
2304
查看次数

如何将表字段映射到主题实体中的不同名称的变量?

我的模型/实体类中有一个变量$ pk.我想将它映射到我的表中的table_pk字段.

我该怎么做呢?

我正在阅读本手册=> http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/annotations-reference.html#annref-column.但似乎什么也没做我想要的.

关于如何使用注释和yaml映射完成此操作的示例将非常感激.

php doctrine-orm

3
推荐指数
1
解决办法
1597
查看次数

如何在查询查询中使用函数?

我想在下面的QoQ中实现类似于IIF的东西.但它给了我一个错误.要么我做错了,要么就是不可能.希望它是前者.

<cfquery dbtype="query">
select 
  lastname + IIF(Len(firstname) > 0, DE(", " & firstname), DE("")) as fullname 
from myquery
</cfquery>
Run Code Online (Sandbox Code Playgroud)

我收到这个错误:

查询查询语法错误.
遇到"(.不正确的Select语句,期待'FROM',但遇到'('相反,一个select语句应该有一个'FROM'结构.

关于如何解决这个问题的任何想法?

coldfusion cfquery

3
推荐指数
1
解决办法
399
查看次数

MySQLWorkbench:获取"访问被拒绝.显示数据库权限所需"错误

所以我试图使用最新版本的MySQLWorkbench(6.3.6)远程连接到MySQL 5.1.x服务器.

我在MySQL提示符下运行了这些命令:

use mysql;
grant all privileges on mydb.*  to 'myuser'@'%' identified by 'mypassword';
flush privileges;
Run Code Online (Sandbox Code Playgroud)

我可以使用工作台连接到架构/数据库,但我无法获得表/其他架构对象的列表.

这是我得到的确切答案:

Error Code: 1227 Access denied; you need the SHOW DATABASES privilege for this operation
Run Code Online (Sandbox Code Playgroud)

这是我从节目赠款中得到的回应.我在localhost上以root用户身份运行它.我弄乱了可能识别我的数据库的任何信息.

mysql> show grants for 'mydb'@'%';
+-----------------------------------------------------------------------------------------------------+
| Grants for mydb@%                                                                                   |
+-----------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'mydb'@'%' IDENTIFIED BY PASSWORD 'mypassword' |
| GRANT ALL PRIVILEGES ON `mydb`.* TO 'mydb'@'%'                                                      |
+-----------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)

关于如何修复它的任何想法?谢谢.

mysql

3
推荐指数
1
解决办法
1041
查看次数

奇怪的if-then行为在Java中

可能重复:
如何比较Java中的字符串?

我有这个代码:

    System.out.println(staff.getEmail().length());
    System.out.println(staff.getEmailList());
    if ((staff.getEmail().length() > 0) && (staff.getEmailList() == "Y")) {
        System.out.println(staff.getEmail());
Run Code Online (Sandbox Code Playgroud)

这是我的eclipse控制台上的输出:

12
Y
Run Code Online (Sandbox Code Playgroud)

我的问题是,即使满足if语句中的两个条件,我的程序也永远不会到达上面的最后一行代码(System.out.println(staff.getEmail())).我也没有任何错误.

我有什么想法,我做错了什么?谢谢 :)

java

2
推荐指数
1
解决办法
91
查看次数

无法加载Twig模板(Symfony 2.8.8)

所以我有以下文件夹结构:

在此输入图像描述

根据Symfony手册(点击这里),我应该可以加载我的Twig模板,但Symfony找不到它.

在此输入图像描述

我有什么想法可能做错了吗?谢谢.


代码我试过了

    return $this->render(
        "AppBundle:DisplayForm.html.twig"
        , array(
            "form" => $form->createView()
    );

    return $this->render(
        "DisplayForm.html.twig"
        , array(
            "form" => $form->createView()
        )
    );
Run Code Online (Sandbox Code Playgroud)

我的app/AppKernel.php的内容

<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new AppBundle\AppBundle(),

            new Symfony\Bundle\AsseticBundle\AsseticBundle(),
        );

        if (in_array($this->getEnvironment(), array('dev', 'test'), true)) {
            $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle(); …
Run Code Online (Sandbox Code Playgroud)

symfony twig

2
推荐指数
1
解决办法
2659
查看次数

ColdFusion 2018:如何正确设置映射?

这些是我使用的步骤:

1)我在CF Server中创建了新的映射=>服务器设置=>映射

logical path: /mysite
directory path: /Volumes/drive2/work/mysite
Run Code Online (Sandbox Code Playgroud)

2)我重启了服务器

/Applications/ColdFusion2018/cfusion/bin/coldfusion stop && /Applications/ColdFusion2018/cfusion/bin/coldfusion start
Run Code Online (Sandbox Code Playgroud)

3)使用首选的文本编辑器,我在/ Volumes / drive2 / work / mysite中创建了test.cfm,内容如下

<cfdump var="#CGI#">
Run Code Online (Sandbox Code Playgroud)

4)然后我尝试通过浏览器在浏览器中查看新文件

localhost:8500/mysite/test.cfm
Run Code Online (Sandbox Code Playgroud)

然后,我收到404错误。确切的消息就像“ coldfusion.runtime.TemplateNotFoundException:找不到文件:/mysite/test.cfm”

我检查了以下两件事:

  1. 我验证了/ Volumes / drive2 / work / mysite可以被所有人阅读(755许可)
  2. 我验证了/Volumes/drive2/work/mysite/test.cfm可以被所有人读取(644权限)

除了创建映射,我更改的其他配置还有:

  1. 为我的应用程序创建了数据源
  2. 启用调试/日志记录,但仅在出现第一个404错误之后

有什么想法我可能做错了吗?还是我应该设置的其他设置?我在下面添加了“映射”部分的屏幕截图。

谢谢!

编辑:我正在使用独立/开发人员版提供的内置Web服务器。我也在使用本地主机。

在此处输入图片说明

coldfusion cfadmin coldfusion-2018

2
推荐指数
1
解决办法
123
查看次数

使用LINQ从Microsoft CRM检索数据时出现奇怪的行为

我在使用LINQ访问Contact实体时遇到此问题.

我有以下2个功能.

如果我运行第一个函数然后调用第二个函数,我似乎在第二个查询中缺少很多字段.就像firstname和lastname没有出现一样.它们只显示为空值.如果我自己运行第二个功能,我会得到正确的数据.在两次运行中唯一正确显示的字段是Id,ContactId和new_username.

如果我自己运行第二个功能,我会得到正确的数据.

有什么想法我做错了什么?

非常感谢

这是2个功能

    public List<String> GetContactsUsernameOnly()
    {
        IQueryable<String> _records = from _contactSet in _flinsafeContext.ContactSet
                                       where
                                           _contactSet.new_FAN == "username"
                                       orderby _contactSet.new_username
                                       select _contactSet.new_username;

        return _records.ToList();
    }

    public List<Contact> GetContacts()
    {
        IQueryable<Contact> _records = from _contactSet in _flinsafeContext.ContactSet
                                       where
                                           _contactSet.new_FAN == "my-username-here"
                                       orderby _contactSet.new_username
                                       select _contactSet;

        return _records.ToList();
    }
Run Code Online (Sandbox Code Playgroud)

c# linq microsoft-dynamics dynamics-crm-2011

1
推荐指数
1
解决办法
1001
查看次数