int i = Integer.parseInt(request.getParemeter("value"));
时间: 2024-05-28 09:13:00 浏览: 16
这段代码的作用是将请求中名为"value"的参数解析成整数类型,并赋值给变量i。具体来说,它调用了request对象的getParameter方法来获取名为"value"的请求参数,并使用Integer.parseInt方法将其解析成整数类型。如果无法解析,会抛出NumberFormatException异常。
相关问题
springboot 两个方法都执行成功后数据才提交 public ResultRespone saveYhda(@RequestBody DaCustomer daCustomer,@RequestBody DaMeter daMeter ) { //获取最大用户编号 Map<String ,Object> map= daCustomerMapper.selectMaxCustomerNo(); int yhbh=Integer.parseInt(map.get("CUSTOMER_NO").toString())+1; daCustomer.setCustomerNo(String.valueOf(yhbh)); daCustomer.setCustomerNoOld(String.valueOf(yhbh)); if(daCustomerService.save(daCustomer)) { daMeterService.save(daMeter); } return ResultRespone.success(); }
可以使用声明式事务管理(基于注解的方式)实现两个方法都执行成功后数据才提交的需求。具体实现方式如下:
```java
@Transactional(rollbackFor = Exception.class)
public ResultRespone saveYhda(@RequestBody DaCustomer daCustomer, @RequestBody DaMeter daMeter) {
//获取最大用户编号
Map<String, Object> map = daCustomerMapper.selectMaxCustomerNo();
int yhbh = Integer.parseInt(map.get("CUSTOMER_NO").toString()) + 1;
daCustomer.setCustomerNo(String.valueOf(yhbh));
daCustomer.setCustomerNoOld(String.valueOf(yhbh));
if (daCustomerService.save(daCustomer)) {
daMeterService.save(daMeter);
}
return ResultRespone.success();
}
```
在上面的代码中,我们通过在方法上添加 `@Transactional` 注解实现了事务管理。该注解默认开启了一个事务,如果方法执行成功,则自动提交事务,否则自动回滚事务。同时,我们还通过 `rollbackFor` 属性配置了回滚的异常类型。在这里,我们配置了所有异常类型都会回滚事务。
需要注意的是,在这里的 `save()` 方法中,如果其中一个方法执行失败,会抛出异常,事务将自动回滚。同时,由于该方法使用了 `@RequestBody` 注解,需要确保请求体中包含正确的 JSON 数据,否则会导致请求失败。
@RequestMapping("get_stu_info_list") public String getStuInfoList(HttpServletRequest request, Model model){ String field_name = request.getParameter("columnName"); String field_value = request.getParameter("content"); int start_page = Integer.parseInt(request.getParameter("start_page")); if (start_page <= 0) start_page = 1; int page_size = Integer.parseInt(request.getParameter("page_size")); //自己测试的时候写输出语句验证数据正确 List<StuInfo> stuInfoList = null; stuInfoList = stuInfoService.getStuInfoList(field_name, field_value, start_page, page_size); model.addAttribute("stu_info_list", stuInfoList); model.addAttribute("columnName", field_name); model.addAttribute("content", field_value); model.addAttribute("start_page", start_page); model.addAttribute("page_size", page_size); return "stu_info_list"; } }
这段代码是一个 Java Web 应用程序中的 Controller 层的代码。它的作用是处理一个名为 "get_stu_info_list" 的请求,并返回一个名为 "stu_info_list" 的 JSP 页面。
具体来说,这个请求会传入一些参数,包括查询字段名、查询字段的值、起始页码和每页记录数。这些参数会被用来调用 stuInfoService 中的 getStuInfoList 方法,这个方法会返回一个学生信息列表。然后,这个列表会被添加到 Model 中,并被传递给 JSP 页面进行渲染。
在 JSP 页面中,这个列表会被展示出来,同时还会展示查询条件和分页信息。用户可以通过 JSP 页面中的表单来修改查询条件或者翻页。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![sql](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page import="com.test.bean.Goods,java.util.ArrayList" %> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>购物车</title> <style type="text/css"> table{border-collapse:collapse;} td{border:1px solid black; text-align:center; } #deal{margin-left:200px} </style> </head> <body> <jsp:useBean id="cart" class="com.test.bean.Cart" scope="session"></jsp:useBean> <%if(cart==null||cart.getGoodslist().size()==0) out.println("购物车空空如也.....返回商品首页"); else{ ArrayList<Goods>goodslist=cart.getGoodslist(); %> 当前购物车共有<%=cart.getGcount() %>件物品 返回商品首页
序号 商品号 商品名称 价格 数量 小计 描述 <%for(int i=0;i<goodslist.size();i++){ Goods goods=goodslist.get(i); %> <%=i+1 %> <%=goods.getGid() %> <%=goods.getGname() %> <%= String.format("%.2f", goods.getGprice())%> <%=goods.getGcount() %> <%=String.format("%.2f", goods.getGprice()*goods.getGcount()) %> 删除 <%}%>
总计<%=String.format("%.2f",cart.getTotal())%> <input type="button" id="deal" value="购买" /></input> <%}%> <script type="text/javascript"> var dealbutton=document.getElementById("deal"); dealbutton.onclick=function(){ var cf=confirm("确定购买吗?"); if(cf==true){ window.location.href="Servlet/DealServlet"; } } </script> </body> </html> 修改删除功能,在购物车物品数量大于1的情况下点击“删除”时减少1个,等于1时删除此项商品;
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
给下面代码增加分页功能,要求细致,逻辑清楚,<form action="./../selectNews" method="post"> <input type="text" name="key" id="key" placeholder="请输入标题"/> <input type="submit" value="查询"/> 发布新闻 返回主页 </form> 新闻编号 新闻标题 <%-- 新闻内容 --%> 新闻类别 发布人 发布时间 状态 是否头条 操作 <c:forEach items="${newslist}" var="u"> ${u.nid} ${u.title} <%-- ${u.content} --%> ${u.type} ${u.userName} ${u.pubTime} <c:choose> <c:when test="${u.state==0}">未审核</c:when> <c:when test="${u.state==1}">审核通过</c:when> <c:otherwise>未通过</c:otherwise> </c:choose> <c:choose> <c:when test="${u.top==0}">否</c:when> <c:otherwise>是</c:otherwise> </c:choose> <c:choose> <c:when test="${user.rule==1}"> 查看 修改 删除 审核 </c:when> <c:when test="${user.rule==0 && user.uid==u.uid}"> 查看 修改 删除 </c:when> <c:otherwise> 查看 </c:otherwise> </c:choose> </c:forEach>
<% //连接数据库 String driver = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/votedb?serverTimezone=UTC&characterEncoding=UTF-8"; String username = "root"; String password = "123456"; Connection conn = null; Statement stmt = null; ResultSet rs = null; try { Class.forName(driver); conn = DriverManager.getConnection(url, username, password); stmt = conn.createStatement(); rs = stmt.executeQuery("SELECT * FROM vote"); while(rs.next()){ String title = rs.getString("title"); %> <input type="radio" name="option" value="<%=title%>"><%=title%>
<% } } catch (Exception e) { e.printStackTrace(); } finally { //关闭连接 try { if (rs != null) { rs.close(); } if (stmt != null) { stmt.close(); } if (conn != null) { conn.close(); } } catch (SQLException e) { e.printStackTrace(); } } %> 提交投票选中后数据库数据变化
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
<% //连接数据库 String driver = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/votedb?serverTimezone=UTC&characterEncoding=UTF-8"; String username = "root"; String password = "123456"; Connection conn = null; Statement stmt = null; ResultSet rs = null; try { Class.forName(driver); conn = DriverManager.getConnection(url, username, password); stmt = conn.createStatement(); rs = stmt.executeQuery("SELECT * FROM vote"); while(rs.next()){ String title = rs.getString("title"); %> <input type="radio" name="option" value="<%=title%>"><%=title%>
<% } } catch (Exception e) { e.printStackTrace(); } finally { //关闭连接 try { if (rs != null) { rs.close(); } if (stmt != null) { stmt.close(); } if (conn != null) { conn.close(); } } catch (SQLException e) { e.printStackTrace(); } } %> 提交投票选中后数据库数据变化
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)