这是我的HTML页面:
<!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=UTF-8">
<title>Sports</title>
</head>
<body>
<center>
<h1>Configuring Database for MSell Application</h1>
<form method="post" action="http://localhost:8080/MSellApp/msellapp/DBConfig/changedb" enctype="text/plain">
<table border="0">
<tr>
<td>Database to be Used</td>
<td><select name="selectDB">
<option value=0>Sports and Outdoor</option>
<option value=1>Fashion</option>
</select>
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="submit"></td>
</tr>
</table>
</form>
</center>
</body>
</html>
这是我的春假休息服务。
@RequestMapping("/DBConfig")
@RestController
public class DBConfigController {
final static Logger logger = Logger.getLogger(DBConfigController.class);
@Autowired
DBConfig dbc;
@RequestMapping(value="/changedb",method = RequestMethod.POST,consumes="text/plain",produces="text/plain")
String changeDB(@RequestBody String db){
logger.info("DB Selected :- " +db);
System.out.println(db);
if(db.equals("selectDB=0"))
dbc.sessionFac="sports";
else
dbc.sessionFac="fashion";
return dbc.sessionFac;
}
}
字符串比较总是失败。我正在使用Spring rest API。我发现即使print语句打印相同的“selectDB = 0”,也很难解释为什么字符串比较总是失败。有人可以告诉我为什么吗?