用idea搭建maven项目与ssm框架整合
<%–
Created by IntelliJ IDEA.
User: ibm
Date: 2018/11/12
Time: 20:33
To change this template use File | Settings | File Templates.
–%>
<%@ page contentType=“text/html;charset=UTF-8” language=“java” %>
<form action="${pageContext.request.contextPath}/user/addUser" method="get">
<p> 用户名: <input type="text" name="name" id="uLogin" onblur="check();"></p><span id="sp1"></span>
<p> 密码: <input type="password" name="pwd"></p>
<p> 确认密码: <input type="password" name="repwd"></p>
<p> <input type="submit" value="注册"></p>
</form>
后台处理:
package com.offcn.controller;
import com.offcn.entity.User;
import com.offcn.service.IUserService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
private IUserService userService;
@RequestMapping("/list")
public String toRegist(){
return "regist";
}
@RequestMapping("/addUser")
public String addUser(@ModelAttribute User user) {
userService.save(user);
System.out.println(user);
return "../index";
}
@RequestMapping("/toLogin")
public String regist(User user, Model model, HttpSession session) {
User user1 = userService.selectUser(user.getName(), user.getPwd());
if(user1!=null){
session.setAttribute("user",user1);
return "redirect:/main/list";
}
return "error";
}
@RequestMapping(value = "check",method = RequestMethod.POST)
@ResponseBody
public Object checkUserName(@RequestParam(value = "uname",required =false)
String uname){
Map<String ,Object> map=new HashMap<>();
User user = userService.checkUser(uname);
if(user==null){
map.put("end","ok");
}else {
map.put("end","error");
}
return map;
}
}
Usermapper.xml文件配置:
<?xml version="1.0" encoding="UTF-8"?><insert id="save" parameterType="user" useGeneratedKeys="true" keyColumn="uid" keyProperty="uid">
insert into `user`(name, pwd) values (#{name}, #{pwd})
</insert>
<select id="selectUser" resultType="User">
select * from `user` where name=#{name}
</select>
<select id="selectAllUser" resultType="User">
select * from `user`
</select>
<select id="selectAllUserByLimit" resultType="User">
select * from `user` limit #{currentPage},#{pageSize}
</select>
<select id="selectCount" resultType="Integer">
select count(1) from `user`
</select>
<delete id="deleteUser" parameterType="Integer">
delete from `user` where uid=#{uid}
</delete>