我是Spring的新手.我在eclipse中创建了一个maven项目,通过类似Spring示例SVN存储库中的mvc-basic示例来测试Spring MVC.当我试图在jsp中检索模型值时,jsp只显示$ {模型属性名称},而不是模型属性值.
我是否会错过任何使Spring无法检索模型值的内容?
以下是详细信息:
代码:控制器:
@Controller
public class TestAction {
@RequestMapping(value="/test" , method=RequestMethod.GET)
public String returnHelloWorld(Model model)
{
ObjectTest objectTest=new ObjectTest();
objectTest.setName("heng");
model.addAttribute(objectTest);
return "/test/start";
}
}
Run Code Online (Sandbox Code Playgroud)
代码JSP:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
hello ${objectTest.name}
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
在服务器(tomcat 6)上运行时,显示的页面就像
你好$ {objectTest.name}
但应该是
你好
POM.XML文件: …
我有一个facebook应用程序.
Facebook说我需要重定向到某个facebook网址,以便用户授予应用程序权限.
我目前有一个视图phtml文件,以下工作正常:
<script type="text/javascript">
top.location.href = 'https://www.facebook.com/dialog/oauth?client_id=<?php echo $this->fbAppId?>&redirect_uri=<?php echo $this->serverUrl() . $this->baseUrl() . $this->url(array('controller' => 'index', 'action' => 'post-authorize'))?>&scope=publish_stream,user_birthday,user_about_me,user_activities,user_location';
</script>
Run Code Online (Sandbox Code Playgroud)
但是 - 我想尝试一种不同的方法,通过不渲染视图来节省资源和处理时间,只需通过Location头重定向(使用重定向器动作助手或任何其他动作帮助器).
在视图脚本中,我使用ServerUrl视图助手来生成绝对路径.
如何在不使用视图助手的情况下在控制器中生成绝对路径?
我不知道如何在MVC模式中使用控制器内的视图助手是一个很好的做法.
注意:重定向到facebook,我自己的网站url作为get参数附加.所以我需要的绝对网址是我自己而不是facebook.这意味着使用该setUseAbsoluteUri方法对我没用,因为它可以在facebook url上运行,而不是我的.
我想声明一些PHP函数,我想在magento中的各个地方调用这些函数.通常在我的核心php项目中,我在functions.php中声明php函数,我在所有页面中包含该文件.我不是熟悉MVC结构.所以我可以在哪里声明这些功能.
谢谢
编辑: -
Mango_Myfunc.xml(app/etc/modules)
<?xml version="1.0"?>
<config>
<modules>
<Mango_Myfunc>
<active>true</active>
<codePool>local</codePool>
</Mango_Myfunc>
</modules>
</config>
Run Code Online (Sandbox Code Playgroud)
Config.xml(app/code/local/Mango/Myfunc/etc/configure.xml)
<?xml version="1.0"?>
<config>
<modules>
<Mango_Myfunc>
<version>0.1.0</version>
</Mango_Myfunc>
</modules>
<global>
<helpers>
<Myfunc>
<class>Mango_Myfunc_Helper</class>
</Myfunc>
</helpers>
</global>
</config>
Run Code Online (Sandbox Code Playgroud)
Data.php(app/code/local/Mango/Myfunc/helper/Data.php)
class Mango_Myfunc_Helper_Data extends Mage_Core_Helper_Abstract
{
public function short_str ($str, $len, $suf = '...') {
if (strlen($str) > $len)
return substr($str, 0, $len - strlen($suf) ) . $suf;
return $str;
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我添加的内容
我用下面的一个来调用list.phtml中的函数
echo $this->helper('Myfunc/Data')->short_str("test","3"); got the error
Run Code Online (Sandbox Code Playgroud)
致命错误:找不到类'Mage_Myfunc_Helper_Data'
我正在使用DataAnnotations将验证应用于MVC ViewModel,它是几个实体框架对象和一些自定义逻辑的组合.已经为接口中的实体对象定义了验证,但是如何将此验证应用于ViewModel?
我最初的想法是将接口组合成一个并将组合接口应用于ViewModel,但这不起作用.这是一些示例代码,展示了我的意思:
// interfaces containing DataAnnotations implemented by entity framework classes
public interface IPerson
{
[Required]
[Display(Name = "First Name")]
string FirstName { get; set; }
[Required]
[Display(Name = "Last Name")]
string LastName { get; set; }
[Required]
int Age { get; set; }
}
public interface IAddress
{
[Required]
[Display(Name = "Street")]
string Street1 { get; set; }
[Display(Name = "")]
string Street2 { get; set; }
[Required]
string City { get; set; }
[Required]
string State { …Run Code Online (Sandbox Code Playgroud) Google建议将MVP用于构建GWT应用程序的原因是什么?当View层直接意识到模型是什么时,我真的很喜欢MVC方法 - 为什么他们认为这是个坏主意?
我无法弄清楚为什么会这样.我正在从Game类创建一个View类,然后我尝试从View in Game中调用一个方法,并将整个游戏对象作为参数发送给它.如果我发送单个变量作为参数然后它没有问题,但我想发送整个Game对象,以便只传递一件事.
游戏课
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace Airfield
{
public class Game : Microsoft.Xna.Framework.Game
{
// Device Objects
GraphicsDevice device = null;
GraphicsDeviceManager graphics = null;
MouseState mouse;
// Game Objects
SpriteBatch spriteBatch;
Texture2D b = null;
View view = null;
// Arrays
Buoy [] buoy = new Buoy[3];
Plane [] plane = new Plane[3];
// Variables
bool selected = false;
int …Run Code Online (Sandbox Code Playgroud) 我有一个包含一个或多个问题的Project类:
public class Project
{
public int Id {get; set;}
public string Name {get; set;}
public List<Issue> Issues {get; set;}
}
public class Issue
{
public int Id {get; set;}
public string Description {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
我在构建我的mvc应用程序时遇到问题,以便问题是URL路由上项目的子项?
/projects/details/1/issues/ - Display list of project issues
/projects/details/1/issues/1 - Display issue #1
/projects/details/1/issues/2 - Display issue #2
/projects/details/1/issues/create/ - Create a new issue for project #1
Run Code Online (Sandbox Code Playgroud)
我最初的想法是创建一条导致以下Action Method的路线
public ActionResult Details(int projectId, string action)
{
if(action =="issues")
{
//Call ActionMethod...
}
}
Run Code Online (Sandbox Code Playgroud)
但它感觉不对.有什么建议?用RoR这样的事情是真的吗?
model-view-controller asp.net-mvc design-patterns url-routing ruby-on-rails-3
在我的ZF 1.11应用程序中,我将我的翻译器存储在注册表中,如下所示:
Zend_Registry::set('Zend_Translate', $translator);
Run Code Online (Sandbox Code Playgroud)
所以在我的视图脚本中,我可以这样访问翻译器:
$this->translate('abc');
Run Code Online (Sandbox Code Playgroud)
是否有任何聪明的方法可以使用此调用:
$this->_('abc');
Run Code Online (Sandbox Code Playgroud)
使用$ this-> translate会使视图变得混乱,而且很多人习惯于看到_().
我是rails开发的初学者,并从cakephp转移.
在cakephp中,您可以在布局中自动包含任何与控制器或操作命名相同的javascript文件.
例如www.website.com/post/add
post.js和post/add.js都会自动加载(如果存在).
有没有办法在rails中执行此操作?我尝试做谷歌,但不知道搜索什么,并没有出现太多.
(与css相同)