我想知道如果有一种方法,因为1970年1月1日(时期),以获得当前毫秒使用新的LocalDate,LocalTime或LocalDateTimeJava的8类.
已知的方法如下:
long currentMilliseconds = new Date().getTime();
Run Code Online (Sandbox Code Playgroud)
要么
long currentMilliseconds = System.currentTimeMillis();
Run Code Online (Sandbox Code Playgroud) Spring Data JPA支持使用规范计算实体.但它有没有办法使用方法名称解析来计算实体?假设我想要一种方法countByName来计算具有特定名称的实体,就像findByName获取具有特定名称的所有实体的方法一样.
我正在使用Spring开发一个网站,并且我正在尝试提供不是.jsp文件的资源(例如.html)
现在我已经注释掉了我的servlet配置的这一部分
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
Run Code Online (Sandbox Code Playgroud)
并试图从控制器返回资源的完整路径.
@Controller
public class LandingPageController {
protected static Logger logger = Logger.getLogger(LandingPageController.class);
@RequestMapping({"/","/home"})
public String showHomePage(Map<String, Object> model) {
return "/WEB-INF/jsp/index.html";
}
}
Run Code Online (Sandbox Code Playgroud)
index.html文件存在于该文件夹中.
注意:当我将index.html更改为index.jsp时,我的服务器现在正确地提供页面.
谢谢.
我正在使用spring security和java config
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/api/*").hasRole("ADMIN")
.and()
.addFilterAfter(new CsrfTokenResponseHeaderBindingFilter(), CsrfFilter.class)
.exceptionHandling()
.authenticationEntryPoint(restAuthenticationEntryPoint)
.and()
.formLogin()
.successHandler(authenticationSuccessHandler)
.failureHandler(new SimpleUrlAuthenticationFailureHandler());
Run Code Online (Sandbox Code Playgroud)
我正在使用PostMan来测试我的REST服务.我成功获得'csrf token',我可以使用X-CSRF-TOKEN请求标头登录.但登录后我点击发布请求(我在请求标题中包含相同的令牌,我用于登录发布请求)我收到以下错误消息:
HTTP状态403 - 无法验证提供的CSRF令牌,因为找不到您的会话.
任何人都可以指导我做错了什么.
我正在使用spring mvc.当method = post时,我无法从url获取param.但是当我将方法改为GET时,我可以得到所有的参数.
这是我的表格:
<form method="POST" action="http://localhost:8080/cms/customer/create_customer" id="frmRegister" name ="frmRegister" enctype="multipart/form-data">
<input class ="iptRegister" type="text" id="txtEmail" name="txtEmail" value="" />
<input class ="iptRegister" type="password" id="txtPassword" name="txtPassword" value="" />
<input class ="iptRegister" type="text" id="txtPhone" name="txtPhone" value="" />
<input type="button" id="btnRegister" name="btnRegister" value="Register" onclick="" style="cursor:pointer"/>
</form>
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
@RequestMapping(value= "/create_customer", method = RequestMethod.POST)
@ResponseBody
public String createCustomer(HttpServletRequest request,
@RequestParam(value="txtEmail", required=false) String email,
@RequestParam(value="txtPassword", required=false) String password,
@RequestParam(value="txtPhone", required=false) String phone){
ResultDTO<String> rs = new ResultDTO<String>();
rs.setStatus(IConfig.SHOW_RESULT_SUCCESS_ON_MAIN_SCREEN);
try{
Customer c = new Customer();
c.setEmail(email); …Run Code Online (Sandbox Code Playgroud) 有没有办法将File对象转换为MultiPartFile?这样我就可以将该对象发送给接受MultiPartFile接口对象的方法了?
File myFile = new File("/path/to/the/file.txt")
MultiPartFile ....?
def (MultiPartFile file) {
def is = new BufferedInputStream(file.getInputStream())
//do something interesting with the stream
}
Run Code Online (Sandbox Code Playgroud) 可以使用Jackson @JsonView和@JsonFilter注释来修改Spring MVC控制器返回的JSON,同时使用MappingJacksonHttpMessageConverterSpring @ResponseBody和@RequestBody注释吗?
public class Product
{
private Integer id;
private Set<ProductDescription> descriptions;
private BigDecimal price;
...
}
public class ProductDescription
{
private Integer id;
private Language language;
private String name;
private String summary;
private String lifeStory;
...
}
Run Code Online (Sandbox Code Playgroud)
当客户端请求收集时Products,我想返回每个的最小版本ProductDescription,也许只是它的ID.然后在后续调用中,客户端可以使用此ID来请求ProductDescription包含所有属性的完整实例.
能够在Spring MVC控制器方法上指定它是理想的,因为调用的方法定义了客户端请求数据的上下文.
我发现了许多类似的问题但没有一个能解决我的问题.我的问题是ROLE_USER可以访问的功能ROLE_ADMIN
我的spring-security.xml代码如下.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:s="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<s:http auto-config="true" use-expressions="true">
<s:intercept-url pattern="/index.jsp" access="permitAll" />
<s:intercept-url pattern="/welcome*" access="hasRole('ROLE_USER')" />
<s:intercept-url pattern="/helloadmin*" access="hasRole('ROLE_ADMIN')" />
<s:form-login login-page="/login" default-target-url="/welcome"
authentication-failure-url="/loginfailed" />
<s:logout logout-success-url="/logout" />
</s:http>
<s:authentication-manager>
<s:authentication-provider>
<s:user-service>
<s:user name="asif" password="123456" authorities="ROLE_USER,ROLE_ADMIN" />
<s:user name="raheel" password="123456" authorities="ROLE_USER" />
</s:user-service>
</s:authentication-provider>
</s:authentication-manager>
Run Code Online (Sandbox Code Playgroud)
当我添加<s:global-method-security pre-post-annotations="enabled"/>
我的代码显示资源未找到错误,当我删除我的代码执行成功但ROLE_USER可以访问ROLE_ADMIN功能
我的控制器功能是.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value="/delete", method = RequestMethod.GET)
public String DeleteAll(ModelMap model, Principal principal ) {
org.springframework.security.core.userdetails.User activeUser = (org.springframework.security.core.userdetails.User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
System.out.println("Active …Run Code Online (Sandbox Code Playgroud) 我是Postgresql的新手,我正在使用WCF服务.
这是我的代码片段:
$.ajax({
url: '../Services/AuctionEntryServices.svc/InsertAuctionDetails',
data: JSON.stringify({ "objAuctionEntryEntity": {
"AuctionNO": '',
"AuctionDate": $('[Id$="lblAuctionDateVal"]').text(),
"TraderID": $('[Id$="ddlTraderName"] option:selected').val(),
"Grade": $('[Id$="ddlGrade"] option:selected').val(),
"Varity": $('[Id$="ddlVarity"] option:selected').val(),
"QuntityInAuction": $('#txtQuantityForAuction').val(),
"AuctionRate": $('#txtAuctionRate').val(),
"BrokerID": a[0],
"IsSold": $('#chlIsSold').is(':checked'),
"CreatedBy": $.parseJSON(GetCookie('Admin_User_In_Mandi')).UserID,
"UpdatedBy": $.parseJSON(GetCookie('Admin_User_In_Mandi')).UserID,
"CreationDate": GetCurrentDate().toMSJSON(),
"IsActive": true,
"AuctionTransaction": arrAuctionTransaction,
"MandiID": $.parseJSON(GetCookie('Admin_User_In_Mandi')).MandiID,
"FarmerID": _ownerid,
"AuctionNO": _auctionno,
"AmmanatPattiID": _ammantpattiid,
"ToTraderID": b[0],
"ToTraderName": $('#txtOtherBuyerNameEN').val(),
"ToTraderName_HI": $('#txtOtherBuyerNameHI').val()
}
}),
type: 'POST',
contentType: 'application/json',
dataType: 'json'
});
Run Code Online (Sandbox Code Playgroud)
这里:
$('[Id$="lblAuctionDateVal"]').text() = "20/8/2013 14:52:49"
Run Code Online (Sandbox Code Playgroud)
我的这个领域的数据类型是timestamp without time zone.
如何将此字符串转换为timestamp without time zone数据类型?
我在spring webmvc项目中使用spring-data-jpa.我在我的一个实体的存储库上使用查询创建时遇到了问题.您可以在下面看到我的实体,我的存储库和例外.
我的实体,
@Entity
@Table(schema = "mainschema")
@XmlRootElement
public class Municipalperson implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(nullable = false)
private Integer id;
@Basic(optional = false)
@Column(name = "municipal_id", nullable = false)
private Integer municipal_id;
@Basic(optional = false)
@Column(nullable = false, length = 60)
private String firstname;
public Municipalperson(Integer id, Integer municipal_id, String firstname) {
this.id = id;
this.municipal_id = municipal_id;
this.firstname = firstname;
}
public Integer …Run Code Online (Sandbox Code Playgroud) java ×9
spring ×6
spring-mvc ×3
ajax ×1
csrf ×1
datetime ×1
groovy ×1
jackson ×1
java-8 ×1
java-time ×1
javascript ×1
jpa ×1
jquery ×1
json ×1
milliseconds ×1
postgresql ×1
repository ×1
spring-data ×1
wcf ×1