第二篇文章

在UserService.java中写:
package com.yhp.service;

import java.util.List;

import com.yhp.model.User;

public interface UserService {

public List list(User user);
1
}
在UserServiceImpl.java中写:
package com.yhp.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yhp.dao.UserDao;
import com.yhp.model.User;

@Service
public class UserServiceImpl implements UserService {

@Autowired
private UserDao userDao;

@Override
public List list(User user) {
return userDao.list(user);
}

}
在User.java中写:
package com.yhp.model;

public class User {
private Integer id;
private String username;
private String pwd;
private String realname;

public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public String getRealname() {
return realname;
}
public void setRealname(String realname) {
this.realname = realname;
}

}

UserController.java中写:
package com.yhp.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yhp.model.User;
import com.yhp.service.UserService;

@RequestMapping("/user")
@Controller
public class UserController {

@Autowired
private UserService userService;

@ResponseBody
@RequestMapping("/list.do")
public List list(User user){
return userService.list(user);
}

@RequestMapping("/toLogin.do")
public String toLogin(){
return “login”;
}

}
另需配置xml文件springmvc-config.xml:

<context:component-scan base-package=“com.yhp.controller” />

<mvc:annotation-driven />

<mvc:resources location="/js/" mapping="/js/" />
<mvc:resources location="/css/" mapping="/css/
" />
<mvc:resources location="/images/" mapping="/images/**" />




和mybatis-config.xml文件: <?xml version="1.0" encoding="UTF-8" ?> 还有applicationContext.xml文件:

<context:property-placeholder location=“classpath:jdbc.properties” />

<aop:aspectj-autoproxy />



<tx:annotation-driven transaction-manager=“transactionManager” />

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值