发表于: 2018-02-09 23:56:09

1 679


因为改老是做不好,所以我从how2java网站下载下来了他的Eclipse所做的SSM文件,

用IDEA打开,改成maven模式,把以前的pom.xml文件里面的内容放进去,然后把mapper里面的category.xml文件放进去resource里面,

applicationContext.xml里面的内容换成以前student.SSM里面的,value="classpath:mapper/Category.xml"/>

alibaba换成how2java

jabc连接数据库里面的url路径要改

<property name="url">
   <value>jdbc:mysql://localhost:3306/how2java</value>

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">

运行:报错No tests found matching Method

解决方案:@Before加上
@Test标签。在MybatisTest里面加入了@Before

@Autowired
private CategoryMapper categoryMapper;


@Before
public void setUp() throws Exception {
}

@Test
public void testAdd() {
  
for (int i = 0; i < 100; i++) {
      Category category =
new Category();
     
category.setName("new Category");
     
categoryMapper.add(category);
  
}

 

测试类不关tomcat里面的问题

即便把测试类删掉,也可以运行tomcat。主要关于CategoryController里面

 

运行的时候,一开始无法运行tomcat,我点了edit configurations,更改端口号,Deployment里面更改了ssm:war explodedapplyOK

运行tomcat,但是输入http://localhost:8123/listCategory也没有显示

于是点击FileModules、如图,

图片里面错了不是jsp所在文件夹,而是jsp所在问价夹的所在文件夹,如下图

选择WEB-INF所在的文件夹,如WebContent,如上图


控制器里面的内容是:

@Controller
//@RequestMapping("")
public class CategoryController {
@Autowired
  CategoryService categoryService;

  @RequestMapping("listCategory")
public ModelAndView listCategory(Page page){

ModelAndView mav = new ModelAndView();
     List<Category> cs= categoryService.list(page);
     int total = categoryService.total();
     
     page.caculateLast(total);
     
     // 放入转发参数
     mav.addObject("cs", cs);
     // 放入jsp路径
     mav.setViewName("listCategory");
     return mav;
  }

@RequestMapping("addCategory")
public ModelAndView addCategory(Category category){
categoryService.add(category);
     ModelAndView mav = new ModelAndView("redirect:/listCategory");
      return mav;
  }
@RequestMapping("deleteCategory")
public ModelAndView deleteCategory(Category category){
categoryService.delete(category);
     ModelAndView mav = new ModelAndView("redirect:/listCategory");
     return mav;
  }
@RequestMapping("editCategory")
public ModelAndView editCategory(Category category){
Category c= categoryService.get(category.getId());
     ModelAndView mav = new ModelAndView("editCategory");
     mav.addObject("c", c);
     return mav;
  }
@RequestMapping("updateCategory")
public ModelAndView updateCategory(Category category){
categoryService.update(category);
     ModelAndView mav = new ModelAndView("redirect:/listCategory");
     return mav;
  }  

listCategory里面的内容

<%@ page language="java" contentType="text/html; charset=UTF-8"
   pageEncoding="UTF-8" import="java.util.*"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<div style="width:500px;margin:0px auto;text-align:center">
  <table align='center' border='1' cellspacing='0'>
      <tr>
          <td>id</td>
          <td>name</td>
          <td>编辑</td>
          <td>删除</td>
      </tr>
      <c:forEach items="${cs}" var="c" varStatus="st">
<tr>
              <td>${c.id}</td>
              <td>${c.name}</td>
              <td><a href="editCategory?id=${c.id}">编辑</a></td>
              <td><a href="deleteCategory?id=${c.id}">删除</a></td>
          </tr>
      </c:forEach>
</table>
  <div style="text-align:center">
     <a href="?start=0">首  页</a>
     <a href="?start=${page.start-page.count}">上一页</a>
     <a href="?start=${page.start+page.count}">下一页</a>
     <a href="?start=${page.last}">末  页</a>
  </div>
 
 
  <div style="text-align:center;margin-top:40px">
     
     <form method="post" action="addCategory">
        分类名称: <input name="name" value="" type="text"> <br><br>
        <input type="submit" value="增加分类">
     </form>

  </div>
</div>

editCategory里面的内容是:

<%@ page language="java" contentType="text/html; charset=UTF-8"
   pageEncoding="UTF-8" import="java.util.*"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<div style="width:500px;margin:0px auto;text-align:center">
  <table align='center' border='1' cellspacing='0'>
      <tr>
          <td>id</td>
          <td>name</td>
          <td>编辑</td>
          <td>删除</td>
      </tr>
      <c:forEach items="${cs}" var="c" varStatus="st">
<tr>
              <td>${c.id}</td>
              <td>${c.name}</td>
              <td><a href="editCategory?id=${c.id}">编辑</a></td>
              <td><a href="deleteCategory?id=${c.id}">删除</a></td>
          </tr>
      </c:forEach>
</table>
  <div style="text-align:center">
     <a href="?start=0">首  页</a>
     <a href="?start=${page.start-page.count}">上一页</a>
     <a href="?start=${page.start+page.count}">下一页</a>
     <a href="?start=${page.last}">末  页</a>
  </div>
 
 
  <div style="text-align:center;margin-top:40px">
     
     <form method="post" action="addCategory">
        分类名称: <input name="name" value="" type="text"> <br><br>
        <input type="submit" value="增加分类">
     </form>

  </div>
</div>

运行,成功

增加:

删除:134,hello,没了

改动,编辑:133变为了何东霖

明天的计划:把student那个SSM框架改为现在的categorySSM框架,敲一遍五子棋

遇到的问题:暂无

今天的收获:完成了SSM的增删改查(尽管换了个主类)

java任务二开始时间:2018.01.25

预计demo时间:2018.02.12

可能有延期风险,原因是:基础比较差,

禅道链接地址:http://task.ptteng.com/zentao/project-task-501.html



返回列表 返回列表
评论

    分享到