有没有办法格式化JSON以在视图中显示?这样当我添加新属性时,我的API文档会自动更新?额外的功劳是用CSS包围某些元素来设计它.我也想为XML做这个.
class Student
{
static CreateEmpty()
{
return new Student() {
FirstName: 'Mike',
LastName: 'Flynn',
Classes: new List<Class>(),
School: new School() {
Name: 'High School'
}
}
}
}
<code>
@(Student.CreateEmpty().ToJSON())
</code>
Run Code Online (Sandbox Code Playgroud)
至
<code>
{
FirstName: 'Mike',
LastName: 'Flynn',
Classes: [],
School: {
Name: 'High School'
}
}
</code>
Run Code Online (Sandbox Code Playgroud) 我有一个单一的网页应用程序,都是JavaScript.我注意到每次返回新视图的AJAX调用都会出现JavaScript堆大小.我应该做些什么来清理旧观点?
我无法弄清楚为什么下面代码的时区一直显示UTC而不是EST.在我的本地计算机上它显示EST,即使我在MST时间但在实际服务器上它仍然显示UTC.任何线索?
Mon Nov 9 2015 1:58:49 PM UTC
@JsonIgnore
public String getDateCreatedFormatted() {
Calendar calendar = Calendar.getInstance();
calendar.setTime(getDateCreated());
calendar.setTimeZone(TimeZone.getTimeZone("EST"));
SimpleDateFormat format = new SimpleDateFormat("EEE MMM d yyyy h:mm:ss a z");
return format.format(calendar.getTime());
}
Run Code Online (Sandbox Code Playgroud) 当我在动作上有CompressFilter并且它们是错误时,我没有得到我的ExceptionHandling命中.请求未返回任何响应.如果我删除压缩过滤器然后它返回错误数组就好了.如何在错误上跳过压缩过滤器,或者让它达到第二个?
控制器动作
[HttpPost, CompressAttribute]
public virtual ActionResult Builder()
Run Code Online (Sandbox Code Playgroud)
Global.asax中
GlobalConfiguration.Configuration.Filters.Add(new ExceptionHandlingAttribute());
Run Code Online (Sandbox Code Playgroud)
CompressFilter
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
public class CompressAttribue : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var encodingsAccepted = filterContext.HttpContext.Request.Headers["Accept-Encoding"];
if (string.IsNullOrEmpty(encodingsAccepted)) return;
encodingsAccepted = encodingsAccepted.ToLowerInvariant();
var response = filterContext.HttpContext.Response;
if (encodingsAccepted.Contains("gzip"))
{
response.AppendHeader("Content-encoding", "gzip");
response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
}
else if (encodingsAccepted.Contains("deflate"))
{
response.AppendHeader("Content-encoding", "deflate");
response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
}
}
}
Run Code Online (Sandbox Code Playgroud) 我想知道Java Spring MVC是否有某种与返回部分视图(如ASP.NET MVC)相关的实现?基本上我想返回HTML,绑定到一个对象并将其返回到javascript回调以附加到dom,而不是使用Jquery构建html(这是单调乏味的).如果不是,我可以使用Jquery模板.
为什么我的测试中下面的响应总是为空?
SSO.cs
public class SSO : ISSO
{
const string SSO_URL = "http://localhost";
const string SSO_PROFILE_URL = "http://localhost";
public AuthenticateResponse Authenticate(string userName, string password)
{
return GetResponse(SSO_URL);
}
public void GetProfile(string key)
{
throw new NotImplementedException();
}
public virtual AuthenticateResponse GetResponse(string url)
{
return new AuthenticateResponse();
}
}
public class AuthenticateResponse
{
public bool Expired { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
SSOTest.cs
[TestMethod()]
public void Authenticate_Expired_ReturnTrue()
{
var target = MockRepository.GenerateStub<SSO>();
AuthenticateResponse authResponse = new AuthenticateResponse() { Expired = true }; …Run Code Online (Sandbox Code Playgroud) 我有一个名为ImporterState的复合表,它与一个名为Importer和State的表相关联.这里发生错误context.Importers.Include(q => q.States).为什么会这样?
{"无效的对象名称'ImporterStates'."}
[Table("HeadlineWebsiteImport", Schema = "GrassrootsHoops")]
public class Importer
{
public int Id { get; set; }
public string Name { get; set; }
public string RssUrl { get; set; }
public string Type { get; set; }
public string Keywords { get; set; }
public bool Active { get; set; }
public DateTime DateModified { get; set; }
public DateTime DateCreated { get; set; }
public int WebsiteId { get; set; }
public HeadlineWebsite Website …Run Code Online (Sandbox Code Playgroud) 我想知道在WHERE子句和NULL值中处理多个条件时哪个是更好的性能或最佳实践.
WHERE
u.id = COALESCE(user_id, u.id) AND
su.custom_id = COALESCE(student_number, su.custom_id)
Run Code Online (Sandbox Code Playgroud)
要么
WHERE
CASE
WHEN user_id IS NOT NULL AND LENGTH(user_id) > 0
THEN
u.id = user_id
ELSE
su.custom_id = student_number
END
Run Code Online (Sandbox Code Playgroud) 为什么这条路线http://localhost:2222/2012-adidas-spring-classic/37不能从下面的路线中获取?我收到404错误.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*vti_inf}", new { vti_inf = @"(.*/)?_vti_inf.html(/.*)?" });
routes.IgnoreRoute("{*vti_rpc}", new { vti_rpc = @"(.*/)?_vti_rpc(/.*)?" });
#region API
routes.MapRouteLowercase(
"NamedHomeEvent",
"{year}-{name}/{Id}",
new { controller = "Event", action = "Index", year = DateTime.Now.Year },
new { year = @"\d{4}", Id = @"\d+" }
);
public virtual ActionResult Index(int? id, int? year, string name)
{
Run Code Online (Sandbox Code Playgroud) asp.net-mvc ×4
java ×2
performance ×2
.net ×1
ajax ×1
c# ×1
calendar ×1
case ×1
classloader ×1
css ×1
heap ×1
javascript ×1
json ×1
linux ×1
mysql ×1
null ×1
razor ×1
rhino-mocks ×1
spring-mvc ×1
sql ×1
timezone ×1
unit-testing ×1
xml ×1