project2.ssm实现的注册功能.3.Controller
程序员文章站
2022-04-30 15:51:47
...
1.用到的注解的含义
[email protected]
@RequestMapping("")用于匹配Http请求中的请求路径url
可以通过value=“url”,produces = "application/json;charset=UTF-8"来改变返回值编码类型,但是之前在annotation中已经统一配置过了,不需要再写。
[email protected]
@ResponseBody表示返回值跳过视图解析器,写入response的body区域
[email protected]
@RequestBody表示请求体的参数要和其注解的参数匹配
2.我对controller中解析参数和其它过程的看法
鲁二蛋ssm开发原则:controller中故每个函数尽可能短,更加一目了然,尽可能调用辅助类
package com.project2.controller;
import java.io.IOException;
import java.io.InputStream;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.project2.Beans.userBean;
import com.project2.aop.jdbcProcess;
//import com.project2.aop.jDao;
import com.project2.dao.dao;
@Controller
public class loadDao {
@RequestMapping("/loaduser")
@ResponseBody
public String loadUserFun(@RequestBody userBean user) {
//System.out.println(user);
//jDao arm=new jDao();
ApplicationContext ioc=new ClassPathXmlApplicationContext("aop.xml");
userBean user1=new userBean();
user1.setName(user.getName());
user1.setPassword(user.getPassword());
user1.setSex(user1.getSex());
jdbcProcess jdbcTools=ioc.getBean(jdbcProcess.class);
int userCount=jdbcTools.checkUser(user1);
if(userCount>0) {
return "locatedUser";
}
boolean insertUserFlag=jdbcTools.insertUser(user);
if(insertUserFlag==false) {
return "faileToInsert";
}
return "success";
}
}
上一篇: web.xml配置加载顺序
下一篇: JSP与Servlet