为什么我在pwaSourceId中得到零,但我通过了13个表格网址,我也在控制器上打印,并且还在dao stil它的零也在那里?

时间:2017-08-03 07:39:29

标签: java spring rest

这是我的Dao.java类

public int updatePwaSourceDetails(PwaSourceDetails pwa){System.out.println("pwa.getPwaSourceID()"); //out is zero here 
    String query="update pwa_source set name='"+pwa.getName()+"',is_deleted='"+pwa.getIsDeleted()+"',created_by='"+pwa.getCreatedBy()+"',created_time='"+pwa.getCreatedTime()+"',modified_by='"+pwa.getModifiedBy()+"',modified_time='"+pwa.getModifiedTime()+"'  where pwa_source_id="+pwa.getPwaSourceID()+"";  
    return jdbcTemplate.update(query);
    }

这是我的控制器类

@RequestMapping(value="/update",method = RequestMethod.PUT)
public void updateEmployeee(@ModelAttribute("PwaSourceDetails") PwaSourceDetails pwa1)
{
System.out.println("pwa1.getPwaSourceID()"); //out is zero here also  
pwaSourceDetailsService.updatePwaSourceDetails(pwa1);
}

这是网址

http://localhost:7080/vitality-web/boardsource/update?pwaSourceId=13&name=Agile&isDeleted=0&createdBy=1&createdTime=2017-08-02%2005:00:00&modifiedBy=1&modifiedTime=2017-08-02%2005:00:00

在数据库中

pwaSourceId-int
name-varchar
isDeleted-int
createdBy-int
createdTime-Timestamp
modifiedBy-int
modifiedTime-Timestamp

这是我得到的错误

root cause

org.springframework.jdbc.BadSqlGrammarException: StatementCallback;
bad SQL grammar [update pwa_source set name='nitish',is_deleted=0,created_by=1,created_time=,modified_by=1,modified_time=  where pwa_source_id=0];
nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
'modified_by=1,modified_time=  where pwasourceid=0' at line 1

3 个答案:

答案 0 :(得分:0)

您可以在网址中发送参数,例如在GET请求中,但您的控制器希望您在请求正文中发送模型。您可以在此处找到示例:https://stackoverflow.com/a/35880456/8319308

答案 1 :(得分:0)

你需要一个@RequestParam,并且你发送pwaSourceId作为单个数字,所以你的控制器方法应该是这样的

@RequestMapping(value="/update",method = RequestMethod.PUT)
public void updateEmployeee(@RequestParam("PwaSourceDetails") long pwa1)

答案 2 :(得分:0)

将您的.select{ width:100%; padding-left: 2%; text-align: left; margin: 10px auto 10px; position: relative; } #select{ border: 1px solid #ccc; font-size: 16px; height: 34px; width: 150px; background-color: aqua; } .selectLabel{ display:inline-block; height: 34px; width: 150px; line-height:34px; background-color: aquamarine; }替换为<div className='select'> <label class='selectLabel'>Label</label><select id ='select'> <option>A</option> <option>B</option> </select> </div>注释,并以JSON格式发送数据,如下所示

@ModelAttribute("PwaSourceDetails")