发表于: 2017-09-30 23:46:10

1 711


今天完成的任务

将springmvc整合进原有的任务一体系


因为是根据自己的知识体系写的,所以写了几个小时bug没有进展


现将自己遇到的问题复述如下


原意是通过mybatis调用一个id查询语句

@Select("select * from   student  where id= #{id} ")
public List<Category> selId(Category category);//查id

public static List<Category> SelOfId(CategoryMapper categoryMapper){
Category category = new Category();
   category.setId(30);
   List<Category> cs = categoryMapper.selId(category);
    return cs;
}

返回的category通过get语句获得相应的变量,在下面的controller类中反射到hello.jsp中


a,b为获得的变量


@Controller//该类为请求处理的controller类
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public class  HelloController {
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public String printHello(ModelMap model) {

String a="data";
       String b="data";
       model.addAttribute("msg", a);//打印的字符
       model.addAttribute("name", b);
       return "hello";//返回hello.jsp

   }
}


但是遇到以下的问题

1.在任务一中调用方法使用的是如下的语句作为单元测试,可以看到有不少的标签,如果就这么简单的将标签都放入controller中,一个是影响代码的美观,不易维护,另一个是容易出现嵌套错误



@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class test {
@Autowired
   //因idea检测不到Spring装配的CategoryMapper,需通过此标签声明
   @SuppressWarnings("SpringJavaAutowiringInspection")
CategoryMapper categoryMapper;
   @Test
   public void CURD(){
//CRUD.SelOfId(categoryMapper);
       List<Category> cs=CRUD.SelOfId(categoryMapper);
       System.out.print(cs.get(0));


   }


故而我打算尽量在

public static List<Category> SelOfId(CategoryMapper categoryMapper){
Category category = new Category();
   category.setId(30);
   List<Category> cs = categoryMapper.selId(category);
    return cs;
}

使用标签注入xml,但是并未成功



明天要做的事


还是看看资料,前辈们是如何整合sssm框架的



遇到的问题

今天做的事情全是问题


收获


返回列表 返回列表
评论

    分享到